Skip to content

Commit

Permalink
Merge pull request #5 from carlos-sarmiento/patch-1
Browse files Browse the repository at this point in the history
Added HTTPS support to nvr.py
  • Loading branch information
kk7ds authored Nov 28, 2018
2 parents b090128 + a635d3e commit 6d0b9ab
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions uvcclient/nvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ class UVCRemote(object):
"""Remote control client for Ubiquiti Unifi Video NVR."""
CHANNEL_NAMES = ['high', 'medium', 'low']

def __init__(self, host, port, apikey, path='/'):
def __init__(self, host, port, apikey, path='/', ssl=False):
self._host = host
self._port = port
self._path = path
self._ssl = ssl
if path != '/':
raise Invalid('Path not supported yet')
self._apikey = apikey
Expand All @@ -80,10 +81,16 @@ def camera_identifier(self):
return 'id'
else:
return 'uuid'

def _get_http_connection(self):
if self._ssl:
return httplib.HTTPSConnection(self._host, self._port)
else:
return httplib.HTTPConnection(self._host, self._port)

def _safe_request(self, *args, **kwargs):
try:
conn = httplib.HTTPConnection(self._host, self._port)
conn = self._get_http_connection();
conn.request(*args, **kwargs)
return conn.getresponse()
except OSError:
Expand All @@ -102,7 +109,7 @@ def _uvc_request(self, *args, **kwargs):

def _uvc_request_safe(self, path, method='GET', data=None,
mimetype='application/json'):
conn = httplib.HTTPConnection(self._host, self._port)
conn = self._get_http_connection();
if '?' in path:
url = '%s&apiKey=%s' % (path, self._apikey)
else:
Expand Down

0 comments on commit 6d0b9ab

Please sign in to comment.