Skip to content

Commit

Permalink
Merge pull request #175 from fronzbot/update-subdomains
Browse files Browse the repository at this point in the history
Change subdomain from rest.region to rest-region
  • Loading branch information
fronzbot authored May 22, 2019
2 parents c319762 + 8fb1116 commit 720d520
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
9 changes: 7 additions & 2 deletions blinkpy/blinkpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class Blink():

def __init__(self, username=None, password=None,
refresh_rate=DEFAULT_REFRESH,
motion_interval=DEFAULT_MOTION_INTERVAL):
motion_interval=DEFAULT_MOTION_INTERVAL,
legacy_subdomain=False):
"""
Initialize Blink system.
Expand All @@ -55,6 +56,9 @@ def __init__(self, username=None, password=None,
Defaults to last refresh time.
Useful for preventing motion_detected property
from de-asserting too quickly.
:param legacy_subdomain: Set to TRUE to use old 'rest.region'
endpoints (only use if you are having
api issues).
"""
self._username = username
self._password = password
Expand All @@ -76,6 +80,7 @@ def __init__(self, username=None, password=None,
self._login_url = LOGIN_URL
self.motion_interval = DEFAULT_MOTION_INTERVAL
self.version = __version__
self.legacy = legacy_subdomain

@property
def auth_header(self):
Expand Down Expand Up @@ -139,7 +144,7 @@ def get_auth_token(self, is_retry=False):

self._auth_header = {'Host': self._host,
'TOKEN_AUTH': self._token}
self.urls = BlinkURLHandler(self.region_id)
self.urls = BlinkURLHandler(self.region_id, legacy=self.legacy)

return self._auth_header

Expand Down
7 changes: 5 additions & 2 deletions blinkpy/helpers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,12 @@ class BlinkAuthenticationException(BlinkException):
class BlinkURLHandler():
"""Class that handles Blink URLS."""

def __init__(self, region_id):
def __init__(self, region_id, legacy=False):
"""Initialize the urls."""
self.base_url = "https://rest.{}.{}".format(region_id, BLINK_URL)
self.subdomain = 'rest-{}'.format(region_id)
if legacy:
self.subdomain = 'rest.{}'.format(region_id)
self.base_url = "https://{}.{}".format(self.subdomain, BLINK_URL)
self.home_url = "{}/homescreen".format(self.base_url)
self.event_url = "{}/events/network".format(self.base_url)
self.network_url = "{}/network".format(self.base_url)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cameras.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ def test_camera_update(self, mock_sess):
self.assertEqual(self.camera.temperature_calibrated, 71)
self.assertEqual(self.camera.wifi_strength, 4)
self.assertEqual(self.camera.thumbnail,
'https://rest.test.immedia-semi.com/thumb.jpg')
'https://rest-test.immedia-semi.com/thumb.jpg')
self.assertEqual(self.camera.clip,
'https://rest.test.immedia-semi.com/test.mp4')
'https://rest-test.immedia-semi.com/test.mp4')
self.assertEqual(self.camera.image_from_cache, 'test')
self.assertEqual(self.camera.video_from_cache, 'foobar')

Expand Down Expand Up @@ -136,7 +136,7 @@ def test_thumbnail_not_in_info(self, mock_sess):
}
self.camera.update(config)
self.assertEqual(self.camera.thumbnail,
'https://rest.test.immedia-semi.com/new/thumb.jpg')
'https://rest-test.immedia-semi.com/new/thumb.jpg')

def test_no_thumbnails(self, mock_sess):
"""Tests that thumbnail is 'None' if none found."""
Expand Down
9 changes: 8 additions & 1 deletion tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import unittest
from unittest import mock
import time
from blinkpy.helpers.util import Throttle
from blinkpy.helpers.util import Throttle, BlinkURLHandler


class TestUtil(unittest.TestCase):
Expand Down Expand Up @@ -98,3 +98,10 @@ def test2(self):
with mock.patch('time.time', return_value=now_plus_6):
self.assertEqual(tester.test1(), None)
self.assertEqual(tester.test2(), True)

def test_legacy_subdomains(self):
"""Test that subdomain can be set to legacy mode."""
urls = BlinkURLHandler('test')
self.assertEqual(urls.subdomain, 'rest-test')
urls = BlinkURLHandler('test', legacy=True)
self.assertEqual(urls.subdomain, 'rest.test')

0 comments on commit 720d520

Please sign in to comment.