From 35cc3155a62f4fbbfcfac9d2b053ff601adb5347 Mon Sep 17 00:00:00 2001 From: Sam Wierema Date: Thu, 11 Jun 2015 12:09:28 +0200 Subject: [PATCH 1/4] Don't raise an AttributeError for missing attributes The API is prone to change, but developers often forget to document these changes in the API docs, or add them to the clients. Removing this check makes the client more flexible and resistent to future changes. --- messagebird/base.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/messagebird/base.py b/messagebird/base.py index 55792ca..24a5e69 100644 --- a/messagebird/base.py +++ b/messagebird/base.py @@ -5,8 +5,6 @@ def load(self, data): for name, value in data.items(): if hasattr(self, name): setattr(self, name, value) - else: - raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, name)) return self From f0a2604ede58b4885a92d4e59333ef68f635b860 Mon Sep 17 00:00:00 2001 From: Sam Wierema Date: Thu, 11 Jun 2015 12:36:03 +0200 Subject: [PATCH 2/4] Ignore common Python build/packaging/distribution/test files and directories --- .gitignore | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0740712 --- /dev/null +++ b/.gitignore @@ -0,0 +1,58 @@ +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ From 398ae5c687af3e701fadfa53107bf6c6b7d18af5 Mon Sep 17 00:00:00 2001 From: Sam Wierema Date: Thu, 11 Jun 2015 12:41:21 +0200 Subject: [PATCH 3/4] Send all requests as JSON This change mitigates an issue where nested parameters (such as typedetails) can be incorrectly processed by the requests library in Python. --- messagebird/client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/messagebird/client.py b/messagebird/client.py index a1a8667..cf442d4 100644 --- a/messagebird/client.py +++ b/messagebird/client.py @@ -1,4 +1,5 @@ import sys +import json import requests try: @@ -32,13 +33,14 @@ def request(self, path, params={}): headers = { 'Accept' : 'application/json', 'Authorization' : 'AccessKey ' + self.access_key, - 'User-Agent' : 'MessageBird/ApiClient/%s Python/%s' % (CLIENT_VERSION, PYTHON_VERSION) + 'User-Agent' : 'MessageBird/ApiClient/%s Python/%s' % (CLIENT_VERSION, PYTHON_VERSION), + 'Content-Type' : 'application/json' } if len(params) == 0: response = requests.get(url, verify=True, headers=headers) else: - response = requests.post(url, verify=True, headers=headers, data=params) + response = requests.post(url, verify=True, headers=headers, data=json.dumps(params)) if response.status_code in self._supported_status_codes: json_response = response.json() From a3800ba3aabd0a2564a7e1531a56ba49cdd5d730 Mon Sep 17 00:00:00 2001 From: Sam Wierema Date: Thu, 11 Jun 2015 12:47:13 +0200 Subject: [PATCH 4/4] Bump the version to 1.0.1 Also change the maintainer to MessageBird as a company, because not one person is responsible for maintaining. If you want to see the authors, check the commits :-). --- messagebird/client.py | 2 +- setup.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/messagebird/client.py b/messagebird/client.py index cf442d4..cbfec70 100644 --- a/messagebird/client.py +++ b/messagebird/client.py @@ -15,7 +15,7 @@ from messagebird.voicemessage import VoiceMessage ENDPOINT = 'https://rest.messagebird.com' -CLIENT_VERSION = '1.0.0' +CLIENT_VERSION = '1.0.1' PYTHON_VERSION = '%d.%d.%d' % (sys.version_info[0], sys.version_info[1], sys.version_info[2]) class ErrorException(BaseException): diff --git a/setup.py b/setup.py index 89ff0a4..0c6f6e3 100644 --- a/setup.py +++ b/setup.py @@ -3,10 +3,10 @@ setup( name = 'messagebird', packages = ['messagebird'], - version = '1.0.0', + version = '1.0.1', description = "MessageBird's REST API", - author = 'Maurice Nonnekes', - author_email = 'maurice@messagebird.com', + author = 'MessageBird', + author_email = 'support@messagebird.com', url = 'https://github.com/messagebird/python-rest-api', install_requires = ['requests>=2.4.1'], license = 'BSD-2-Clause',