-
Notifications
You must be signed in to change notification settings - Fork 65
add support for create MMS #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8f8995c
setup.py: update the setup file to support py2.7
sarathsp06 942b892
base.py: updated the base class utility functions to be not bound
sarathsp06 1deec65
mms: add create mms api support
sarathsp06 0785056
client/mms: add docstring to create_mms method
sarathsp06 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys, os | ||
sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | ||
|
||
import messagebird | ||
|
||
ACCESS_KEY = os.environ.get('ACCESS_KEY', None) | ||
if ACCESS_KEY is None: | ||
print("Set environment ACCESS_KEY from https://dashboard.messagebird.com/en/developers/access") | ||
exit(1) | ||
|
||
try: | ||
# Create a MessageBird client with the specified ACCESS_KEY. | ||
client = messagebird.Client(ACCESS_KEY) | ||
# Send a MMS | ||
mms = client.mms_create('Sarath','+4915238456487','Rich test message','https://www.messagebird.com/assets/images/og/messagebird.gif') | ||
# Print the object information. | ||
print("The following information was returned as a MMS object:\n%s" % mms) | ||
|
||
except messagebird.client.ErrorException as e: | ||
print('\nAn error occured while requesting to send a MMS:\n') | ||
for error in e.errors: | ||
print(' code : %d' % error.code) | ||
print(' description : %s' % error.description) | ||
print(' parameter : %s\n' % error.parameter) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from messagebird.base import Base | ||
from messagebird.recipient import Recipient | ||
|
||
class MMS(Base): | ||
def __init__(self): | ||
self.id = None | ||
self.href = None | ||
self.direction = None | ||
self.originator = None | ||
self.subject = None | ||
self.body = None | ||
self.mediaUrls = None | ||
self.reference = None | ||
self._scheduledDatetime = None | ||
self._createdDatetime = None | ||
self._recipients = None | ||
|
||
@property | ||
def scheduledDatetime(self): | ||
return self._scheduledDatetime | ||
|
||
@scheduledDatetime.setter | ||
def scheduledDatetime(self, value): | ||
self._scheduledDatetime = self.value_to_time(value) | ||
|
||
@property | ||
def createdDatetime(self): | ||
return self._createdDatetime | ||
|
||
@createdDatetime.setter | ||
def createdDatetime(self, value): | ||
self._createdDatetime = self.value_to_time(value) | ||
|
||
@property | ||
def recipients(self): | ||
return self._recipients | ||
|
||
@recipients.setter | ||
def recipients(self, value): | ||
value['items'] = [Recipient().load(r) for r in value['items']] | ||
self._recipients = value | ||
|
||
def __str__(self): | ||
return "\n".join([ | ||
"id : %s" % self.id , | ||
"href : %s" % self.href , | ||
"direction : %s" % self.direction , | ||
"originator : %s" % self.originator , | ||
"subject : %s" % self.subject , | ||
"body : %s" % self.body , | ||
"mediaUrls : %s" % ",".join(self.mediaUrls), | ||
"reference : %s" % self.reference , | ||
"scheduledDatetime : %s" % self.scheduledDatetime , | ||
"createdDatetime : %s" % self.createdDatetime , | ||
"recipients : %s" % self.recipients, | ||
]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import unittest | ||
from messagebird import Client | ||
|
||
try: | ||
from unittest.mock import Mock | ||
except ImportError: | ||
# mock was added to unittest in Python 3.3, but was an external library | ||
# before. | ||
from mock import Mock | ||
|
||
|
||
class TestMMS(unittest.TestCase): | ||
|
||
def test_create_mms(self): | ||
http_client = Mock() | ||
http_client.request.return_value = '{"originator": "test-org", "body": "Rich test message", "direction": "mt", "recipients": {"totalCount": 1, "totalSentCount": 1, "totalDeliveredCount": 0, "totalDeliveryFailedCount": 0, "items": [{"status": "sent", "statusDatetime": "2019-06-04T13:54:48+00:00", "recipient": 4915238456487}]}, "reference": null, "createdDatetime": "2019-06-04T13:54:48+00:00", "href": "https://rest.messagebird.com/mms/0a75f8f82b5d4377bd8fb5b22ac1e8ac", "mediaUrls": ["https://www.messagebird.com/assets/images/og/messagebird.gif"], "scheduledDatetime": null, "id": "0a75f8f82b5d4377bd8fb5b22ac1e8ac", "subject": null}' | ||
|
||
params = {"originator": "test-org", "body": "Rich test message","recipients":"+4915238456487","mediaUrls":"https://www.messagebird.com/assets/images/og/messagebird.gif"} | ||
mms = Client('', http_client).mms_create(**params) | ||
|
||
params["mediaUrls"] = [params["mediaUrls"]] | ||
params.update({'subject': None, 'reference': None, 'scheduledDatetime': None}) | ||
http_client.request.assert_called_once_with('mms', 'POST', params) | ||
|
||
self.assertEqual(params["originator"], mms.originator) | ||
self.assertEqual(params["recipients"].strip("+"), str(mms.recipients["items"][0].recipient)) | ||
self.assertEqual(1,len(mms.recipients["items"])) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure where the documentation is or how explicit it may be, but there could be more info on the parameters of these methods I think. Now the user has to figure out by reading through the code what the exact format is for
scheduledDatetime
. Adding a small docstring here would helpThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added docstring to the function