From ef47b184b26f112ee10f8349c338ea20ed791080 Mon Sep 17 00:00:00 2001 From: Senthil Ramakrishnan Date: Wed, 16 Dec 2015 16:59:46 -0800 Subject: [PATCH 1/2] IP Messaging public beta release --- tests/ip_messaging/__init__.py | 0 tests/ip_messaging/test_channels.py | 54 +++++++++++++ tests/ip_messaging/test_credentials.py | 53 ++++++++++++ tests/ip_messaging/test_members.py | 53 ++++++++++++ tests/ip_messaging/test_messages.py | 68 ++++++++++++++++ tests/ip_messaging/test_roles.py | 57 +++++++++++++ tests/ip_messaging/test_services.py | 53 ++++++++++++ tests/ip_messaging/test_users.py | 53 ++++++++++++ twilio/rest/__init__.py | 7 +- twilio/rest/ip_messaging.py | 31 +++++++ .../rest/resources/ip_messaging/__init__.py | 34 ++++++++ .../rest/resources/ip_messaging/channels.py | 78 ++++++++++++++++++ .../resources/ip_messaging/credentials.py | 80 +++++++++++++++++++ twilio/rest/resources/ip_messaging/members.py | 68 ++++++++++++++++ .../rest/resources/ip_messaging/messages.py | 68 ++++++++++++++++ twilio/rest/resources/ip_messaging/roles.py | 67 ++++++++++++++++ .../rest/resources/ip_messaging/services.py | 69 ++++++++++++++++ twilio/rest/resources/ip_messaging/users.py | 63 +++++++++++++++ 18 files changed, 953 insertions(+), 3 deletions(-) create mode 100644 tests/ip_messaging/__init__.py create mode 100644 tests/ip_messaging/test_channels.py create mode 100644 tests/ip_messaging/test_credentials.py create mode 100644 tests/ip_messaging/test_members.py create mode 100644 tests/ip_messaging/test_messages.py create mode 100644 tests/ip_messaging/test_roles.py create mode 100644 tests/ip_messaging/test_services.py create mode 100644 tests/ip_messaging/test_users.py create mode 100644 twilio/rest/ip_messaging.py create mode 100644 twilio/rest/resources/ip_messaging/__init__.py create mode 100644 twilio/rest/resources/ip_messaging/channels.py create mode 100644 twilio/rest/resources/ip_messaging/credentials.py create mode 100644 twilio/rest/resources/ip_messaging/members.py create mode 100644 twilio/rest/resources/ip_messaging/messages.py create mode 100644 twilio/rest/resources/ip_messaging/roles.py create mode 100644 twilio/rest/resources/ip_messaging/services.py create mode 100644 twilio/rest/resources/ip_messaging/users.py diff --git a/tests/ip_messaging/__init__.py b/tests/ip_messaging/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/ip_messaging/test_channels.py b/tests/ip_messaging/test_channels.py new file mode 100644 index 0000000000..90720cdd3a --- /dev/null +++ b/tests/ip_messaging/test_channels.py @@ -0,0 +1,54 @@ +import unittest +from mock import patch, Mock +from twilio.rest.resources.ip_messaging import Channels, Channel +from tests.tools import create_mock_json + +BASE_URI = "https://ip-messaging.twilio.com/v1/Services/ISxxx" +ACCOUNT_SID = "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +AUTH = (ACCOUNT_SID, "token") +CHANNEL_SID = "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + +list_resource = Channels(BASE_URI, AUTH) + + +class ChannelTest(unittest.TestCase): + + @patch("twilio.rest.resources.base.make_twilio_request") + def test_create_channel(self, mock): + resp = create_mock_json("tests/resources/ip_messaging/channel_instance.json") + resp.status_code = 201 + mock.return_value = resp + + uri = "%s/Channels" % (BASE_URI) + list_resource.create(friendly_name='TestChannel', unique_name='Unique') + exp_params = { + 'FriendlyName': "TestChannel", + 'UniqueName': 'Unique' + } + + mock.assert_called_with("POST", uri, data=exp_params, auth=AUTH, + use_json_extension=False) + + @patch("twilio.rest.resources.base.make_twilio_request") + def test_get(self, mock): + resp = create_mock_json("tests/resources/ip_messaging/channel_instance.json") + mock.return_value = resp + + uri = "%s/Channels/%s" % (BASE_URI, CHANNEL_SID) + list_resource.get(CHANNEL_SID) + + mock.assert_called_with("GET", uri, auth=AUTH, + use_json_extension=False) + + @patch("twilio.rest.resources.base.Resource.request") + def test_delete(self, req): + """ Deleting a call should work """ + resp = Mock() + resp.content = "" + resp.status_code = 204 + req.return_value = resp, {} + + app = Channel(list_resource, "CH123") + app.delete() + uri = "%s/Channels/CH123" % (BASE_URI) + req.assert_called_with("DELETE", uri) diff --git a/tests/ip_messaging/test_credentials.py b/tests/ip_messaging/test_credentials.py new file mode 100644 index 0000000000..ae749db875 --- /dev/null +++ b/tests/ip_messaging/test_credentials.py @@ -0,0 +1,53 @@ +import unittest +from mock import patch, Mock +from twilio.rest.resources.ip_messaging import Credentials, Credential +from tests.tools import create_mock_json + +BASE_URI = "https://ip-messaging.twilio.com/v1" +ACCOUNT_SID = "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +AUTH = (ACCOUNT_SID, "token") +CREDENTIAL_SID = "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + +list_resource = Credentials(BASE_URI, AUTH) + + +class CredentialTest(unittest.TestCase): + + @patch("twilio.rest.resources.base.make_twilio_request") + def test_create_credential(self, mock): + resp = create_mock_json("tests/resources/ip_messaging/credential_instance.json") + resp.status_code = 201 + mock.return_value = resp + + uri = "%s/Credentials" % (BASE_URI) + list_resource.create('apn') + exp_params = { + 'Type': "apn" + } + + mock.assert_called_with("POST", uri, data=exp_params, auth=AUTH, + use_json_extension=False) + + @patch("twilio.rest.resources.base.make_twilio_request") + def test_get(self, mock): + resp = create_mock_json("tests/resources/ip_messaging/credential_instance.json") + mock.return_value = resp + + uri = "%s/Credentials/%s" % (BASE_URI, CREDENTIAL_SID) + list_resource.get(CREDENTIAL_SID) + + mock.assert_called_with("GET", uri, auth=AUTH, + use_json_extension=False) + + @patch("twilio.rest.resources.base.Resource.request") + def test_delete(self, req): + """ Deleting a call should work """ + resp = Mock() + resp.content = "" + resp.status_code = 204 + req.return_value = resp, {} + + app = Credential(list_resource, "IS123") + app.delete() + uri = "https://ip-messaging.twilio.com/v1/Credentials/IS123" + req.assert_called_with("DELETE", uri) diff --git a/tests/ip_messaging/test_members.py b/tests/ip_messaging/test_members.py new file mode 100644 index 0000000000..23010bbee3 --- /dev/null +++ b/tests/ip_messaging/test_members.py @@ -0,0 +1,53 @@ +import unittest +from mock import patch, Mock +from twilio.rest.resources.ip_messaging import Members, Member +from tests.tools import create_mock_json + +BASE_URI = "https://ip-messaging.twilio.com/v1/Services/ISxxx/Channels/CHxxx" +ACCOUNT_SID = "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +AUTH = (ACCOUNT_SID, "token") +MEMBER_SID = "MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + +list_resource = Members(BASE_URI, AUTH) + + +class MemberTest(unittest.TestCase): + + @patch("twilio.rest.resources.base.make_twilio_request") + def test_create_member(self, mock): + resp = create_mock_json("tests/resources/ip_messaging/member_instance.json") + resp.status_code = 201 + mock.return_value = resp + + uri = "%s/Members" % (BASE_URI) + list_resource.create('test_identity') + exp_params = { + 'Identity': "test_identity" + } + + mock.assert_called_with("POST", uri, data=exp_params, auth=AUTH, + use_json_extension=False) + + @patch("twilio.rest.resources.base.make_twilio_request") + def test_get(self, mock): + resp = create_mock_json("tests/resources/ip_messaging/member_instance.json") + mock.return_value = resp + + uri = "%s/Members/%s" % (BASE_URI, MEMBER_SID) + list_resource.get(MEMBER_SID) + + mock.assert_called_with("GET", uri, auth=AUTH, + use_json_extension=False) + + @patch("twilio.rest.resources.base.Resource.request") + def test_delete(self, req): + """ Deleting a call should work """ + resp = Mock() + resp.content = "" + resp.status_code = 204 + req.return_value = resp, {} + + app = Member(list_resource, "MB123") + app.delete() + uri = "%s/Members/MB123" % (BASE_URI) + req.assert_called_with("DELETE", uri) diff --git a/tests/ip_messaging/test_messages.py b/tests/ip_messaging/test_messages.py new file mode 100644 index 0000000000..49b5778225 --- /dev/null +++ b/tests/ip_messaging/test_messages.py @@ -0,0 +1,68 @@ +import unittest +from mock import patch, Mock +from twilio.rest.resources.ip_messaging import Messages, Message +from tests.tools import create_mock_json + +BASE_URI = "https://ip-messaging.twilio.com/v1/Services/ISxxx/Channels/CHxxx" +ACCOUNT_SID = "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +AUTH = (ACCOUNT_SID, "token") +MESSAGE_SID = "MSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + +list_resource = Messages(BASE_URI, AUTH) + + +class MessageTest(unittest.TestCase): + + @patch("twilio.rest.resources.base.make_twilio_request") + def test_create_message(self, mock): + resp = create_mock_json("tests/resources/ip_messaging/message_instance.json") + resp.status_code = 201 + mock.return_value = resp + + uri = "%s/Messages" % (BASE_URI) + list_resource.create('TestBody') + exp_params = { + 'Body': "TestBody" + } + + mock.assert_called_with("POST", uri, data=exp_params, auth=AUTH, + use_json_extension=False) + + @patch("twilio.rest.resources.base.make_twilio_request") + def test_get(self, mock): + resp = create_mock_json("tests/resources/ip_messaging/message_instance.json") + mock.return_value = resp + + uri = "%s/Messages/%s" % (BASE_URI, MESSAGE_SID) + list_resource.get(MESSAGE_SID) + + mock.assert_called_with("GET", uri, auth=AUTH, + use_json_extension=False) + + @patch("twilio.rest.resources.base.make_twilio_request") + def test_update(self, mock): + resp = create_mock_json("tests/resources/ip_messaging/message_instance.json") + mock.return_value = resp + + update_params = { + 'UniqueName': 'unique' + } + + uri = "%s/Messages/%s" % (BASE_URI, MESSAGE_SID) + list_resource.update(MESSAGE_SID, unique_name='unique') + + mock.assert_called_with("POST", uri, data=update_params, auth=AUTH, + use_json_extension=False) + + @patch("twilio.rest.resources.base.Resource.request") + def test_delete(self, req): + """ Deleting a call should work """ + resp = Mock() + resp.content = "" + resp.status_code = 204 + req.return_value = resp, {} + + app = Message(list_resource, "MS123") + app.delete() + uri = "%s/Messages/MS123" % (BASE_URI) + req.assert_called_with("DELETE", uri) diff --git a/tests/ip_messaging/test_roles.py b/tests/ip_messaging/test_roles.py new file mode 100644 index 0000000000..b8485361ee --- /dev/null +++ b/tests/ip_messaging/test_roles.py @@ -0,0 +1,57 @@ +import unittest +from mock import patch, Mock +from twilio.rest.resources.ip_messaging import Roles, Role +from tests.tools import create_mock_json + +BASE_URI = "https://ip-messaging.twilio.com/v1/Services/ISxxx" +ACCOUNT_SID = "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +AUTH = (ACCOUNT_SID, "token") +ROLE_SID = "ROaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + +list_resource = Roles(BASE_URI, AUTH) + + +class RoleTest(unittest.TestCase): + + @patch("twilio.rest.resources.base.make_twilio_request") + def test_get_role(self, mock): + resp = create_mock_json("tests/resources/ip_messaging/role_instance.json") + mock.return_value = resp + + uri = "%s/Roles/%s" % (BASE_URI, ROLE_SID) + list_resource.get(ROLE_SID) + + mock.assert_called_with("GET", uri, auth=AUTH, + use_json_extension=False) + + @patch("twilio.rest.resources.base.make_twilio_request") + def test_create_role(self, mock): + resp = create_mock_json("tests/resources/ip_messaging/role_instance.json") + resp.status_code = 201 + mock.return_value = resp + + list_resource.create("Test Role", "deployment", "createChannel") + uri = "%s/Roles" % (BASE_URI) + mock.assert_called_with( + "POST", + uri, + data={ + 'FriendlyName': 'Test Role', + 'Type': 'deployment', + 'Permission': 'createChannel' + }, + auth=AUTH, + use_json_extension=False + ) + + @patch("twilio.rest.resources.base.Resource.request") + def test_delete_role(self, req): + resp = Mock() + resp.content = "" + resp.status_code = 204 + req.return_value = resp, {} + + app = Role(list_resource, "RO123") + app.delete() + uri = "%s/Roles/RO123" % (BASE_URI) + req.assert_called_with("DELETE", uri) diff --git a/tests/ip_messaging/test_services.py b/tests/ip_messaging/test_services.py new file mode 100644 index 0000000000..e8bd5cde85 --- /dev/null +++ b/tests/ip_messaging/test_services.py @@ -0,0 +1,53 @@ +import unittest +from mock import patch, Mock +from twilio.rest.resources.ip_messaging import Services, Service +from tests.tools import create_mock_json + +BASE_URI = "https://ip-messaging.twilio.com/v1" +ACCOUNT_SID = "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +AUTH = (ACCOUNT_SID, "token") +SERVICE_SID = "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + +list_resource = Services(BASE_URI, AUTH) + + +class ServiceTest(unittest.TestCase): + + @patch("twilio.rest.resources.base.make_twilio_request") + def test_create_service(self, mock): + resp = create_mock_json("tests/resources/ip_messaging/service_instance.json") + resp.status_code = 201 + mock.return_value = resp + + uri = "%s/Services" % (BASE_URI) + list_resource.create('TestService') + exp_params = { + 'FriendlyName': "TestService" + } + + mock.assert_called_with("POST", uri, data=exp_params, auth=AUTH, + use_json_extension=False) + + @patch("twilio.rest.resources.base.make_twilio_request") + def test_get(self, mock): + resp = create_mock_json("tests/resources/ip_messaging/service_instance.json") + mock.return_value = resp + + uri = "%s/Services/%s" % (BASE_URI, SERVICE_SID) + list_resource.get(SERVICE_SID) + + mock.assert_called_with("GET", uri, auth=AUTH, + use_json_extension=False) + + @patch("twilio.rest.resources.base.Resource.request") + def test_delete(self, req): + """ Deleting a call should work """ + resp = Mock() + resp.content = "" + resp.status_code = 204 + req.return_value = resp, {} + + app = Service(list_resource, "IS123") + app.delete() + uri = "https://ip-messaging.twilio.com/v1/Services/IS123" + req.assert_called_with("DELETE", uri) diff --git a/tests/ip_messaging/test_users.py b/tests/ip_messaging/test_users.py new file mode 100644 index 0000000000..7a92c15569 --- /dev/null +++ b/tests/ip_messaging/test_users.py @@ -0,0 +1,53 @@ +import unittest +from mock import patch, Mock +from twilio.rest.resources.ip_messaging import Users, User +from tests.tools import create_mock_json + +BASE_URI = "https://ip-messaging.twilio.com/v1/Services/ISxxx" +ACCOUNT_SID = "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +AUTH = (ACCOUNT_SID, "token") +USER_SID = "USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + +list_resource = Users(BASE_URI, AUTH) + + +class UserTest(unittest.TestCase): + + @patch("twilio.rest.resources.base.make_twilio_request") + def test_create_user(self, mock): + resp = create_mock_json("tests/resources/ip_messaging/user_instance.json") + resp.status_code = 201 + mock.return_value = resp + + uri = "%s/Users" % (BASE_URI) + list_resource.create('test_id') + exp_params = { + 'Identity': "test_id" + } + + mock.assert_called_with("POST", uri, data=exp_params, auth=AUTH, + use_json_extension=False) + + @patch("twilio.rest.resources.base.make_twilio_request") + def test_get(self, mock): + resp = create_mock_json("tests/resources/ip_messaging/user_instance.json") + mock.return_value = resp + + uri = "%s/Users/%s" % (BASE_URI, USER_SID) + list_resource.get(USER_SID) + + mock.assert_called_with("GET", uri, auth=AUTH, + use_json_extension=False) + + @patch("twilio.rest.resources.base.Resource.request") + def test_delete(self, req): + """ Deleting a call should work """ + resp = Mock() + resp.content = "" + resp.status_code = 204 + req.return_value = resp, {} + + app = User(list_resource, "US123") + app.delete() + uri = "%s/Users/US123" % (BASE_URI) + req.assert_called_with("DELETE", uri) diff --git a/twilio/rest/__init__.py b/twilio/rest/__init__.py index b1963720e0..f4077334aa 100644 --- a/twilio/rest/__init__.py +++ b/twilio/rest/__init__.py @@ -1,10 +1,11 @@ from .base import set_twilio_proxy from .client import TwilioRestClient +from .ip_messaging import TwilioIpMessagingClient from .lookups import TwilioLookupsClient from .pricing import TwilioPricingClient from .task_router import TwilioTaskRouterClient from .trunking import TwilioTrunkingClient -_hush_pyflakes = [set_twilio_proxy, TwilioRestClient, TwilioLookupsClient, - TwilioPricingClient, TwilioTaskRouterClient, - TwilioTrunkingClient] +_hush_pyflakes = [set_twilio_proxy, TwilioRestClient, TwilioIpMessagingClient, + TwilioLookupsClient, TwilioPricingClient, + TwilioTaskRouterClient, TwilioTrunkingClient] diff --git a/twilio/rest/ip_messaging.py b/twilio/rest/ip_messaging.py new file mode 100644 index 0000000000..91a07b3c30 --- /dev/null +++ b/twilio/rest/ip_messaging.py @@ -0,0 +1,31 @@ +from twilio.rest.base import TwilioClient +from twilio.rest.resources import UNSET_TIMEOUT +from twilio.rest.resources.ip_messaging.services import Services +from twilio.rest.resources.ip_messaging.credentials import Credentials + + +class TwilioIpMessagingClient(TwilioClient): + """ + A client for accessing the Twilio IP Messaging API. + + The Twilio IP Messaging API provides information about events. For more + information, see the + `IP Messaging API documentation `_. + + :param str account: Your Account Sid from `your dashboard + `_ + :param str token: Your Auth Token from `your dashboard + `_ + :param float timeout: The socket and read timeout for requests to Twilio + """ + + def __init__(self, account=None, token=None, + base="https://ip-messaging.twilio.com", version="v1", + timeout=UNSET_TIMEOUT): + + super(TwilioIpMessagingClient, self).__init__(account, token, base, + version, timeout) + + self.version_uri = "%s/%s" % (base, version) + self.services = Services(self.version_uri, self.auth, timeout) + self.credentials = Credentials(self.version_uri, self.auth, timeout) diff --git a/twilio/rest/resources/ip_messaging/__init__.py b/twilio/rest/resources/ip_messaging/__init__.py new file mode 100644 index 0000000000..55f60ad203 --- /dev/null +++ b/twilio/rest/resources/ip_messaging/__init__.py @@ -0,0 +1,34 @@ +from .services import ( + Service, + Services +) + +from .channels import ( + Channel, + Channels +) + +from .members import ( + Member, + Members +) + +from .messages import ( + Message, + Messages +) + +from .roles import ( + Role, + Roles +) + +from .users import ( + User, + Users +) + +from .credentials import ( + Credential, + Credentials +) diff --git a/twilio/rest/resources/ip_messaging/channels.py b/twilio/rest/resources/ip_messaging/channels.py new file mode 100644 index 0000000000..b7e4f5529a --- /dev/null +++ b/twilio/rest/resources/ip_messaging/channels.py @@ -0,0 +1,78 @@ +from .members import Members +from .messages import Messages +from twilio.rest.resources import NextGenInstanceResource, NextGenListResource + + +class Channel(NextGenInstanceResource): + + subresources = [ + Members, + Messages + ] + + def update(self, **kwargs): + """ + Updates the Channel instance + :param sid: Channel instance identifier + :param type: Channel type + :param friendly_name: Channel's friendly name + :param unique_name: Channel's Unique name + :param attributes: Additional attributes that needs to be stored with + channel + :return: the updated instance + """ + return self.update_instance(**kwargs) + + def delete(self): + """ + Delete this channel + """ + return self.delete_instance() + + +class Channels(NextGenListResource): + + name = "Channels" + instance = Channel + + def list(self, **kwargs): + """ + Returns a page of :class:`Channel` resources as a list. + For paging information see :class:`ListResource`. + + **NOTE**: Due to the potentially voluminous amount of data in an + alert, the full HTTP request and response data is only returned + in the Channel instance resource representation. + """ + return self.get_instances(kwargs) + + def create(self, **kwargs): + """ + Create a channel. + + :param str friendly_name: Channel's friendly name + :param unique_name: Channel's Unique name + :param str attributes: Developer-specific data (json) storage + + :return: A :class:`Channel` object + """ + return self.create_instance(kwargs) + + def delete(self, sid): + """ + Delete a given Channel + """ + return self.delete_instance(sid) + + def update(self, sid, **kwargs): + """ + Updates the Channel instance identified by sid + :param sid: Channel instance identifier + :param type: Channel type + :param friendly_name: Channel's friendly name + :param unique_name: Channel's Unique name + :param attributes: Additional attributes that needs to be stored with + channel + :return: Updated instance + """ + return self.update_instance(sid, kwargs) diff --git a/twilio/rest/resources/ip_messaging/credentials.py b/twilio/rest/resources/ip_messaging/credentials.py new file mode 100644 index 0000000000..3b84f85364 --- /dev/null +++ b/twilio/rest/resources/ip_messaging/credentials.py @@ -0,0 +1,80 @@ +from twilio.rest.resources import NextGenInstanceResource, NextGenListResource + + +class Credential(NextGenInstanceResource): + + def update(self, credential_type, **kwargs): + """ + Updates this Credential instance + :param sid: Credential instance identifier + :param credential_type: Credential type + :param friendly_name: Credential's friendly name + :param certificate: Credential's certificate + :param private_key: Credential's Private key + :param sandbox: Credential's Sandbox + :param api_key: Credential's Api Key + :return: Updated instance + """ + kwargs['type'] = credential_type + return self.update_instance(**kwargs) + + def delete(self): + """ + Delete this credential + """ + return self.delete_instance() + + +class Credentials(NextGenListResource): + + name = "Credentials" + instance = Credential + + def list(self, **kwargs): + """ + Returns a page of :class:`Credential` resources as a list. + For paging information see :class:`ListResource`. + + **NOTE**: Due to the potentially voluminous amount of data in an + alert, the full HTTP request and response data is only returned + in the Credential instance resource representation. + + :param date after: Only list alerts logged after this datetime + :param date before: Only list alerts logger before this datetime + :param log_level: If 'error', only shows errors. If 'warning', + only show warnings + """ + return self.get_instances(kwargs) + + def create(self, credential_type, **kwargs): + """ + Make a phone call to a number. + + :param str credential_type: The type of credential + :param str friendly_name: The friendly name of the credential. + + :return: A :class:`Credential` object + """ + kwargs["type"] = credential_type + return self.create_instance(kwargs) + + def delete(self, sid): + """ + Delete a given Credential + """ + return self.delete_instance(sid) + + def update(self, sid, credential_type, **kwargs): + """ + Updates the Credential instance identified by sid + :param sid: Credential instance identifier + :param credential_type: Credential type + :param friendly_name: Credential's friendly name + :param certificate: Credential's certificate + :param private_key: Credential's Private key + :param sandbox: Credential's Sandbox + :param api_key: Credential's Api Key + :return: Updated instance + """ + kwargs['type'] = credential_type + return self.update_instance(sid, kwargs) diff --git a/twilio/rest/resources/ip_messaging/members.py b/twilio/rest/resources/ip_messaging/members.py new file mode 100644 index 0000000000..dfdaadf149 --- /dev/null +++ b/twilio/rest/resources/ip_messaging/members.py @@ -0,0 +1,68 @@ +from twilio.rest.resources import NextGenInstanceResource, NextGenListResource + + +class Member(NextGenInstanceResource): + + def update(self, role_sid, **kwargs): + """ + Updates the Member instance identified by sid + :param sid: Member instance identifier + :param role_sid: Member's Role Sid + :param identity: Member's Identity + :return: Updated instance + """ + kwargs['role_sid'] = role_sid + return self.update_instance(**kwargs) + + def delete(self): + """ + Delete this member + """ + return self.delete_instance() + + +class Members(NextGenListResource): + + name = "Members" + instance = Member + + def list(self, **kwargs): + """ + Returns a page of :class:`Member` resources as a list. + For paging information see :class:`ListResource`. + + **NOTE**: Due to the potentially voluminous amount of data in an + alert, the full HTTP request and response data is only returned + in the Member instance resource representation. + + """ + return self.get_instances(kwargs) + + def create(self, identity, **kwargs): + """ + Create a Member. + + :param str identity: The identity of the user. + :param str role: The role to assign the member. + + :return: A :class:`Member` object + """ + kwargs["identity"] = identity + return self.create_instance(kwargs) + + def delete(self, sid): + """ + Delete a given Member + """ + return self.delete_instance(sid) + + def update(self, sid, role_sid, **kwargs): + """ + Updates the Member instance identified by sid + :param sid: Member instance identifier + :param role_sid: Member's Role Sid + :param identity: Member's Identity + :return: Updated instance + """ + kwargs['role_sid'] = role_sid + return self.update_instance(sid, kwargs) diff --git a/twilio/rest/resources/ip_messaging/messages.py b/twilio/rest/resources/ip_messaging/messages.py new file mode 100644 index 0000000000..848ba16095 --- /dev/null +++ b/twilio/rest/resources/ip_messaging/messages.py @@ -0,0 +1,68 @@ +from twilio.rest.resources import NextGenInstanceResource, NextGenListResource + + +class Message(NextGenInstanceResource): + + def update(self, **kwargs): + """ + Updates the Message instance + :param sid: Message instance identifier + :param service_sid: Service instance identifier + :param channel_sid: Channel instance identifier + :param body: Message's body + :return: the updated instance + """ + return self.update_instance(**kwargs) + + def delete(self): + """ + Delete this message + """ + return self.delete_instance() + + +class Messages(NextGenListResource): + + name = "Messages" + instance = Message + + def list(self, **kwargs): + """ + Returns a page of :class:`Message` resources as a list. + For paging information see :class:`ListResource`. + + **NOTE**: Due to the potentially voluminous amount of data in an + alert, the full HTTP request and response data is only returned + in the Message instance resource representation. + + """ + return self.get_instances(kwargs) + + def create(self, body, **kwargs): + """ + Create a Message. + + :param str body: The body of the message. + :param str from: The message author's identity. + + :return: A :class:`Message` object + """ + kwargs["body"] = body + return self.create_instance(kwargs) + + def delete(self, sid): + """ + Delete a given Message + """ + return self.delete_instance(sid) + + def update(self, sid, **kwargs): + """ + Updates the Message instance identified by sid + :param sid: Message instance identifier + :param service_sid: Service instance identifier + :param channel_sid: Channel instance identifier + :param body: Message's body + :return: the updated instance + """ + return self.update_instance(sid, kwargs) diff --git a/twilio/rest/resources/ip_messaging/roles.py b/twilio/rest/resources/ip_messaging/roles.py new file mode 100644 index 0000000000..3e1f232842 --- /dev/null +++ b/twilio/rest/resources/ip_messaging/roles.py @@ -0,0 +1,67 @@ +from twilio.rest.resources import NextGenInstanceResource, NextGenListResource + + +class Role(NextGenInstanceResource): + + def update(self, permission, **kwargs): + """ + Updates this Role instance + :param permission: Role permission + :return: Updated instance + """ + kwargs['permission'] = permission + return self.update_instance(**kwargs) + + def delete(self): + """ + Delete this role + """ + return self.delete_instance() + + +class Roles(NextGenListResource): + + name = "Roles" + instance = Role + + def list(self, **kwargs): + """ + Returns a page of :class:`Role` resources as a list. + For paging information see :class:`ListResource`. + + **NOTE**: Due to the potentially voluminous amount of data in an + alert, the full HTTP request and response data is only returned + in the Role instance resource representation. + + """ + return self.get_instances(kwargs) + + def delete(self, sid): + """ + Delete a given Role + """ + return self.delete_instance(sid) + + def create(self, friendly_name, role_type, permission): + """ + Creates a Role + :param str friendly_name: Human readable name to the Role + :param str role_type: Type of role - deployment or channel + :param str permission: Set of permissions for the role + """ + kwargs = { + "friendly_name": friendly_name, + "type": role_type, + "permission": permission + } + return self.create_instance(kwargs) + + def update(self, sid, permission, **kwargs): + """ + Updates the Role instance identified by sid + :param sid: Role instance identifier + :param permission: Role permission + :return: Updated instance + """ + kwargs['permission'] = permission + return self.update_instance(sid, kwargs) diff --git a/twilio/rest/resources/ip_messaging/services.py b/twilio/rest/resources/ip_messaging/services.py new file mode 100644 index 0000000000..f22c30260a --- /dev/null +++ b/twilio/rest/resources/ip_messaging/services.py @@ -0,0 +1,69 @@ +from .channels import Channels +from .roles import Roles +from .users import Users +from twilio.rest.resources import NextGenInstanceResource, NextGenListResource + + +class Service(NextGenInstanceResource): + + subresources = [ + Channels, + Roles, + Users + ] + + def update(self, **kwargs): + """ + Updates this Service instance + :return: Updated instance + """ + return self.update_instance(**kwargs) + + def delete(self): + """ + Delete this service + """ + return self.delete_instance() + + +class Services(NextGenListResource): + + name = "Services" + instance = Service + + def list(self, **kwargs): + """ + Returns a page of :class:`Service` resources as a list. + For paging information see :class:`ListResource`. + + **NOTE**: Due to the potentially voluminous amount of data in an + alert, the full HTTP request and response data is only returned + in the Service instance resource representation. + + """ + return self.get_instances(kwargs) + + def create(self, friendly_name, **kwargs): + """ + Create a service. + + :param str friendly_name: The friendly name for the service + + :return: A :class:`Service` object + """ + kwargs["friendly_name"] = friendly_name + return self.create_instance(kwargs) + + def delete(self, sid): + """ + Delete a given Service + """ + return self.delete_instance(sid) + + def update(self, sid, **kwargs): + """ + Updates the Service instance identified by sid + :param sid: Service instance identifier + :return: Updated instance + """ + return self.update_instance(sid, kwargs) diff --git a/twilio/rest/resources/ip_messaging/users.py b/twilio/rest/resources/ip_messaging/users.py new file mode 100644 index 0000000000..1439772cc0 --- /dev/null +++ b/twilio/rest/resources/ip_messaging/users.py @@ -0,0 +1,63 @@ +from twilio.rest.resources import NextGenInstanceResource, NextGenListResource + + +class User(NextGenInstanceResource): + + def update(self, **kwargs): + """ + Updates this User instance + :param role_sid: The role to assign the user. + :return: Updated instance + """ + return self.update_instance(**kwargs) + + def delete(self): + """ + Delete this user + """ + return self.delete_instance() + + +class Users(NextGenListResource): + + name = "Users" + instance = User + + def list(self, **kwargs): + """ + Returns a page of :class:`User` resources as a list. + For paging information see :class:`ListResource`. + + **NOTE**: Due to the potentially voluminous amount of data in an + alert, the full HTTP request and response data is only returned + in the User instance resource representation. + + """ + return self.get_instances(kwargs) + + def create(self, identity, **kwargs): + """ + Creates a User + + :param str identity: The identity of the user. + :param str role_sid: The role to assign the user. + + :return: A :class:`User` object + """ + kwargs["identity"] = identity + return self.create_instance(kwargs) + + def delete(self, sid): + """ + Delete a given User + """ + return self.delete_instance(sid) + + def update(self, sid, **kwargs): + """ + Updates the User instance identified by sid + :param sid: User instance identifier + :param role_sid: The role to assign the user. + :return: Updated instance + """ + return self.update_instance(sid, kwargs) From 0f7b73c93ab687b0de0bc4e120042835de889522 Mon Sep 17 00:00:00 2001 From: Senthil Ramakrishnan Date: Wed, 16 Dec 2015 17:02:19 -0800 Subject: [PATCH 2/2] Test resources --- .../ip_messaging/channel_instance.json | 16 ++++++++++++++++ .../ip_messaging/credential_instance.json | 8 ++++++++ .../resources/ip_messaging/member_instance.json | 9 +++++++++ .../ip_messaging/message_instance.json | 12 ++++++++++++ tests/resources/ip_messaging/role_instance.json | 11 +++++++++++ .../ip_messaging/service_instance.json | 17 +++++++++++++++++ tests/resources/ip_messaging/user_instance.json | 10 ++++++++++ 7 files changed, 83 insertions(+) create mode 100644 tests/resources/ip_messaging/channel_instance.json create mode 100644 tests/resources/ip_messaging/credential_instance.json create mode 100644 tests/resources/ip_messaging/member_instance.json create mode 100644 tests/resources/ip_messaging/message_instance.json create mode 100644 tests/resources/ip_messaging/role_instance.json create mode 100644 tests/resources/ip_messaging/service_instance.json create mode 100644 tests/resources/ip_messaging/user_instance.json diff --git a/tests/resources/ip_messaging/channel_instance.json b/tests/resources/ip_messaging/channel_instance.json new file mode 100644 index 0000000000..938a62013a --- /dev/null +++ b/tests/resources/ip_messaging/channel_instance.json @@ -0,0 +1,16 @@ +{ + "sid": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "friendly_name": "update", + "unique_name": "unique", + "attributes": "", + "date_created": "2015-08-20T09:30:24Z", + "date_updated": "2015-08-20T09:30:24Z", + "created_by": "system", + "url": "https://ip-messaging.stage.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "links": { + "members": "https://ip-messaging.stage.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Member", + "messages": "https://ip-messaging.stage.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages" + } +} diff --git a/tests/resources/ip_messaging/credential_instance.json b/tests/resources/ip_messaging/credential_instance.json new file mode 100644 index 0000000000..9b24940277 --- /dev/null +++ b/tests/resources/ip_messaging/credential_instance.json @@ -0,0 +1,8 @@ +{ + "account_sid":"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "sid":"CRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "friendly_name":"MyApp APN Certificate", + "type":"apn", + "date_created":"2015-06-30T21:16:50Z", + "date_updated":"2015-07-30T21:16:50Z" +} diff --git a/tests/resources/ip_messaging/member_instance.json b/tests/resources/ip_messaging/member_instance.json new file mode 100644 index 0000000000..adc75ddcfe --- /dev/null +++ b/tests/resources/ip_messaging/member_instance.json @@ -0,0 +1,9 @@ +{ + "sid": "MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "channel_sid": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "space_sid": "SPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "id": "carl@twilio.com", + "role": "admin", + "url": "/v1/Spaces/SPxx/Channels/CHxx/Members/MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +} diff --git a/tests/resources/ip_messaging/message_instance.json b/tests/resources/ip_messaging/message_instance.json new file mode 100644 index 0000000000..acbe53124f --- /dev/null +++ b/tests/resources/ip_messaging/message_instance.json @@ -0,0 +1,12 @@ +{ + "sid": "IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "space_sid": "SPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "date_created": "2015-07-23T20:20:10Z", + "date_updated": "2015-07-23T20:20:10Z", + "was_edited": true, + "from": "carl@twilio.com", + "to": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "body": "Hello", + "url": "/v1/Spaces/SPxx/Channels/CHxx/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +} diff --git a/tests/resources/ip_messaging/role_instance.json b/tests/resources/ip_messaging/role_instance.json new file mode 100644 index 0000000000..bbd604428c --- /dev/null +++ b/tests/resources/ip_messaging/role_instance.json @@ -0,0 +1,11 @@ +{ + "sid":"RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "account_sid":"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "space_sid": "SPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "name":"Deployment Admin", + "type":"deployment", + "permissions":[ + "createChannel", + "destroyChannel" + ] +} diff --git a/tests/resources/ip_messaging/service_instance.json b/tests/resources/ip_messaging/service_instance.json new file mode 100644 index 0000000000..bc4d56e4a9 --- /dev/null +++ b/tests/resources/ip_messaging/service_instance.json @@ -0,0 +1,17 @@ +{ + "sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "friendly_name": "TestService", + "date_created": "2015-10-21T04:15:36Z", + "date_updated": "2015-10-21T04:15:36Z", + "default_service_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "default_channel_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "typing_indicator_timeout": 5, + "webhooks": {}, + "url": "https://ip-messaging.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "links": { + "channels": "https://ip-messaging.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels", + "roles": "https://ip-messaging.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Roles", + "users": "https://ip-messaging.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users" + } +} diff --git a/tests/resources/ip_messaging/user_instance.json b/tests/resources/ip_messaging/user_instance.json new file mode 100644 index 0000000000..a2326cc20c --- /dev/null +++ b/tests/resources/ip_messaging/user_instance.json @@ -0,0 +1,10 @@ +{ + "sid": "USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "date_created": "2015-08-19T18:18:00Z", + "date_updated": "2015-08-19T18:18:00Z", + "identity": "carl@twilio.com", + "service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "role_sid": null, + "url": "https://ip-messaging.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +}