Skip to content

Commit b5cdc34

Browse files
Merge pull request #29 from ScalaInc/python-2.6-support
Python 2.6 support
2 parents 5440a82 + a84d0c1 commit b5cdc34

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Raised when an error or timeout occurs when attempting to listen on the network.
9696

9797
**`exp_sdk.ApiError`**
9898

99-
Raised when an API call fails. Has properties `message` and `code`.
99+
Raised when an API call fails. Has properties `message`, `code`, and `payload`. `payload` is the parsed JSON document received from the API.
100100

101101

102102
## Authentication Payload

exp_sdk/api.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ def _get_channel_name (self):
6666
return self.uuid
6767

6868
def _get_resource_path (self):
69-
return '{}/{}'.format(self._collection_path, self.uuid)
69+
return '{0}/{1}'.format(self._collection_path, self.uuid)
7070

7171
@classmethod
7272
def get (cls, uuid, sdk):
7373
if not uuid or not isinstance(uuid, basestring):
7474
return None
75-
path = '{}/{}'.format(cls._collection_path, uuid)
75+
path = '{0}/{1}'.format(cls._collection_path, uuid)
7676
try:
7777
remote_document = sdk.api.get(path)
7878
except sdk.exceptions.ApiError as exception:
@@ -292,11 +292,11 @@ def value(self, value):
292292
self.document['value'] = value
293293

294294
def _get_resource_path(self):
295-
return '{}/{}/{}'.format(self._collection_path, self.group, self.key)
295+
return '{0}/{1}/{2}'.format(self._collection_path, self.group, self.key)
296296

297297
@classmethod
298298
def get (cls, group, key, sdk):
299-
path = '{}/{}/{}'.format(cls._collection_path, group, key)
299+
path = '{0}/{1}/{2}'.format(cls._collection_path, group, key)
300300
try:
301301
document = sdk.api.get(path)
302302
except sdk.exceptions.ApiError as exception:
@@ -307,7 +307,7 @@ def get (cls, group, key, sdk):
307307

308308
@classmethod
309309
def create (cls, group, key, value, sdk):
310-
path = '{}/{}/{}'.format(cls._collection_path, group, key)
310+
path = '{0}/{1}/{2}'.format(cls._collection_path, group, key)
311311
document = sdk.api.put(path, value)
312312
data = cls(document, sdk)
313313
return data
@@ -316,7 +316,7 @@ def save (self):
316316
self._document = self._sdk.api.put(self._get_resource_path(), self.value)
317317

318318
def _get_channel_name (self):
319-
return 'data:{}:{}'.format(self.group, self.key)
319+
return 'data:{0}:{1}'.format(self.group, self.key)
320320

321321

322322

@@ -339,9 +339,9 @@ def get_children (self, params=None):
339339

340340
def _get_delivery_url (self):
341341
auth = self._sdk.authenticator.get_auth()
342-
base = '{}/api/delivery'.format(auth['api']['host'])
342+
base = '{0}/api/delivery'.format(auth['api']['host'])
343343
encoded_path = urllib.quote(self.document.get('path'))
344-
return '{}/{}?_rt={}'.format(base, encoded_path, auth['restrictedToken'])
344+
return '{0}/{1}?_rt={2}'.format(base, encoded_path, auth['restrictedToken'])
345345

346346
def get_url (self):
347347
if self.subtype == 'scala:content:file':
@@ -352,7 +352,7 @@ def get_url (self):
352352
return self.document.get('url')
353353

354354
def get_variant_url (self, name):
355-
return '{}&variant='.format(self._get_delivery_url(), name)
355+
return '{0}&variant='.format(self._get_delivery_url(), name)
356356

357357
def has_variant (self, name):
358358
return name in [variant['name'] for variant in self.document.get('variants', [])]
@@ -388,7 +388,7 @@ def _on_error(self, exception):
388388
self._sdk.logger.debug('API call encountered an unexpected error: %s' % traceback.format_exc())
389389
raise self._sdk.exceptions.UnexpectedError('API call encountered an unexpected error.')
390390
else:
391-
raise self._sdk.exceptions.ApiError(code=payload.get('code'), message=payload.get('message'), status_code=exception.response.status_code)
391+
raise self._sdk.exceptions.ApiError(code=payload.get('code'), message=payload.get('message'), status_code=exception.response.status_code, payload=payload)
392392
else:
393393
self._sdk.logger.warn('API call encountered an unexpected error.')
394394
self._sdk.logger.debug('API call encountered an unexpected error: %s' % traceback.format_exc())

exp_sdk/exceptions.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ def __str__ (self):
3636

3737
class ApiError(ExpError):
3838

39-
def __init__(self, code=None, message=None, status_code=None):
39+
def __init__(self, code=None, message=None, status_code=None, payload=None):
4040
self.message = message or 'An unknown error has occurred.'
4141
self.code = code or 'unknown.error'
4242
self.status_code = status_code
43+
self.payload = payload
4344

4445
def __str__(self):
45-
return '%s: %s' % (self.code, self.message)
46+
return '%s: %s \n %s' % (self.code, self.message, self.payload)
4647

4748

48-
class NetworkError(ExpError): pass
49+
class NetworkError(ExpError): pass

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
setup(
44
name='exp-sdk',
55
packages= ['exp_sdk'],
6-
version='1.0.6',
6+
version='1.0.7',
77
description='EXP Python SDK',
88
author='Scala',
99
author_email='[email protected]',

tests/test_feeds.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Test(utils.Device, utils.CommonResourceBase):
1111
class_ = utils.api.Feed
1212

1313
def generate_valid_document (self):
14-
return { 'subtype': 'scala:feed:weather', 'searchValue': '19713', 'name': self.generate_name() }
14+
return { 'subtype': 'scala:feed:weather', 'dataType': 'static', 'searchValue': '19713', 'name': self.generate_name() }
1515

1616
def test_get_data (self):
1717
feed = self.create_valid()
@@ -20,7 +20,7 @@ def test_get_data (self):
2020
raise Exception
2121

2222
def test_dynamic (self):
23-
feed = self.exp.create_feed({ 'subtype': 'scala:feed:weather', 'searchValue': '', 'metadata': { 'type': 'dynamic' }, 'name': self.generate_name() })
23+
feed = self.exp.create_feed({ 'subtype': 'scala:feed:weather', 'searchValue': '', 'dataType': 'dynamic', 'name': self.generate_name() })
2424
data = feed.get_data(searchValue='19713')
2525
if data['search']['search'] != '19713':
2626
raise Exception

0 commit comments

Comments
 (0)