Skip to content

Commit

Permalink
Merge pull request #97 from pgulley/useragent
Browse files Browse the repository at this point in the history
add user-agent string
  • Loading branch information
pgulley authored Dec 10, 2024
2 parents 8d07b03 + 6b5d61e commit 60dfe4b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mediacloud/api.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import datetime as dt
import importlib.metadata
import logging
from typing import Any, Dict, List, Optional, Union

import requests


import mediacloud
import mediacloud.error

logger = logging.getLogger(__name__)

##Identify the version of this package that's running
try:
VERSION = "v"+importlib.metadata.version('mediacloud')
except importlib.metadata.PackageNotFoundError:
VERSION = "dev"

class BaseApi:

Expand All @@ -19,6 +26,8 @@ class BaseApi:

BASE_API_URL = "https://search.mediacloud.org/api/"

USER_AGENT_STRING = f"mediacloud {VERSION}"

def __init__(self, auth_token: Optional[str] = None):
if not auth_token:
raise mediacloud.error.MCException("No api key set - nothing will work without this")
Expand All @@ -28,6 +37,8 @@ def __init__(self, auth_token: Optional[str] = None):
self._session = requests.Session()
self._session.headers.update({'Authorization': f'Token {self._auth_token}'})
self._session.headers.update({'Accept': 'application/json'})
self._session.headers.update({"User-Agent":self.USER_AGENT_STRING})


def user_profile(self) -> Dict:
# :return: basic info about the current user, including their roles
Expand Down

0 comments on commit 60dfe4b

Please sign in to comment.