Skip to content

Commit f667e71

Browse files
author
marcel corso gonzalez
authored
Merge branch 'master' into encoding-fix
2 parents df2c93f + 2d76aba commit f667e71

29 files changed

+148
-194
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ target/
5959

6060
# PyCharm
6161
.idea/
62+
*.iml
6263

6364
# pyvenv
6465
venv*/

.travis.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
language: python
22
python:
3-
- 'pypy2.7'
4-
- 'pypy3.5'
5-
- '2.7'
6-
- '3.4'
3+
- 'pypy3.6'
4+
- 'pypy3.7'
75
- '3.6'
6+
- '3.7'
7+
- '3.8'
8+
- '3.9'
89
- 'nightly'
910
install:
10-
- pip install -r requirements.txt
11-
- pip install .
11+
- pip install -e .[dev]
1212
script:
1313
- coverage run --source=messagebird -m unittest discover -s tests/
1414
- coverage report --fail-under=80
@@ -17,5 +17,3 @@ script:
1717
matrix:
1818
allow_failures:
1919
- python: 'nightly'
20-
- python: 'pypy2.7'
21-
- python: 'pypy3.5'

README.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import messagebird
3535
Then, create an instance of **messagebird.Client**:
3636

3737
```python
38-
client = messagebird.Client('test_gshuPaZoeEG6ovbc8M79w0QyM')
38+
client = messagebird.Client('YOUR_ACCESS_KEY')
3939
```
4040

4141
Now you can query the API for information or send a request. For example, if we want to request our balance information you'd do something like this:
@@ -78,14 +78,6 @@ To run examples with arguments, try:
7878
$ python ./examples/voice_create_webhook.py --accessKey accessKeyWhichNotExist --url https://example.com --title HELLO_WEBHOOK --token HELLO_TOKEN
7979
```
8080

81-
Conversations WhatsApp Sandbox
82-
-------------
83-
To use the whatsapp sandbox you need to add `messagebird.Feature.ENABLE_CONVERSATIONS_API_WHATSAPP_SANDBOX` to the list of features you want enabled. Don't forget to replace `YOUR_ACCESS_KEY` with your actual access key.
84-
85-
```python
86-
client = messagebird.Client('1ekjMs368KTRlP0z6zfG9P70z', features=[messagebird.Feature.ENABLE_CONVERSATIONS_API_WHATSAPP_SANDBOX])
87-
```
88-
8981
Documentation
9082
-------------
9183
Complete documentation, instructions, and examples are available at:

examples/verify_create_email.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import sys, os
2+
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
3+
4+
import messagebird
5+
6+
# ACCESS_KEY = ''
7+
# RECIPIENT = ''
8+
# ORIGINATOR = ''
9+
10+
try:
11+
ACCESS_KEY
12+
except NameError:
13+
print('You need to set an ACCESS_KEY constant in this file')
14+
sys.exit(1)
15+
16+
try:
17+
RECIPIENT
18+
except NameError:
19+
print('You need to set a RECIPIENT constant in this file')
20+
sys.exit(1)
21+
22+
try:
23+
ORIGINATOR
24+
except NameError:
25+
print('You need to set a ORIGINATOR constant in this file')
26+
sys.exit(1)
27+
28+
try:
29+
# Create a MessageBird client with the specified ACCESS_KEY.
30+
client = messagebird.Client(ACCESS_KEY)
31+
32+
# Create a new Verify.
33+
verify = client.verify_create_email(RECIPIENT, ORIGINATOR, {
34+
'subject': 'your code'
35+
})
36+
37+
# Print the object information.
38+
print('\nThe following information was returned as a Verify object:\n')
39+
print(' id : %s' % verify.id)
40+
print(' href : %s' % verify.href)
41+
print(' recipient : %s' % verify.recipient)
42+
print(' reference : %s' % verify.reference)
43+
print(' messages : %s' % verify.messages)
44+
print(' status : %s' % verify.status)
45+
print(' createdDatetime : %s' % verify.createdDatetime)
46+
print(' validUntilDatetime : %s\n' % verify.validUntilDatetime)
47+
48+
except messagebird.client.ErrorException as e:
49+
print('\nAn error occured while requesting a Verify object:\n')
50+
51+
for error in e.errors:
52+
print(' code : %d' % error.code)
53+
print(' description : %s' % error.description)
54+
print(' parameter : %s\n' % error.parameter)

messagebird/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from messagebird.client import Client, ErrorException, Feature
1+
from messagebird.client import Client, ErrorException
22
from messagebird.signed_request import SignedRequest

messagebird/base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import json
55

66

7-
class Base(object):
7+
class Base:
88
def load(self, data):
9-
for name, value in list(data.items()):
10-
if hasattr(self, name) and not callable(getattr(self, name)):
11-
setattr(self, name, value)
9+
if data is not None:
10+
for name, value in list(data.items()):
11+
if hasattr(self, name) and not callable(getattr(self, name)):
12+
setattr(self, name, value)
1213

1314
return self
1415

messagebird/client.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import sys
22
import json
33
import io
4-
import enum
54

65
from messagebird.balance import Balance
76
from messagebird.call import Call
@@ -26,14 +25,12 @@
2625
from messagebird.number import Number, NumberList
2726

2827
ENDPOINT = 'https://rest.messagebird.com'
29-
CLIENT_VERSION = '1.4.1'
28+
CLIENT_VERSION = '2.0.0'
3029
PYTHON_VERSION = '%d.%d.%d' % (sys.version_info[0], sys.version_info[1], sys.version_info[2])
3130
USER_AGENT = 'MessageBird/ApiClient/%s Python/%s' % (CLIENT_VERSION, PYTHON_VERSION)
3231
REST_TYPE = 'rest'
3332

3433
CONVERSATION_API_ROOT = 'https://conversations.messagebird.com/v1/'
35-
CONVERSATION_API_WHATSAPP_SANDBOX_ROOT = 'https://whatsapp-sandbox.messagebird.com/v1/'
36-
3734
CONVERSATION_PATH = 'conversations'
3835
CONVERSATION_MESSAGES_PATH = 'messages'
3936
CONVERSATION_WEB_HOOKS_PATH = 'webhooks'
@@ -65,24 +62,18 @@ def __init__(self, errorMessage):
6562
super(SignleErrorException, self).__init__(errorMessage)
6663

6764

68-
class Feature(enum.Enum):
69-
ENABLE_CONVERSATIONS_API_WHATSAPP_SANDBOX = 1
70-
7165

7266
class Client(object):
73-
74-
def __init__(self, access_key, http_client=None, features=[]):
67+
def __init__(self, access_key, http_client=None):
7568
self.access_key = access_key
7669
self.http_client = http_client
7770

78-
self.conversation_api_root = CONVERSATION_API_WHATSAPP_SANDBOX_ROOT if Feature.ENABLE_CONVERSATIONS_API_WHATSAPP_SANDBOX in features else CONVERSATION_API_ROOT
79-
8071
def _get_http_client(self, type=REST_TYPE):
8172
if self.http_client:
8273
return self.http_client
8374

8475
if type == CONVERSATION_TYPE:
85-
return HttpClient(self.conversation_api_root, self.access_key, USER_AGENT)
76+
return HttpClient(CONVERSATION_API_ROOT, self.access_key, USER_AGENT)
8677

8778
if type == VOICE_TYPE:
8879
return HttpClient(VOICE_API_ROOT, self.access_key, USER_AGENT)
@@ -294,6 +285,17 @@ def verify_create(self, recipient, params=None):
294285
params.update({'recipient': recipient})
295286
return Verify().load(self.request('verify', 'POST', params))
296287

288+
def verify_create_email(self, recipient, originator, params=None):
289+
"""Create a new email verification."""
290+
if params is None:
291+
params = {}
292+
params.update({
293+
'type' : 'email',
294+
'recipient': recipient,
295+
'originator': originator
296+
})
297+
return Verify().load(self.request('verify', 'POST', params))
298+
297299
def verify_verify(self, id, token):
298300
"""Verify the token of a specific verification."""
299301
return Verify().load(self.request('verify/' + str(id), params={'token': token}))

messagebird/http_client.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
33

44
from messagebird.serde import json_serialize
55

6-
try:
7-
from urllib.parse import urljoin
8-
except ImportError:
9-
from urlparse import urljoin
6+
from urllib.parse import urljoin
107

118

129
class ResponseFormat(Enum):
1310
text = 1
1411
binary = 2
1512

1613

17-
class HttpClient(object):
14+
class HttpClient:
1815
"""Used for sending simple HTTP requests."""
1916

2017
def __init__(self, endpoint, access_key, user_agent):

messagebird/signed_request.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
import time
55
from collections import OrderedDict
66

7-
try:
8-
from urllib.parse import urlencode
9-
except ImportError:
10-
from urllib import urlencode
7+
from urllib.parse import urlencode
118

129

1310
class SignedRequest:

setup.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,38 @@
22
from setuptools import setup
33
from io import open
44

5-
def get_description():
6-
working_directory = path.abspath(path.dirname(__file__))
7-
readme_path = path.join(working_directory, 'README.md')
8-
with open(readme_path, encoding='utf-8') as f:
9-
return (f.read(), 'text/markdown')
10-
11-
description, description_content_type = get_description()
5+
with open('README.md', encoding='utf-8') as f:
6+
description = f.read()
127

138
setup(
149
name = 'messagebird',
1510
packages = ['messagebird'],
16-
version = '1.5.0',
11+
version = '2.0.0',
1712
description = "MessageBird's REST API",
1813
author = 'MessageBird',
1914
author_email = '[email protected]',
2015
long_description = description,
21-
long_description_content_type = description_content_type,
16+
long_description_content_type = 'text/markdown',
2217
url = 'https://github.com/messagebird/python-rest-api',
23-
download_url = 'https://github.com/messagebird/python-rest-api/tarball/1.4.1',
18+
download_url = 'https://github.com/messagebird/python-rest-api/tarball/2.0.0',
2419
keywords = ['messagebird', 'sms'],
2520
install_requires = ['requests>=2.4.1', 'python-dateutil>=2.6.0'],
21+
extras_require = {
22+
'dev': [
23+
'pytest',
24+
'pytest-cov',
25+
'mock>=2.0',
26+
'codecov',
27+
'pycodestyle',
28+
]
29+
},
2630
license = 'BSD-2-Clause',
2731
classifiers = [
28-
'Programming Language :: Python',
29-
'Programming Language :: Python :: 2',
3032
'Programming Language :: Python :: 3',
33+
'Programming Language :: Python :: 3.6',
34+
'Programming Language :: Python :: 3.7',
35+
'Programming Language :: Python :: 3.8',
36+
'Programming Language :: Python :: 3.9',
37+
'Operating System :: OS Independent',
3138
],
3239
)

0 commit comments

Comments
 (0)