Skip to content

Commit

Permalink
Pass in specific User-Agent #14
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterWil committed Jul 26, 2020
1 parent 2d7fd8a commit b3b255e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 6 additions & 4 deletions skybellpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class Skybell():

def __init__(self, username=None, password=None,
auto_login=False, get_devices=False,
cache_path=CONST.CACHE_PATH, disable_cache=False):
cache_path=CONST.CACHE_PATH, disable_cache=False,
agent_identifier=CONST.DEFAULT_AGENT_IDENTIFIER):
"""Init Abode object."""
self._username = username
self._password = password
Expand All @@ -43,6 +44,7 @@ def __init__(self, username=None, password=None,
self._disable_cache = disable_cache
self._devices = None
self._session = requests.session()
self._user_agent = '{} ({})'.format(CONST.USER_AGENT, agent_identifier)

# Create a new cache template
self._cache = {
Expand Down Expand Up @@ -171,9 +173,9 @@ def send_request(self, method, url, headers=None,
headers['Authorization'] = 'Bearer ' + \
self.cache(CONST.ACCESS_TOKEN)

headers['user-agent'] = (
'SkyBell/3.4.1 (iPhone9,2; iOS 11.0; loc=en_US; lang=en-US) '
'com.skybell.doorbell/1')
_LOGGER.info("User-Agent: %s", self._user_agent)

headers['user-agent'] = self._user_agent
headers['content-type'] = 'application/json'
headers['accepts'] = '*/*'
headers['x-skybell-app-id'] = self.cache(CONST.APP_ID)
Expand Down
3 changes: 2 additions & 1 deletion skybellpy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ def call():
# Create skybellpy instance.
skybell = skybellpy.Skybell(username=args.username,
password=args.password,
get_devices=True)
get_devices=True,
agent_identifier='skybellcl')

# # Set setting
# for setting in args.set or []:
Expand Down
8 changes: 7 additions & 1 deletion skybellpy/helpers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

MAJOR_VERSION = 0
MINOR_VERSION = 5
MINOR_VERSION = 6
PATCH_VERSION = '0'

__version__ = '{}.{}.{}'.format(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)
Expand Down Expand Up @@ -40,6 +40,12 @@

CACHE_PATH = './skybell.pickle'

USER_AGENT = 'skybellpy/{}.{}.{}'.format(MAJOR_VERSION,
MINOR_VERSION,
PATCH_VERSION)

DEFAULT_AGENT_IDENTIFIER = 'default'

# URLS
BASE_URL = 'https://cloud.myskybell.com/api/v3/'
BASE_URL_V4 = 'https://cloud.myskybell.com/api/v4/'
Expand Down

0 comments on commit b3b255e

Please sign in to comment.