diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..46ead0b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ + +creds\.sh + +*.komodoproject diff --git a/LICENSE b/LICENSE.md similarity index 99% rename from LICENSE rename to LICENSE.md index 0ad25db..15bc112 100644 --- a/LICENSE +++ b/LICENSE.md @@ -1,7 +1,8 @@ + GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @@ -643,7 +644,7 @@ the "copyright" line and a pointer to where the full notice is found. GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . + along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. @@ -658,4 +659,4 @@ specific requirements. You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see -. +. diff --git a/README.md b/README.md new file mode 100644 index 0000000..4cf85c9 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +sms-sender diff --git a/flowroutenumbersandmessaging/__init__.py b/flowroutenumbersandmessaging/__init__.py new file mode 100644 index 0000000..34404fc --- /dev/null +++ b/flowroutenumbersandmessaging/__init__.py @@ -0,0 +1,10 @@ +__all__ = [ + 'api_helper', + 'configuration', + 'models', + 'controllers', + 'http', + 'exceptions', + 'decorators', + 'flowroute_numbers_and_messaging_client', +] \ No newline at end of file diff --git a/flowroutenumbersandmessaging/__init__.pyc b/flowroutenumbersandmessaging/__init__.pyc new file mode 100644 index 0000000..2d26319 Binary files /dev/null and b/flowroutenumbersandmessaging/__init__.pyc differ diff --git a/flowroutenumbersandmessaging/api_helper.py b/flowroutenumbersandmessaging/api_helper.py new file mode 100644 index 0000000..316ce54 --- /dev/null +++ b/flowroutenumbersandmessaging/api_helper.py @@ -0,0 +1,405 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.api_helper + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" + +import re +import sys +import datetime +import dateutil.parser +import calendar +import email.utils as eut +from time import mktime + +import jsonpickle +import dateutil.parser +from requests.utils import quote + +class APIHelper(object): + + """A Helper Class for various functions associated with API Calls. + + This class contains static methods for operations that need to be + performed during API requests. All of the methods inside this class are + static methods, there is no need to ever initialise an instance of this + class. + + """ + + @staticmethod + def merge_dicts(dict1, dict2): + """Merges two dictionaries into one as a shallow copy. + + Args: + dict1 (dict): The first dictionary. + dict2 (dict): The second dictionary. + + Returns: + dict: A dictionary containing key value pairs + from both the argument dictionaries. In the case + of a key conflict, values from dict2 are used + and those from dict1 are lost. + + """ + temp = dict1.copy() + temp.update(dict2) + return temp + + @staticmethod + def json_serialize(obj): + """JSON Serialization of a given object. + + Args: + obj (object): The object to serialise. + + Returns: + str: The JSON serialized string of the object. + + """ + if obj is None: + return None + + # Resolve any Names if it's one of our objects that needs to have this called on + if isinstance(obj, list): + value = list() + for item in obj: + if hasattr(item, "_names"): + value.append(APIHelper.to_dictionary(item)) + else: + value.append(item) + obj = value + else: + if hasattr(obj, "_names"): + obj = APIHelper.to_dictionary(obj) + + return jsonpickle.encode(obj, False) + + @staticmethod + def json_deserialize(json, unboxing_function=None): + """JSON Deerialization of a given string. + + Args: + json (str): The JSON serialized string to deserialize. + + Returns: + dict: A dictionary representing the data contained in the + JSON serialized string. + + """ + if json is None: + return None + + try: + decoded = jsonpickle.decode(json) + except: + return json + + if unboxing_function is None: + return decoded + elif isinstance(decoded, list): + return [unboxing_function(element) for element in decoded] + else: + return unboxing_function(decoded) + + @staticmethod + def serialize_array(key, array, formatting="indexed"): + """Converts an array parameter to a list of key value tuples. + + Args: + key (str): The name of the parameter. + array (list): The value of the parameter. + formatting (str): The type of key formatting expected. + + Returns: + list: A list with key value tuples for the array elements. + + """ + tuples = [] + + if sys.version_info[0] < 3: + serializable_types = (str, int, long, float, bool, datetime.date, APIHelper.CustomDate) + else: + serializable_types = (str, int, float, bool, datetime.date, APIHelper.CustomDate) + + if isinstance(array[0], serializable_types): + if formatting is "unindexed": + tuples += [("{0}[]".format(key), element) for element in array] + elif formatting is "indexed": + tuples += [("{0}[{1}]".format(key, index), element) for index, element in enumerate(array)] + elif formatting is "plain": + tuples += [(key, element) for element in array] + else: + raise ValueError("Invalid format provided.") + else: + tuples += [("{0}[{1}]".format(key, index), element) for index, element in enumerate(array)] + + return tuples + + @staticmethod + def append_url_with_template_parameters(url, + parameters): + """Replaces template parameters in the given url. + + Args: + url (str): The query url string to replace the template parameters. + parameters (dict): The parameters to replace in the url. + + Returns: + str: URL with replaced parameters. + + """ + # Parameter validation + if url is None: + raise ValueError("URL is None.") + if parameters is None: + return url + + # Iterate and replace parameters + for key in parameters: + element = parameters[key] + replace_value = "" + + # Load parameter value + if element is None: + replace_value = "" + elif isinstance(element, list): + replace_value = "/".join(quote(str(x), safe='') for x in element) + else: + replace_value = quote(str(element), safe='') + + url = url.replace('{{{0}}}'.format(key), str(replace_value)) + + return url + + @staticmethod + def append_url_with_query_parameters(url, + parameters, + array_serialization="indexed"): + """Adds query parameters to a URL. + + Args: + url (str): The URL string. + parameters (dict): The query parameters to add to the URL. + array_serialization (str): The format of array parameter serialization. + + Returns: + str: URL with added query parameters. + + """ + # Parameter validation + if url is None: + raise ValueError("URL is None.") + if parameters is None: + return url + + for key, value in parameters.items(): + seperator = '&' if '?' in url else '?' + if value is not None: + if isinstance(value, list): + value = [element for element in value if element] + if array_serialization is "csv": + url += "{0}{1}={2}".format(seperator, key, + ",".join(quote(str(x), safe='') for x in value)) + elif array_serialization is "psv": + url += "{0}{1}={2}".format(seperator, key, + "|".join(quote(str(x), safe='') for x in value)) + elif array_serialization is "tsv": + url += "{0}{1}={2}".format(seperator, key, + "\t".join(quote(str(x), safe='') for x in value)) + else: + url += "{0}{1}".format(seperator, + "&".join(("{0}={1}".format(k, quote(str(v), safe=''))) + for k, v in APIHelper.serialize_array(key, value, array_serialization))) + else: + url += "{0}{1}={2}".format(seperator, key, quote(str(value), safe='')) + + return url + + @staticmethod + def clean_url(url): + """Validates and processes the given query Url to clean empty slashes. + + Args: + url (str): The given query Url to process. + + Returns: + str: Clean Url as string. + + """ + # Ensure that the urls are absolute + regex = "^https?://[^/]+" + match = re.match(regex, url) + if match is None: + raise ValueError('Invalid Url format.') + + protocol = match.group(0) + index = url.find('?') + query_url = url[len(protocol): index if index != -1 else None] + query_url = re.sub("//+", "/", query_url) + parameters = url[index:] if index != -1 else "" + + return protocol + query_url + parameters + + @staticmethod + def form_encode_parameters(form_parameters, + array_serialization="indexed"): + """Form encodes a dictionary of form parameters + + Args: + form_parameters (dictionary): The given dictionary which has + atleast one model to form encode. + array_serialization (str): The format of array parameter serialization. + + Returns: + dict: A dictionary of form encoded properties of the model. + + """ + encoded = [] + + for key, value in form_parameters.items(): + encoded += APIHelper.form_encode(value, key, array_serialization) + + return encoded + + @staticmethod + def form_encode(obj, + instance_name, + array_serialization="indexed"): + """Encodes a model in a form-encoded manner such as person[Name] + + Args: + obj (object): The given Object to form encode. + instance_name (string): The base name to appear before each entry + for this object. + array_serialization (string): The format of array parameter serialization. + + Returns: + dict: A dictionary of form encoded properties of the model. + + """ + retval = [] + + # If we received an object, resolve it's field names. + if hasattr(obj, "_names"): + obj = APIHelper.to_dictionary(obj) + + if obj is None: + return [] + elif isinstance(obj, list): + for element in APIHelper.serialize_array(instance_name, obj, array_serialization): + retval += APIHelper.form_encode(element[1], element[0], array_serialization) + elif isinstance(obj, dict): + for item in obj: + retval += APIHelper.form_encode(obj[item], instance_name + "[" + item + "]", array_serialization) + else: + retval.append((instance_name, obj)) + + return retval + + @staticmethod + def to_dictionary(obj): + """Creates a dictionary representation of a class instance. The + keys are taken from the API description and may differ from language + specific variable names of properties. + + Args: + obj: The object to be converted into a dictionary. + + Returns: + dictionary: A dictionary form of the model with properties in + their API formats. + + """ + dictionary = dict() + + # Loop through all properties in this model + for name in obj._names: + value = getattr(obj, name) + if isinstance(value, list): + # Loop through each item + dictionary[obj._names[name]] = list() + for item in value: + dictionary[obj._names[name]].append(APIHelper.to_dictionary(item) if hasattr(item, "_names") else item) + elif isinstance(value, dict): + # Loop through each item + dictionary[obj._names[name]] = dict() + for key in value: + dictionary[obj._names[name]][key] = APIHelper.to_dictionary(value[key]) if hasattr(value[key], "_names") else value[key] + else: + dictionary[obj._names[name]] = APIHelper.to_dictionary(value) if hasattr(value, "_names") else value + + # Return the result + return dictionary + + class CustomDate(object): + + """ A base class for wrapper classes of datetime. + + This class contains methods which help in + appropriate serialization of datetime objects. + + """ + + def __init__(self, dtime, value=None): + self.datetime = dtime + if not value: + self.value = self.from_datetime(dtime) + else: + self.value = value + + def __str__(self): + return self.value + + def __getstate__(self): + return self.value + + def __setstate__(self, state): + pass + + class HttpDateTime(CustomDate): + + """ A wrapper class for datetime to support HTTP date format.""" + + @classmethod + def from_datetime(cls, date_time): + return eut.formatdate(timeval=mktime(date_time.timetuple()), + localtime=False, usegmt=True) + + @classmethod + def from_value(cls, value): + dtime = datetime.datetime.fromtimestamp(eut.mktime_tz(eut.parsedate_tz(value))) + return cls(dtime, value) + + class UnixDateTime(CustomDate): + + """ A wrapper class for datetime to support Unix date format.""" + + def __str__(self): + return str(self.value) + + @classmethod + def from_datetime(cls, date_time): + return calendar.timegm(date_time.utctimetuple()) + + @classmethod + def from_value(cls, value): + dtime = datetime.datetime.utcfromtimestamp(float(value)) + return cls(dtime, float(value)) + + class RFC3339DateTime(CustomDate): + + """ A wrapper class for datetime to support Rfc 3339 format.""" + + @classmethod + def from_datetime(cls, date_time): + d = dateutil.parser.parse(date_time).isoformat() + return d + + + @classmethod + def from_value(cls, value): + dtime = dateutil.parser.parse(value) + return cls(dtime, value) diff --git a/flowroutenumbersandmessaging/api_helper.pyc b/flowroutenumbersandmessaging/api_helper.pyc new file mode 100644 index 0000000..6df819c Binary files /dev/null and b/flowroutenumbersandmessaging/api_helper.pyc differ diff --git a/flowroutenumbersandmessaging/configuration.py b/flowroutenumbersandmessaging/configuration.py new file mode 100644 index 0000000..86cc710 --- /dev/null +++ b/flowroutenumbersandmessaging/configuration.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.configuration + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" +from .api_helper import APIHelper + + +class Configuration(object): + + """A class used for configuring the SDK by a user. + + This class need not be instantiated and all properties and methods + are accessible without instance creation. + + """ + + # Set the array parameter serialization method + # (allowed: indexed, unindexed, plain, csv, tsv, psv) + array_serialization = "indexed" + + # The base Uri for API calls + base_uri = 'https://api.flowroute.com' + + # The username to use with basic authentication + # TODO: Set an appropriate value + basic_auth_user_name = "YOUR API KEY" + + # The password to use with basic authentication + # TODO: Set an appropriate value + basic_auth_password = "YOUR SECRET KEY" + diff --git a/flowroutenumbersandmessaging/configuration.pyc b/flowroutenumbersandmessaging/configuration.pyc new file mode 100644 index 0000000..3f07573 Binary files /dev/null and b/flowroutenumbersandmessaging/configuration.pyc differ diff --git a/flowroutenumbersandmessaging/controllers/__init__.py b/flowroutenumbersandmessaging/controllers/__init__.py new file mode 100644 index 0000000..b8e2ece --- /dev/null +++ b/flowroutenumbersandmessaging/controllers/__init__.py @@ -0,0 +1,6 @@ +__all__ = [ + 'base_controller', + 'numbers_controller', + 'routes_controller', + 'messages_controller', +] \ No newline at end of file diff --git a/flowroutenumbersandmessaging/controllers/__init__.pyc b/flowroutenumbersandmessaging/controllers/__init__.pyc new file mode 100644 index 0000000..6266b6c Binary files /dev/null and b/flowroutenumbersandmessaging/controllers/__init__.pyc differ diff --git a/flowroutenumbersandmessaging/controllers/base_controller.py b/flowroutenumbersandmessaging/controllers/base_controller.py new file mode 100644 index 0000000..1b2bfd0 --- /dev/null +++ b/flowroutenumbersandmessaging/controllers/base_controller.py @@ -0,0 +1,124 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessagingcontrollers.base_controller + + This file was automatically generated by APIMATIC v2.0 + ( https://apimatic.io ). +""" + +from ..api_helper import APIHelper +from ..http.http_context import HttpContext +from ..http.requests_client import RequestsClient +from ..exceptions.error_exception import ErrorException +from ..exceptions.api_exception import APIException +from ..http.auth.basic_auth import BasicAuth + + +class BaseController(object): + + """All controllers inherit from this base class. + + Attributes: + http_client (HttpClient): The HttpClient which a specific controller + instance will use. By default all the controller objects share + the same HttpClient. A user can use his own custom HttpClient + as well. + http_call_back (HttpCallBack): An object which holds call back + methods to be called before and after the execution of an + HttpRequest. + """ + + http_client = RequestsClient() + + http_call_back = None + + global_headers = { + 'user-agent': 'Flowroute SDK v3.0' + } + + def __init__(self, client=None, call_back=None): + if client is not None: + self.http_client = client + if call_back is not None: + self.http_call_back = call_back + + @staticmethod + def validate_parameters(**kwargs): + """Validates required parameters of an endpoint. + + Args: + kwargs (dict): A dictionary of the required parameters. + + """ + for name, value in kwargs.items(): + if value is None: + raise ValueError("Required parameter {} cannot be None.". + format(name)) + + def execute_request(self, request, binary=False): + """Executes an HttpRequest. + + Args: + request (HttpRequest): The HttpRequest to execute. + binary (bool): A flag which should be set to True if + a binary response is expected. + + Returns: + HttpContext: The HttpContext of the request. It contains, + both, the request itself and the HttpResponse object. + + """ + # Invoke the on before request HttpCallBack if specified + if self.http_call_back is not None: + self.http_call_back.on_before_request(request) + + # Add global headers to request + request.headers = APIHelper.merge_dicts(self.global_headers, + request.headers) + + # Invoke the API call to fetch the response. + func = self.http_client.execute_as_binary if binary else \ + self.http_client.execute_as_string + response = func(request) + context = HttpContext(request, response) + + # Invoke the on after response HttpCallBack if specified + if self.http_call_back is not None: + self.http_call_back.on_after_response(context) + + return context + + @staticmethod + def validate_response(context): + """Validates an HTTP response by checking for global errors. + + Args: + context (HttpContext): The HttpContext of the API call. + + """ + if (context.response.status_code < 200) or \ + (context.response.status_code > 208): + raise APIException('HTTP response not OK.', context) + + # Process request and status code and response text + def handle_request_and_response(self, request): + BasicAuth.apply(request) + context = self.execute_request(request) + + # Endpoint and global error handling using HTTP status codes. + if context.response.status_code == 401: + raise ErrorException('Unauthorized – There was an issue with your ' + 'API credentials.', context) + elif context.response.status_code == 403: + raise ErrorException('Forbidden – You don\'t have permission to ' + 'access this resource.', context) + elif context.response.status_code == 404: + raise ErrorException('The specified resource was not found', + context) + elif context.response.status_code == 422: + raise ErrorException('Unprocessable Entity - You tried to enter an' + ' incorrect value.', context) + self.validate_response(context) + + return APIHelper.json_deserialize(context.response.raw_body) diff --git a/flowroutenumbersandmessaging/controllers/base_controller.pyc b/flowroutenumbersandmessaging/controllers/base_controller.pyc new file mode 100644 index 0000000..12a04ac Binary files /dev/null and b/flowroutenumbersandmessaging/controllers/base_controller.pyc differ diff --git a/flowroutenumbersandmessaging/controllers/cnams_controller.py b/flowroutenumbersandmessaging/controllers/cnams_controller.py new file mode 100644 index 0000000..1a9988f --- /dev/null +++ b/flowroutenumbersandmessaging/controllers/cnams_controller.py @@ -0,0 +1,203 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.controllers.cnams_controller + + This file was automatically generated by APIMATIC v2.0 (https://apimatic.io). +""" + +from .base_controller import BaseController +from ..api_helper import APIHelper +from ..configuration import Configuration +from .numbers_controller import NumbersController + + +class CNAMsController(BaseController): + + """A Controller to access Endpoints in the + flowroutenumbersandmessaging API.""" + + def list_cnams(self, + limit=None, + offset=None, + is_approved=None): + """Does a GET request to /v2/cnams. + + Returns a list of all cnams owned by the user. + + Args: + limit (int, optional): Limits the number of items to retrieve. A + maximum of 200 items can be retrieved. + offset (int, optional): Offsets the list of phone numbers by your + specified value. For example, if you have 4 phone numbers and + you entered 1 as your offset value, then only 3 of your phone + numbers will be displayed in the response. + is_approved if set to true or false, will only show matching records + + Returns: + mixed: Response from the API. A JSON object of E911 Records + that satisfy your search criteria. + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/cnams' + _query_parameters = { + 'limit': limit, + 'offset': offset + } + if is_approved is not None: + _query_parameters['is_approved'] = is_approved + + _query_builder = APIHelper.append_url_with_query_parameters( + _query_builder, + _query_parameters, + Configuration.array_serialization) + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare and execute request + _request = self.http_client.get(_query_url) + + return self.handle_request_and_response(_request) + + def get_cnam(self, cnam_id): + """Does a GET request to /v2/cnams/. + + Returns a record detail for the CNAM Record Id specified + + Args: + + Returns: + mixed: Response from the API. A JSON object of of an E911 record + that satisfy your search criteria. + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/cnams/{}'.format(cnam_id) + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare and execute request + _request = self.http_client.get(_query_url) + + return self.handle_request_and_response(_request) + + def create_cnam_record(self, value): + """Does a POST request to /v2/cnams. + + Searches for CNAM Records that match the criteria + + Args: + value (string, required): The text string for the new CNAM record + + Returns: + mixed: Response from the API. A JSON object of of a CNAM record + with the new data + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + body = { + "value": value + } + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/cnams' + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/json' + } + + # Prepare and execute request + _request = self.http_client.post(_query_url, headers=_headers, + parameters=body) + + return self.handle_request_and_response(_request) + + def associate_cnam(self, cnam_id, phone_number): + # first, verify the number belongs to the user + did = NumbersController().list_account_phone_numbers( + contains=phone_number) + + if did is None: + error_string = "Error, this phone number does not belong to you." + return error_string + + did = did['data'][0]['id'] + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/numbers/{}/relationships/cnam/{}'.format(did, + cnam_id) + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/json' + } + + # Prepare and execute request + _request = self.http_client.patch(_query_url, headers=_headers) + + return self.handle_request_and_response(_request) + + def unassociate_cnam(self, phone_number): + # first, verify the number belongs to the user + did = NumbersController().list_account_phone_numbers( + contains=phone_number) + + if did is None: + error_string = "Error, this phone number does not belong to you." + return error_string + + did = did['data'][0]['id'] + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/numbers/{}/relationships/cnam'.format(did) + _query_url = APIHelper.clean_url(_query_builder) + # Prepare headers + _headers = { + 'accept': 'application/json' + } + + # Prepare and execute request + _request = self.http_client.delete(_query_url, headers=_headers) + + return self.handle_request_and_response(_request) + + def remove_cnam(self, cnam_id): + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/cnams/{}'.format(cnam_id) + _query_url = APIHelper.clean_url(_query_builder) + # Prepare headers + _headers = { + 'accept': 'application/json' + } + + # Prepare and execute request + _request = self.http_client.delete(_query_url, headers=_headers) + + return self.handle_request_and_response(_request) diff --git a/flowroutenumbersandmessaging/controllers/cnams_controller.pyc b/flowroutenumbersandmessaging/controllers/cnams_controller.pyc new file mode 100644 index 0000000..ee8df3f Binary files /dev/null and b/flowroutenumbersandmessaging/controllers/cnams_controller.pyc differ diff --git a/flowroutenumbersandmessaging/controllers/e911s_controller.py b/flowroutenumbersandmessaging/controllers/e911s_controller.py new file mode 100644 index 0000000..7436b66 --- /dev/null +++ b/flowroutenumbersandmessaging/controllers/e911s_controller.py @@ -0,0 +1,490 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.controllers.e911s_controller + + This file was automatically generated by APIMATIC v2.0 (https://apimatic.io) +""" + +from .base_controller import BaseController +from ..api_helper import APIHelper +from ..configuration import Configuration + + +class E911sController(BaseController): + + """A Controller to access Endpoints in the + flowroutenumbersandmessaging API.""" + + def list_e911s(self, + limit=None, + offset=None, + state=None): + """Does a GET request to /v2/e911s. + + Returns a list of all Central Office (exchange) codes containing + purchasable phone numbers. + + Args: + limit (int, optional): Limits the number of items to retrieve. A + maximum of 200 items can be retrieved. + offset (int, optional): Offsets the list of phone numbers by your + specified value. For example, if you have 4 phone numbers and + you entered 1 as your offset value, then only 3 of your phone + numbers will be displayed in the response. + state (2 char, optional): Restricts the results to the specified + state. + + Returns: + mixed: Response from the API. A JSON object of E911 Records + that satisfy your search criteria. + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/e911s' + _query_parameters = { + 'limit': limit, + 'offset': offset, + 'state': state + } + _query_builder = APIHelper.append_url_with_query_parameters( + _query_builder, _query_parameters, + Configuration.array_serialization) + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare and execute request + _request = self.http_client.get(_query_url) + + return self.handle_request_and_response(_request) + + def get_e911(self, e911_id): + """Does a GET request to /v2/e911s/. + + Returns a record detail for the E911 Record Id specified + + Args: + + Returns: + mixed: Response from the API. A JSON object of of an E911 record + that satisfy your search criteria. + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/e911s/{}'.format(e911_id) + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare and execute request + _request = self.http_client.get(_query_url) + + return self.handle_request_and_response(_request) + + def validate_address(self, + label, + first_name, + last_name, + street_name, + street_number, + city, + state, + country, + zipcode, + address_type=None, + address_type_number=None): + """Does a POST request to /v2/e911s/validate. + + Returns a 204 No Content on success, or a 404 with error data + + Args: + label (string): the alias or friendly name of your entry + first_name (string): + last_name (string): + street_name (string): + street_number (string): + city (string): + state (2 character string): + country (string USA or Canada): + zipcode (string postal code) + address_type (string address type) + address_type_number (string when address_type used, required) + + Returns: + mixed: Response from the API. A 204 - No Content or a + JSON object ith error data + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + body = { + 'data': { + 'type': 'e911', + 'attributes': { + 'label': label, + 'first_name': first_name, + 'last_name': last_name, + 'street_name': street_name, + 'street_number': street_number, + 'city': city, + 'state': state, + 'country': country, + 'zip': zipcode, + } + } + } + + if address_type and address_type_number: + body['data']['attributes']['address_type'] = address_type + body['data']['attributes']['address_type_number'] = address_type_number + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/e911s/validate' + + # Return appropriate type + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/vnd.api+json' + } + + # Prepare and execute request + _request = self.http_client.post(_query_url, headers=_headers, + parameters=APIHelper.json_serialize( + body)) + + return self.handle_request_and_response(_request) + + def create_address(self, + label, + first_name, + last_name, + street_name, + street_number, + city, + state, + country, + zipcode, + address_type=None, + address_type_number=None): + """Does a POST request to /v2/e911s. + + Creates an address record that can then be associated + with 1 or more DIDs + + Args: + label (string): the alias or friendly name of your entry + first_name (string): + last_name (string): + street_name (string): + street_number (string): + city (string): + state (2 character string): + country (string USA or Canada): + zipcode (string postal code) + address_type (string address type) + address_type_number (string required if address_type specified) + + Returns: + mixed: Response from the API. A JSON object containing the new + record information. + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + body = { + 'data': { + 'type': 'e911', + 'attributes': { + 'label': label, + 'first_name': first_name, + 'last_name': last_name, + 'street_name': street_name, + 'street_number': street_number, + 'city': city, + 'state': state, + 'country': country, + 'zip': zipcode, + } + } + } + + if address_type and address_type_number: + body['data']['attributes']['address_type'] = address_type + body['data']['attributes']['address_type_number'] = address_type_number + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/e911s' + + # Return appropriate type + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/vnd.api+json' + } + + # Prepare and execute request + _request = self.http_client.post(_query_url, headers=_headers, + parameters=APIHelper.json_serialize( + body)) + + return self.handle_request_and_response(_request) + + def update_address(self, + e911_id, + label=None, + first_name=None, + last_name=None, + street_name=None, + street_number=None, + city=None, + state=None, + country=None, + zipcode=None, + address_type=None, + address_type_number=None): + + """Does a PATCH request to /v2/e911s/. + + Updates an existing address record and any associations it may have + + Args: + e911_id (integer, required): the id of the e911 record to update + label (string, optional): the alias or friendly name of your entry + first_name (string, optional): + last_name (string, optional): + street_name (string, optional): + street_number (string, optional): + city (string, optional): + state (2 character string, optional): + country (string USA or Canada, optional): + zipcode (string postal code, optional) + + Returns: + mixed: Response from the API. A JSON object containing the + new record information. + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + cur_record = self.get_e911(e911_id) + record_data = cur_record + + # Only update the fields specified + if label is not None: + record_data['data']['attributes']['label'] = label + if first_name is not None: + record_data['data']['attributes']['first_name'] = first_name + if last_name is not None: + record_data['data']['attributes']['last_name'] = last_name + if street_name is not None: + record_data['data']['attributes']['street_name'] = street_name + if street_number is not None: + record_data['data']['attributes']['street_number'] = \ + str(street_number) + if city is not None: + record_data['data']['attributes']['city'] = city + if state is not None: + record_data['data']['attributes']['state'] = state + if country is not None: + record_data['data']['attributes']['country'] = country + if zipcode is not None: + record_data['data']['attributes']['zip'] = str(zipcode) + record_data['data']['attributes']['zip_code'] = str(zipcode) + + record_data['data']['attributes']['address_type'] = address_type + record_data['data']['attributes']['address_type_number'] = \ + address_type_number + + # Fix address_type if not used + if 'address_type' in record_data['data']['attributes'] and \ + record_data['data']['attributes']['address_type'] == u'': + record_data['data']['attributes'].pop('address_type', None) + record_data['data']['attributes'].pop('address_type_number', None) + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/e911s/{}'.format(e911_id) + + # Return appropriate type + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/vnd.api+json' + } + + # Prepare and execute request + _request = self.http_client.patch(_query_url, headers=_headers, + parameters=APIHelper.json_serialize( + record_data)) + + return self.handle_request_and_response(_request) + + def delete_address(self, e911_id): + """Performs a DELETE request to /v2/e911s/. + + Removes the existing address record and any associations it may have + + Args: + e911_id (integer, required): the id of the e911 record to update + + Returns: + mixed: Response from the API. A 204 - No Content or a + JSON object ith error data + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/e911s/{}'.format(e911_id) + + # Return appropriate type + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/vnd.api+json' + } + + # Prepare and execute request + _request = self.http_client.delete(_query_url, headers=_headers) + + return self.handle_request_and_response(_request) + + def associate(self, e911_id, did): + """Does a PATCH request to /v2/numbers//relationships/e911s/. + + Associates the specified e911 record with the specified did + + Args: + e911_id (integer, required): the id of the e911 record to update + did (string, required): the phone number to associate with + + Returns: + mixed: Response from the API. A 204 - No Content or a + JSON object ith error data + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/numbers/{}/relationships/e911s/{}'.format(did, + e911_id) + + # Return appropriate type + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/vnd.api+json' + } + + # Prepare and execute request + _request = self.http_client.patch(_query_url, headers=_headers) + + return self.handle_request_and_response(_request) + + def disconnect(self, did): + """Does a DELETE request to /v2/numbers//relationships/e911s. + + Un-Associates the specified e911 record with the specified did + + Args: + did (string, required): the phone number to associate with + + Returns: + mixed: Response from the API. A 204 - No Content or a + JSON object ith error data + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/numbers/{}/relationships/e911s'.format(did) + + # Return appropriate type + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/vnd.api+json' + } + + # Prepare and execute request + _request = self.http_client.delete(_query_url, headers=_headers) + + return self.handle_request_and_response(_request) + + def list_dids_for_e911(self, e911_id): + """Does a GET request to /v2/e911s//relationships/numbers + + Lists all Did records associated with the specified E911 record + + Args: + e911_id (integer, required): the id of the e911 record to query + + Returns: + mixed: Response from the API. A JSON Object list with the associated + DID records + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/e911s/{}/relationships/numbers'.format(e911_id) + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare and execute request + _request = self.http_client.get(_query_url) + + return self.handle_request_and_response(_request) + diff --git a/flowroutenumbersandmessaging/controllers/e911s_controller.pyc b/flowroutenumbersandmessaging/controllers/e911s_controller.pyc new file mode 100644 index 0000000..ce55d16 Binary files /dev/null and b/flowroutenumbersandmessaging/controllers/e911s_controller.pyc differ diff --git a/flowroutenumbersandmessaging/controllers/messages_controller.py b/flowroutenumbersandmessaging/controllers/messages_controller.py new file mode 100644 index 0000000..0f81e3d --- /dev/null +++ b/flowroutenumbersandmessaging/controllers/messages_controller.py @@ -0,0 +1,345 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.controllers.messages_controller + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +from .base_controller import BaseController +from ..api_helper import APIHelper +from ..configuration import Configuration +from ..models.mdr_2 import MDR2 +import json + + +class MessagesController(BaseController): + + """A Controller to access Endpoints in the + flowroutenumbersandmessaging API.""" + + def look_up_a_set_of_messages(self, + start_date, + end_date=None, + limit=None, + offset=None): + """Does a GET request to /v2.1/messages. + + Retrieves a list of Message Detail Records (MDRs) within a specified + date range. Date and time is based on Coordinated Universal Time + (UTC). + + Args: + start_date (datetime): The beginning date and time, in UTC, on + which to perform an MDR search. The DateTime can be formatted + as YYYY-MM-DDor YYYY-MM-DDTHH:mm:ss.SSZ. + end_date (datetime, optional): The ending date and time, in UTC, + on which to perform an MDR search. The DateTime can be + formatted as YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss.SSZ. + limit (int, optional): The number of MDRs to retrieve at one time. + You can set as high of a number as you want, but the number + cannot be negative and must be greater than 0 (zero). + offset (int, optional): The number of MDRs to skip when performing + a query. The number must be 0 (zero) or greater, but cannot be + negative. + + Returns: + mixed: Response from the API. OK + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + parsed_end_date = None + + if end_date is not None: + parsed_end_date = APIHelper.RFC3339DateTime(end_date) + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2.1/messages' + _query_parameters = { + 'start_date': APIHelper.RFC3339DateTime(start_date), + 'end_date': parsed_end_date, + 'limit': limit, + 'offset': offset + } + _query_builder = APIHelper.append_url_with_query_parameters( + _query_builder, + _query_parameters, + Configuration.array_serialization) + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/json' + } + + # Prepare and execute request + _request = self.http_client.get(_query_url, headers=_headers) + + return self.handle_request_and_response(_request) + + def look_up_a_message_detail_record(self, + id): + """Does a GET request to /v2.1/messages/{id}. + + Searches for a specific message record ID and returns a Message Detail + Record (in MDR2 format). + + Args: + id (string): The unique message detail record identifier (MDR ID) + of any message. When entering the MDR ID, the number should + include the mdr2- preface. + + Returns: + MDR2: Response from the API. OK + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2.1/messages/{id}' + _query_builder = APIHelper.append_url_with_template_parameters( + _query_builder, { + 'id': id + }) + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/json' + } + + # Prepare and execute request + _request = self.http_client.get(_query_url, headers=_headers) + + return self.handle_request_and_response(_request) + + def send_a_message(self, body): + """Does a POST request to /v2.1/messages. + + Sends an SMS or MMS from a Flowroute long code or toll-free phone + number to another valid phone number. + + Args: + body (Message): The SMS or MMS message to send. + + Returns: + mixed: Response from the API. ACCEPTED + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2.1/messages' + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/vnd.api+json', + 'content-type': 'application/vnd.api+json; charset=utf-8' + } + + # Prepare and execute request + _request = self.http_client.post(_query_url, + headers=_headers, + parameters=APIHelper.json_serialize(json.loads(body))) + + return self.handle_request_and_response(_request) + + def set_account_level_sms_callback(self, url): + """Does a PUT request to /v2.1/messages/sms_callback. + + Sets the callback url for all sms messages. + + Args: + url (string): The callback url to be hit. + + Returns: + mixed: Response from the API. ACCEPTED + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2.1/messages/sms_callback' + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/vnd.api+json', + 'content-type': 'application/vnd.api+json; charset=utf-8' + } + + body = { + 'data': { + 'attributes': { + 'callback_url': url + } + } + } + + # Prepare and execute request + _request = self.http_client.put(_query_url, + headers=_headers, + parameters=APIHelper.json_serialize(body)) + + return self.handle_request_and_response(_request) + + def set_account_level_mms_callback(self, url): + """Does a PUT request to /v2.1/messages/mms_callback. + + Sets the callback url for all mms messages. + + Args: + url (string): The callback url to be hit. + + Returns: + mixed: Response from the API. ACCEPTED + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2.1/messages/mms_callback' + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/vnd.api+json', + 'content-type': 'application/vnd.api+json; charset=utf-8' + } + + body = { + 'data': { + 'attributes': { + 'callback_url': url + } + } + } + + # Prepare and execute request + _request = self.http_client.put(_query_url, + headers=_headers, + parameters=APIHelper.json_serialize( + body)) + + return self.handle_request_and_response(_request) + + def set_account_level_dlr_callback(self, url): + """Does a PUT request to /v2.1/messages/dlr_callback. + + Sets the callback url for all delivery receipts (dlrs) + + Args: + url (string): The callback url to be hit. + + Returns: + mixed: Response from the API. ACCEPTED + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2.1/messages/dlr_callback' + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/vnd.api+json', + 'content-type': 'application/vnd.api+json; charset=utf-8' + } + + body = { + 'data': { + 'attributes': { + 'callback_url': url + } + } + } + + # Prepare and execute request + _request = self.http_client.put(_query_url, + headers=_headers, + parameters=APIHelper.json_serialize( + body)) + + return self.handle_request_and_response(_request) + + def set_did_level_dlr_callback(self, number_id, dlr_url): + """Does a POST request to /v2/numbers/number_id/relationships/dlr_callback + + Sets the callback url for all delivery receipts (dlrs) for the + specified did + + Args: + number_id (integer): pk of the DID record + url (string): The callback url to be hit. + + Returns: + mixed: Response from the API. ACCEPTED + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/numbers/{}/relationships/dlr_callback'.format(number_id) + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/vnd.api+json', + 'content-type': 'application/vnd.api+json; charset=utf-8' + } + + body = { + 'data': { + 'attributes': { + 'callback_url': dlr_url + } + } + } + + # Prepare and execute request + _request = self.http_client.post(_query_url, + headers=_headers, + parameters=APIHelper.json_serialize( + body)) + + return self.handle_request_and_response(_request) \ No newline at end of file diff --git a/flowroutenumbersandmessaging/controllers/messages_controller.pyc b/flowroutenumbersandmessaging/controllers/messages_controller.pyc new file mode 100644 index 0000000..c8294af Binary files /dev/null and b/flowroutenumbersandmessaging/controllers/messages_controller.pyc differ diff --git a/flowroutenumbersandmessaging/controllers/numbers_controller.py b/flowroutenumbersandmessaging/controllers/numbers_controller.py new file mode 100644 index 0000000..c653487 --- /dev/null +++ b/flowroutenumbersandmessaging/controllers/numbers_controller.py @@ -0,0 +1,480 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.controllers.numbers_controller + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +from .base_controller import BaseController +from ..api_helper import APIHelper +from ..configuration import Configuration +from ..models.number_26 import Number26 + + +class NumbersController(BaseController): + + """A Controller to access Endpoints in the + flowroutenumbersandmessaging API.""" + + def list_available_exchange_codes(self, + limit=None, + offset=None, + max_setup_cost=None, + areacode=None): + """Does a GET request to /v2/numbers/available/exchanges. + + Returns a list of all Central Office (exchange) codes containing + purchasable phone numbers. + + Args: + limit (int, optional): Limits the number of items to retrieve. A + maximum of 200 items can be retrieved. + offset (int, optional): Offsets the list of phone numbers by your + specified value. For example, if you have 4 phone numbers and + you entered 1 as your offset value, then only 3 of your phone + numbers will be displayed in the response. + max_setup_cost (float, optional): Restricts the results to the + specified maximum non-recurring setup cost. + areacode (int, optional): Restricts the results to the specified + area code. + + Returns: + mixed: Response from the API. A JSON object of Central Office + (exchange) codes containing + purchasable phone numbers that satisfy your search criteria. + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/numbers/available/exchanges' + _query_parameters = { + 'limit': limit, + 'offset': offset, + 'max_setup_cost': max_setup_cost, + 'areacode': areacode + } + _query_builder = APIHelper.append_url_with_query_parameters( + _query_builder, + _query_parameters, + Configuration.array_serialization) + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare and execute request + _request = self.http_client.get(_query_url) + + return self.handle_request_and_response(_request) + + def list_available_area_codes(self, + limit=None, + offset=None, + max_setup_cost=None): + """Does a GET request to /v2/numbers/available/areacodes. + + Returns a list of all Numbering Plan Area (NPA) codes containing + purchasable phone numbers. + + Args: + limit (int, optional): Limits the number of items to retrieve. A + maximum of 400 items can be retrieved. + offset (int, optional): Offsets the list of phone numbers by your + specified value. For example, if you have 4 phone numbers and + you entered 1 as your offset value, then only 3 of your phone + numbers will be displayed in the response. + max_setup_cost (float, optional): Restricts the results to the + specified maximum non-recurring setup cost. + + Returns: + mixed: Response from the API. A JSON object of area codes containing + purchasable phone numbers that satisfy your search criteria. + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/numbers/available/areacodes' + _query_parameters = { + 'limit': limit, + 'offset': offset, + 'max_setup_cost': max_setup_cost + } + _query_builder = APIHelper.append_url_with_query_parameters( + _query_builder, + _query_parameters, + Configuration.array_serialization) + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare and execute request + _request = self.http_client.get(_query_url) + + return self.handle_request_and_response(_request) + + def search_for_purchasable_phone_numbers(self, + starts_with=None, + contains=None, + ends_with=None, + limit=None, + offset=None, + rate_center=None, + state=None): + """Does a GET request to /v2/numbers/available. + + This endpoint lets you search for phone numbers by state or rate + center, or by your specified search value. + + Args: + starts_with (int, optional): Retrieve phone numbers that start + with the specified value. + contains (int, optional): Retrieve phone numbers containing the + specified value. + ends_with (int, optional): Retrieve phone numbers that end with + the specified value. + limit (int, optional): Limits the number of items to retrieve. A + maximum of 200 items can be retrieved. + offset (int, optional): Offsets the list of phone numbers by your + specified value. For example, if you have 4 phone numbers and + you entered 1 as your offset value, then only 3 of your phone + numbers will be displayed in the response. + rate_center (string, optional): Filters by and displays phone + numbers in the specified rate center. + state (string, optional): Filters by and displays phone numbers in + the specified state. Optional unless a ratecenter is + specified. + + Returns: + mixed: Response from the API. OK + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/numbers/available' + _query_parameters = { + 'starts_with': starts_with, + 'contains': contains, + 'ends_with': ends_with, + 'limit': limit, + 'offset': offset, + 'rate_center': rate_center, + 'state': state + } + _query_builder = APIHelper.append_url_with_query_parameters( + _query_builder, + _query_parameters, + Configuration.array_serialization) + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/json' + } + + # Prepare and execute request + _request = self.http_client.get(_query_url, headers=_headers) + + return self.handle_request_and_response(_request) + + def list_account_phone_numbers(self, + starts_with=None, + ends_with=None, + contains=None, + limit=None, + offset=None): + """Does a GET request to /v2/numbers. + + Returns a list of all phone numbers currently on your Flowroute + account. The response includes details such as the phone number's rate + center, state, number type, and whether CNAM Lookup is enabled for + that number. + + Args: + starts_with (int, optional): Retrieves phone numbers that start + with the specified value. + ends_with (int, optional): Retrieves phone numbers that end with + the specified value. + contains (int, optional): Retrieves phone numbers containing the + specified value. + limit (int, optional): Limits the number of items to retrieve. A + maximum of 200 items can be retrieved. + offset (int, optional): Offsets the list of phone numbers by your + specified value. For example, if you have 4 phone numbers and + you entered 1 as your offset value, then only 3 of your phone + numbers will be displayed in the response. + + Returns: + mixed: Response from the API. A JSON object of phone numbers in + your account + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/numbers' + _query_parameters = { + 'starts_with': starts_with, + 'ends_with': ends_with, + 'contains': contains, + 'limit': limit, + 'offset': offset + } + _query_builder = APIHelper.append_url_with_query_parameters( + _query_builder, + _query_parameters, + Configuration.array_serialization) + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/json' + } + + # Prepare and execute request + _request = self.http_client.get(_query_url, headers=_headers) + + return self.handle_request_and_response(_request) + + def purchase_a_phone_number(self, id): + """Does a POST request to /v2/numbers/{id}. + + Lets you purchase a phone number from available Flowroute inventory. + + Args: + id (int): Phone number to purchase. Must be in 11-digit E.164 + format; e.g. 12061231234. + + Returns: + Number26: Response from the API. CREATED + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/numbers/{id}' + _query_builder = APIHelper.append_url_with_template_parameters( + _query_builder, { + 'id': id + }) + # Return appropriate type + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/json' + } + + # Prepare and execute request + _request = self.http_client.post(_query_url, headers=_headers) + + return self.handle_request_and_response(_request) + + def list_phone_number_details(self, id): + """Does a GET request to /v2/numbers/{id}. + + Lists all of the information associated with any of the phone numbers + in your account, including billing method, primary voice route, and + failover voice route. + + Args: + id (int): Phone number to search for which must be a number that + you own. Must be in 11-digit E.164 format; e.g. 12061231234. + + Returns: + Number26: Response from the API. A JSON object of phone numbers in + your account + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/numbers/{id}' + _query_builder = APIHelper.append_url_with_template_parameters( + _query_builder, { + 'id': id + }) + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/json' + } + + # Prepare and execute request + _request = self.http_client.get(_query_url, headers=_headers) + + return self.handle_request_and_response(_request) + + def release_a_did(self, id): + """Does a DELETE request to /v2/numbers/{id}. + + Lets you release a phone number back to available Flowroute inventory. + + Args: + id (int): Phone number to purchase. Must be in 11-digit E.164 + format; e.g. 12061231234. + + Returns: + Number26: Response from the API. CREATED + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/numbers/{id}' + _query_builder = APIHelper.append_url_with_template_parameters( + _query_builder, { + 'id': id + }) + + # Return appropriate type + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/json' + } + + # Prepare and execute request + _request = self.http_client.delete(_query_url, headers=_headers) + + return self.handle_request_and_response(_request) + + def set_did_alias(self, id, alias): + """Does a PATCH request to /v2/numbers/{id}. + + Lets you set an alias on one of your DIDs. + + Args: + id (int): Phone number to purchase. Must be in 11-digit E.164 + format; e.g. 12061231234. + alias (string): String to use as alias for this DID + + Returns: + Number26: Response from the API. CREATED + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/numbers/{id}' + _query_builder = APIHelper.append_url_with_template_parameters( + _query_builder, { + 'id': id + }) + # Return appropriate type + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/json' + } + + body = { + 'type': 'number', + 'alias': alias + } + + # Prepare and execute request + _request = self.http_client.patch(_query_url, headers=_headers, + parameters=APIHelper.json_serialize( + body)) + + return self.handle_request_and_response(_request) + + def set_did_callback(self, id, url): + """Does a POST request to /v2/numbers/{id}/relationships/dlr_callback. + + Lets you set a dlr callback for a specific DID. + + Args: + id (int): Phone number to purchase. Must be in 11-digit E.164 + format; e.g. 12061231234. + url (string): String / URL to notify + + Returns: + 204 No Content + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/numbers/{id}/relationships/dlr_callback' + _query_builder = APIHelper.append_url_with_template_parameters( + _query_builder, { + 'id': id + }) + # Return appropriate type + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/json' + } + + body = { + 'data': { + 'attributes': { + 'callback_url': url + } + } + } + + # Prepare and execute request + _request = self.http_client.post(_query_url, headers=_headers, + parameters=APIHelper.json_serialize( + body)) + + return self.handle_request_and_response(_request) diff --git a/flowroutenumbersandmessaging/controllers/numbers_controller.pyc b/flowroutenumbersandmessaging/controllers/numbers_controller.pyc new file mode 100644 index 0000000..973ee6d Binary files /dev/null and b/flowroutenumbersandmessaging/controllers/numbers_controller.pyc differ diff --git a/flowroutenumbersandmessaging/controllers/porting_controller.py b/flowroutenumbersandmessaging/controllers/porting_controller.py new file mode 100644 index 0000000..d72d691 --- /dev/null +++ b/flowroutenumbersandmessaging/controllers/porting_controller.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.controllers.porting_controller + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +from .base_controller import BaseController +from ..api_helper import APIHelper +from ..configuration import Configuration + + +class PortingController(BaseController): + + """A Controller to access Endpoints in the + flowroutenumbersandmessaging API.""" + + def checkPortability(self, numbers): + """Does a POST request to /v2/portorders/portability. + + Args: + numbers (list: comma delimited list of strings, required): + Phone numbers to check + + Returns: + mixed: Response from the API. A JSON object of the status of each + number specified + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + body = { + "numbers": numbers + } + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/portorders/portability' + _query_url = APIHelper.clean_url(_query_builder) + # Prepare headers + _headers = { + 'accept': 'application/json' + } + + # Prepare and execute request + _request = self.http_client.post(_query_url, headers=_headers, + parameters=body) + + return self.handle_request_and_response(_request) diff --git a/flowroutenumbersandmessaging/controllers/porting_controller.pyc b/flowroutenumbersandmessaging/controllers/porting_controller.pyc new file mode 100644 index 0000000..abd62d8 Binary files /dev/null and b/flowroutenumbersandmessaging/controllers/porting_controller.pyc differ diff --git a/flowroutenumbersandmessaging/controllers/routes_controller.py b/flowroutenumbersandmessaging/controllers/routes_controller.py new file mode 100644 index 0000000..5b08e2c --- /dev/null +++ b/flowroutenumbersandmessaging/controllers/routes_controller.py @@ -0,0 +1,192 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.controllers.routes_controller + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +from .base_controller import BaseController +from ..api_helper import APIHelper +from ..configuration import Configuration +import json + + +class RoutesController(BaseController): + + """A Controller to access Endpoints in the + flowroutenumbersandmessaging API.""" + + def create_an_inbound_route(self, body): + """Does a POST request to /v2/routes. + + Creates a new inbound route which can then be associated with phone + numbers. Please see "List Inbound Routes" to review the route values + that you can associate with your Flowroute phone numbers. + + Args: + body (NewRoute): The new inbound route to be created. + + Returns: + mixed: Response from the API. CREATED + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/routes' + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare headers + _headers = { + 'accept': 'application/json', + 'content-type': 'application/json; charset=utf-8' + } + + # Prepare and execute request + _request = self.http_client.post(_query_url, + headers=_headers, + parameters=APIHelper.json_serialize(json.loads(body))) + + return self.handle_request_and_response(_request) + + def list_inbound_routes(self, + limit=None, + offset=None): + """Does a GET request to /v2/routes. + + Returns a list of your inbound routes. From the list, you can then + select routes to use as the primary and failover routes for a phone + number, which you can do via "Update Primary Voice Route for a Phone + Number" and "Update Failover Voice Route for a Phone Number". + + Args: + limit (int, optional): Limits the number of routes to retrieve. A + maximum of 200 items can be retrieved. + offset (int, optional): Offsets the list of routes by your + specified value. For example, if you have 4 inbound routes and + you entered 1 as your offset value, then only 3 of your routes + will be displayed in the response. + + Returns: + void: Response from the API. OK + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/routes' + _query_parameters = { + 'limit': limit, + 'offset': offset + } + _query_builder = APIHelper.append_url_with_query_parameters(_query_builder, + _query_parameters, Configuration.array_serialization) + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare and execute request + _request = self.http_client.get(_query_url) + + return self.handle_request_and_response(_request) + + def update_primary_voice_route(self, number_id, body): + """Does a PATCH request to /v2/numbers/{number_id}/relationships/primary_route. + + Use this endpoint to update the primary voice route for a phone + number. You must create the route first by following "Create an + Inbound Route". You can then assign the created route by specifying + its value in a PATCH request. + + Args: + number_id (int): The phone number in E.164 11-digit North American + format to which the primary route for voice will be assigned. + body (void): The primary route to be assigned. + + Returns: + void: Response from the API. NO CONTENT + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/numbers/{number_id}/relationships/primary_route' + _query_builder = APIHelper.append_url_with_template_parameters(_query_builder, { + 'number_id': number_id + }) + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare and execute request + _request = self.http_client.patch(_query_url, + parameters=APIHelper.json_serialize(json.loads(body))) + + return self.handle_request_and_response(_request) + + def update_failover_voice_route(self, + number_id, + body): + """Does a PATCH request to /v2/numbers/{number_id}/relationships/failover_route. + + Use this endpoint to update the failover voice route for a phone + number. You must create the route first by following "Create an + Inbound Route". You can then assign the created route by specifying + its value in a PATCH request. + + Args: + number_id (int): The phone number in E.164 11-digit North American + format to which the failover route for voice will be + assigned. + body (void): The failover route to be assigned. + + Returns: + void: Response from the API. NO CONTENT + + Raises: + APIException: When an error occurs while fetching the data from + the remote API. This exception includes the HTTP Response + code, an error message, and the HTTP body that was received in + the request. + + """ + + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/numbers/{number_id}/relationships/failover_route' + _query_builder = APIHelper.append_url_with_template_parameters( + _query_builder, { + 'number_id': number_id + }) + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare and execute request + _request = self.http_client.patch(_query_url, parameters=APIHelper.json_serialize(json.loads(body))) + + return self.handle_request_and_response(_request) + + def list_edge_strategies(self): + # Prepare query URL + _query_builder = Configuration.base_uri + _query_builder += '/v2/routes/edge_strategies' + _query_url = APIHelper.clean_url(_query_builder) + + # Prepare and execute request + _request = self.http_client.get(_query_url) + + return self.handle_request_and_response(_request) diff --git a/flowroutenumbersandmessaging/controllers/routes_controller.pyc b/flowroutenumbersandmessaging/controllers/routes_controller.pyc new file mode 100644 index 0000000..9ebd320 Binary files /dev/null and b/flowroutenumbersandmessaging/controllers/routes_controller.pyc differ diff --git a/flowroutenumbersandmessaging/decorators.py b/flowroutenumbersandmessaging/decorators.py new file mode 100644 index 0000000..4475c26 --- /dev/null +++ b/flowroutenumbersandmessaging/decorators.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.decorators + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" + +class lazy_property(object): + + """A decorator class for lazy instantiation.""" + + def __init__(self, fget): + self.fget = fget + self.func_name = fget.__name__ + + def __get__(self, obj, cls): + if obj is None: + return None + value = self.fget(obj) + setattr(obj, self.func_name, value) + return value diff --git a/flowroutenumbersandmessaging/decorators.pyc b/flowroutenumbersandmessaging/decorators.pyc new file mode 100644 index 0000000..e3e9591 Binary files /dev/null and b/flowroutenumbersandmessaging/decorators.pyc differ diff --git a/flowroutenumbersandmessaging/exceptions/__init__.py b/flowroutenumbersandmessaging/exceptions/__init__.py new file mode 100644 index 0000000..42782a8 --- /dev/null +++ b/flowroutenumbersandmessaging/exceptions/__init__.py @@ -0,0 +1,4 @@ +__all__ = [ + 'api_exception', + 'error_exception', +] \ No newline at end of file diff --git a/flowroutenumbersandmessaging/exceptions/__init__.pyc b/flowroutenumbersandmessaging/exceptions/__init__.pyc new file mode 100644 index 0000000..aaa67e7 Binary files /dev/null and b/flowroutenumbersandmessaging/exceptions/__init__.pyc differ diff --git a/flowroutenumbersandmessaging/exceptions/api_exception.py b/flowroutenumbersandmessaging/exceptions/api_exception.py new file mode 100644 index 0000000..3aaf90f --- /dev/null +++ b/flowroutenumbersandmessaging/exceptions/api_exception.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.exceptions.api_exception + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" + +class APIException(Exception): + + """Class that handles HTTP Exceptions when fetching API Endpoints. + + Attributes: + response_code (int): The status code of the response. + context (HttpContext): The HttpContext of the API call. + + """ + + def __init__(self, + reason, + context): + """Constructor for the APIException class + + Args: + reason (string): The reason (or error message) for the Exception + to be raised. + context (HttpContext): The HttpContext of the API call. + + """ + super(APIException, self).__init__(reason) + self.context = context + self.response_code = context.response.status_code diff --git a/flowroutenumbersandmessaging/exceptions/api_exception.pyc b/flowroutenumbersandmessaging/exceptions/api_exception.pyc new file mode 100644 index 0000000..ec89518 Binary files /dev/null and b/flowroutenumbersandmessaging/exceptions/api_exception.pyc differ diff --git a/flowroutenumbersandmessaging/exceptions/error_exception.py b/flowroutenumbersandmessaging/exceptions/error_exception.py new file mode 100644 index 0000000..607d1c2 --- /dev/null +++ b/flowroutenumbersandmessaging/exceptions/error_exception.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.error_exception + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" +from ..api_helper import APIHelper +import flowroutenumbersandmessaging.exceptions.api_exception +import flowroutenumbersandmessaging.models.error_1 + +class ErrorException(flowroutenumbersandmessaging.exceptions.api_exception.APIException): + def __init__(self, reason, context): + """Constructor for the ErrorException class + + Args: + reason (string): The reason (or error message) for the Exception + to be raised. + context (HttpContext): The HttpContext of the API call. + + """ + super(ErrorException, self).__init__(reason, context) + dictionary = APIHelper.json_deserialize(self.context.response.raw_body) + if isinstance(dictionary, dict): + self.unbox(dictionary) + + def unbox(self, dictionary): + """Populates the properties of this object by extracting them from a dictionary. + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + """ + self.errors = None + if dictionary.get("errors") != None: + self.errors = list() + for structure in dictionary.get("errors"): + self.errors.append(flowroutenumbersandmessaging.models.error_1.Error1.from_dictionary(structure)) diff --git a/flowroutenumbersandmessaging/exceptions/error_exception.pyc b/flowroutenumbersandmessaging/exceptions/error_exception.pyc new file mode 100644 index 0000000..283d225 Binary files /dev/null and b/flowroutenumbersandmessaging/exceptions/error_exception.pyc differ diff --git a/flowroutenumbersandmessaging/flowroutenumbersandmessaging_client.py b/flowroutenumbersandmessaging/flowroutenumbersandmessaging_client.py new file mode 100644 index 0000000..03b3494 --- /dev/null +++ b/flowroutenumbersandmessaging/flowroutenumbersandmessaging_client.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.flowroute_numbers_and_messaging_client + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" +from .decorators import lazy_property +from .configuration import Configuration +from .controllers.numbers_controller import NumbersController +from .controllers.routes_controller import RoutesController +from .controllers.messages_controller import MessagesController +from .controllers.e911s_controller import E911sController +from .controllers.cnams_controller import CNAMsController +from .controllers.porting_controller import PortingController + + +class FlowroutenumbersandmessagingClient(object): + + config = Configuration + + @lazy_property + def numbers(self): + return NumbersController() + + @lazy_property + def routes(self): + return RoutesController() + + @lazy_property + def messages(self): + return MessagesController() + + @lazy_property + def e911s(self): + return E911sController() + + @lazy_property + def cnams(self): + return CNAMsController() + + @lazy_property + def porting(self): + return PortingController() + + def __init__(self, + basic_auth_user_name = None, + basic_auth_password = None): + if basic_auth_user_name != None: + Configuration.basic_auth_user_name = basic_auth_user_name + if basic_auth_password != None: + Configuration.basic_auth_password = basic_auth_password diff --git a/flowroutenumbersandmessaging/flowroutenumbersandmessaging_client.pyc b/flowroutenumbersandmessaging/flowroutenumbersandmessaging_client.pyc new file mode 100644 index 0000000..c426536 Binary files /dev/null and b/flowroutenumbersandmessaging/flowroutenumbersandmessaging_client.pyc differ diff --git a/flowroutenumbersandmessaging/http/__init__.py b/flowroutenumbersandmessaging/http/__init__.py new file mode 100644 index 0000000..c9f2054 --- /dev/null +++ b/flowroutenumbersandmessaging/http/__init__.py @@ -0,0 +1,10 @@ +__all__ = [ + 'auth', + 'http_method_enum', + 'http_request', + 'http_response', + 'http_client', + 'http_context', + 'requests_client', + 'http_call_back', +] \ No newline at end of file diff --git a/flowroutenumbersandmessaging/http/__init__.pyc b/flowroutenumbersandmessaging/http/__init__.pyc new file mode 100644 index 0000000..f366b20 Binary files /dev/null and b/flowroutenumbersandmessaging/http/__init__.pyc differ diff --git a/flowroutenumbersandmessaging/http/auth/__init__.py b/flowroutenumbersandmessaging/http/auth/__init__.py new file mode 100644 index 0000000..8514e7a --- /dev/null +++ b/flowroutenumbersandmessaging/http/auth/__init__.py @@ -0,0 +1,3 @@ +__all__ = [ + 'basic_auth', +] \ No newline at end of file diff --git a/flowroutenumbersandmessaging/http/auth/__init__.pyc b/flowroutenumbersandmessaging/http/auth/__init__.pyc new file mode 100644 index 0000000..199894e Binary files /dev/null and b/flowroutenumbersandmessaging/http/auth/__init__.pyc differ diff --git a/flowroutenumbersandmessaging/http/auth/basic_auth.py b/flowroutenumbersandmessaging/http/auth/basic_auth.py new file mode 100644 index 0000000..dab71f8 --- /dev/null +++ b/flowroutenumbersandmessaging/http/auth/basic_auth.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.http.auth.basic_auth + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" + +import base64 +from ...configuration import Configuration + +class BasicAuth: + + @staticmethod + def apply(http_request): + """ Add basic authentication to the request. + + Args: + http_request (HttpRequest): The HttpRequest object to which + authentication will be added. + + """ + username = Configuration.basic_auth_user_name + password = Configuration.basic_auth_password + joined = "{}:{}".format(username, password) + encoded = base64.b64encode(str.encode(joined)).decode('iso-8859-1') + header_value = "Basic {}".format(encoded) + http_request.headers["Authorization"] = header_value \ No newline at end of file diff --git a/flowroutenumbersandmessaging/http/auth/basic_auth.pyc b/flowroutenumbersandmessaging/http/auth/basic_auth.pyc new file mode 100644 index 0000000..2732a54 Binary files /dev/null and b/flowroutenumbersandmessaging/http/auth/basic_auth.pyc differ diff --git a/flowroutenumbersandmessaging/http/http_call_back.py b/flowroutenumbersandmessaging/http/http_call_back.py new file mode 100644 index 0000000..b2815d8 --- /dev/null +++ b/flowroutenumbersandmessaging/http/http_call_back.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.http.http_call_back + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +class HttpCallBack(object): + + """An interface for the callback to be called before and after the + HTTP call for an endpoint is made. + + This class should not be instantiated but should be used as a base class + for HttpCallBack classes. + + """ + + def on_before_request(self, + request): + """The controller will call this method before making the HttpRequest. + + Args: + request (HttpRequest): The request object which will be sent + to the HttpClient to be executed. + """ + raise NotImplementedError("This method has not been implemented.") + + def on_after_response(self, + context): + """The controller will call this method after making the HttpRequest. + + Args: + context (HttpContext): The HttpContext of the API call. + """ + raise NotImplementedError("This method has not been implemented.") diff --git a/flowroutenumbersandmessaging/http/http_client.py b/flowroutenumbersandmessaging/http/http_client.py new file mode 100644 index 0000000..cd29e1f --- /dev/null +++ b/flowroutenumbersandmessaging/http/http_client.py @@ -0,0 +1,177 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.http.http_client + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +from .http_request import HttpRequest +from .http_method_enum import HttpMethodEnum + +class HttpClient(object): + + """An interface for the methods that an HTTP Client must implement + + This class should not be instantiated but should be used as a base class + for HTTP Client classes. + + """ + + def execute_as_string(self, request): + """Execute a given HttpRequest to get a string response back + + Args: + request (HttpRequest): The given HttpRequest to execute. + + Returns: + HttpResponse: The response of the HttpRequest. + + """ + raise NotImplementedError("Please Implement this method") + + def execute_as_binary(self, request): + """Execute a given HttpRequest to get a binary response back + + Args: + request (HttpRequest): The given HttpRequest to execute. + + Returns: + HttpResponse: The response of the HttpRequest. + + """ + raise NotImplementedError("Please Implement this method") + + def convert_response(self, response, binary): + """Converts the Response object of the HttpClient into an + HttpResponse object. + + Args: + response (dynamic): The original response object. + + Returns: + HttpResponse: The converted HttpResponse object. + + """ + raise NotImplementedError("Please Implement this method") + + def get(self, query_url, + headers={}, + query_parameters={}): + """Create a simple GET HttpRequest object for the given parameters + + Args: + query_url (string): The URL to send the request to. + headers (dict, optional): The headers for the HTTP Request. + query_parameters (dict, optional): Query parameters to add in the URL. + + Returns: + HttpRequest: The generated HttpRequest for the given paremeters. + + """ + return HttpRequest(HttpMethodEnum.GET, + query_url, + headers, + query_parameters, + None, + None) + + def post(self, query_url, + headers={}, + query_parameters={}, + parameters={}, + files={}): + """Create a simple POST HttpRequest object for the given parameters + + Args: + query_url (string): The URL to send the request to. + headers (dict, optional): The headers for the HTTP Request. + query_parameters (dict, optional): Query parameters to add in the URL. + parameters (dict, optional): Form or body parameters to be included in the body. + files (dict, optional): Files to be sent with the request. + + Returns: + HttpRequest: The generated HttpRequest for the given paremeters. + + """ + return HttpRequest(HttpMethodEnum.POST, + query_url, + headers, + query_parameters, + parameters, + files) + + def put(self, query_url, + headers={}, + query_parameters={}, + parameters={}, + files={}): + """Create a simple PUT HttpRequest object for the given parameters + + Args: + query_url (string): The URL to send the request to. + headers (dict, optional): The headers for the HTTP Request. + query_parameters (dict, optional): Query parameters to add in the URL. + parameters (dict, optional): Form or body parameters to be included in the body. + files (dict, optional): Files to be sent with the request. + + Returns: + HttpRequest: The generated HttpRequest for the given paremeters. + + """ + return HttpRequest(HttpMethodEnum.PUT, + query_url, + headers, + query_parameters, + parameters, + files) + + def patch(self, query_url, + headers={}, + query_parameters={}, + parameters={}, + files={}): + """Create a simple PATCH HttpRequest object for the given parameters + + Args: + query_url (string): The URL to send the request to. + headers (dict, optional): The headers for the HTTP Request. + query_parameters (dict, optional): Query parameters to add in the URL. + parameters (dict, optional): Form or body parameters to be included in the body. + files (dict, optional): Files to be sent with the request. + + Returns: + HttpRequest: The generated HttpRequest for the given paremeters. + + """ + return HttpRequest(HttpMethodEnum.PATCH, + query_url, + headers, + query_parameters, + parameters, + files) + + def delete(self, query_url, + headers={}, + query_parameters={}, + parameters={}, + files={}): + """Create a simple DELETE HttpRequest object for the given parameters + + Args: + query_url (string): The URL to send the request to. + headers (dict, optional): The headers for the HTTP Request. + query_parameters (dict, optional): Query parameters to add in the URL. + parameters (dict, optional): Form or body parameters to be included in the body. + files (dict, optional): Files to be sent with the request. + + Returns: + HttpRequest: The generated HttpRequest for the given paremeters. + + """ + return HttpRequest(HttpMethodEnum.DELETE, + query_url, + headers, + query_parameters, + parameters, + files) diff --git a/flowroutenumbersandmessaging/http/http_client.pyc b/flowroutenumbersandmessaging/http/http_client.pyc new file mode 100644 index 0000000..65f2893 Binary files /dev/null and b/flowroutenumbersandmessaging/http/http_client.pyc differ diff --git a/flowroutenumbersandmessaging/http/http_context.py b/flowroutenumbersandmessaging/http/http_context.py new file mode 100644 index 0000000..bcfa825 --- /dev/null +++ b/flowroutenumbersandmessaging/http/http_context.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.http.http_context + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +class HttpContext(object): + + """An HTTP Context that contains both the original HttpRequest + object that intitiated the call and the HttpResponse object that + is the result of the call. + + Attributes: + request (HttpRequest): The original request object. + response (HttpResponse): The returned response object after + executing the request. Note that this may be None + depending on if and when an error occurred. + + """ + + def __init__(self, + request, + response): + """Constructor for the HttpContext class + + Args: + request (HttpRequest): The HTTP Request. + response (HttpResponse): The HTTP Response. + + """ + self.request = request + self.response = response diff --git a/flowroutenumbersandmessaging/http/http_context.pyc b/flowroutenumbersandmessaging/http/http_context.pyc new file mode 100644 index 0000000..8c0b724 Binary files /dev/null and b/flowroutenumbersandmessaging/http/http_context.pyc differ diff --git a/flowroutenumbersandmessaging/http/http_method_enum.py b/flowroutenumbersandmessaging/http/http_method_enum.py new file mode 100644 index 0000000..9b604e1 --- /dev/null +++ b/flowroutenumbersandmessaging/http/http_method_enum.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.http.http_method_enum + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +class HttpMethodEnum(object): + + """Enumeration of an HTTP Method + + Attributes: + GET: A GET Request + POST: A POST Request + PUT: A PUT Request + PATCH: A PATCH Request + DELETE: A DELETE Request + + """ + + GET = "GET" + + POST = "POST" + + PUT = "PUT" + + PATCH = "PATCH" + + DELETE = "DELETE" + + + @classmethod + def to_string(cls, val): + """Returns the string equivalent for the Enum. + + """ + for k, v in list(vars(cls).items()): + if v == val: + return k + + @classmethod + def from_string(cls, str): + """Creates an instance of the Enum from a given string. + + """ + return getattr(cls, str.upper(), None) diff --git a/flowroutenumbersandmessaging/http/http_method_enum.pyc b/flowroutenumbersandmessaging/http/http_method_enum.pyc new file mode 100644 index 0000000..fb2fe42 Binary files /dev/null and b/flowroutenumbersandmessaging/http/http_method_enum.pyc differ diff --git a/flowroutenumbersandmessaging/http/http_request.py b/flowroutenumbersandmessaging/http/http_request.py new file mode 100644 index 0000000..d8835f8 --- /dev/null +++ b/flowroutenumbersandmessaging/http/http_request.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.http.http_request + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" +from ..api_helper import APIHelper + +class HttpRequest(object): + + """Information about an HTTP Request including its method, headers, + parameters, URL, and Basic Auth details + + Attributes: + http_method (HttpMethodEnum): The HTTP Method that this request should + perform when called. + headers (dict): A dictionary of headers (key : value) that should be + sent along with the request. + query_url (string): The URL that the request should be sent to. + parameters (dict): A dictionary of parameters that are to be sent along + with the request in the form body of the request + + """ + + def __init__(self, + http_method, + query_url, + headers=None, + query_parameters=None, + parameters=None, + files=None): + """Constructor for the HttpRequest class + + Args: + http_method (HttpMethodEnum): The HTTP Method. + query_url (string): The URL to send the request to. + headers (dict, optional): The headers for the HTTP Request. + query_parameters (dict, optional): Query parameters to add in the URL. + parameters (dict, optional): Form or body parameters to be included in the body. + files (dict, optional): Files to be sent with the request. + + """ + self.http_method = http_method + self.query_url = query_url + self.headers = headers + self.query_parameters = query_parameters + self.parameters = parameters + self.files = files + + def add_header(self, name, value): + """ Add a header to the HttpRequest. + + Args: + name (string): The name of the header. + value (string): The value of the header. + + """ + self.headers[name] = value + + def add_parameter(self, name, value): + """ Add a parameter to the HttpRequest. + + Args: + name (string): The name of the parameter. + value (string): The value of the parameter. + + """ + self.parameters[name] = value + + def add_query_parameter(self, name, value): + """ Add a query parameter to the HttpRequest. + + Args: + name (string): The name of the query parameter. + value (string): The value of the query parameter. + + """ + self.query_url = APIHelper.append_url_with_query_parameters(self.query_url, + {name:value}) + self.query_url = APIHelper.clean_url(self.query_url) diff --git a/flowroutenumbersandmessaging/http/http_request.pyc b/flowroutenumbersandmessaging/http/http_request.pyc new file mode 100644 index 0000000..485e0c6 Binary files /dev/null and b/flowroutenumbersandmessaging/http/http_request.pyc differ diff --git a/flowroutenumbersandmessaging/http/http_response.py b/flowroutenumbersandmessaging/http/http_response.py new file mode 100644 index 0000000..f92112a --- /dev/null +++ b/flowroutenumbersandmessaging/http/http_response.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.http.http_response + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +class HttpResponse(object): + + """Information about an HTTP Response including its status code, returned + headers, and raw body + + Attributes: + status_code (int): The status code response from the server that + corresponds to this response. + headers (dict): A dictionary of headers (key : value) that were + returned with the response + raw_body (string): The Raw body of the HTTP Response as a string + + """ + + def __init__(self, + status_code, + headers, + raw_body): + """Constructor for the HttpResponse class + + Args: + status_code (int): The response status code. + headers (dict): The response headers. + raw_body (string): The raw body from the server. + + """ + self.status_code = status_code + self.headers = headers + self.raw_body = raw_body diff --git a/flowroutenumbersandmessaging/http/http_response.pyc b/flowroutenumbersandmessaging/http/http_response.pyc new file mode 100644 index 0000000..87b45d8 Binary files /dev/null and b/flowroutenumbersandmessaging/http/http_response.pyc differ diff --git a/flowroutenumbersandmessaging/http/requests_client.py b/flowroutenumbersandmessaging/http/requests_client.py new file mode 100644 index 0000000..168d5d1 --- /dev/null +++ b/flowroutenumbersandmessaging/http/requests_client.py @@ -0,0 +1,100 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.http.requests_client + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +import requests + +from cachecontrol import CacheControl +from requests.adapters import HTTPAdapter +from requests.packages.urllib3.util.retry import Retry + +from .http_client import HttpClient +from .http_response import HttpResponse +from .http_method_enum import HttpMethodEnum + +class RequestsClient(HttpClient): + + """An implementation of HttpClient that uses Requests as its HTTP Client + + Attributes: + timeout (int): The default timeout for all API requests. + + """ + + def __init__(self, timeout=60, cache=False, max_retries=None, retry_interval=None): + """The constructor. + + Args: + timeout (float): The default global timeout(seconds). + + """ + self.timeout = timeout + self.session = requests.session() + + if max_retries and retry_interval: + retries = Retry(total=max_retries, backoff_factor=retry_interval) + self.session.mount('http://', HTTPAdapter(max_retries=retries)) + self.session.mount('https://', HTTPAdapter(max_retries=retries)) + + if cache: + self.session = CacheControl(self.session) + + def execute_as_string(self, request): + """Execute a given HttpRequest to get a string response back + + Args: + request (HttpRequest): The given HttpRequest to execute. + + Returns: + HttpResponse: The response of the HttpRequest. + + """ + response = self.session.request(HttpMethodEnum.to_string(request.http_method), + request.query_url, + headers=request.headers, + params=request.query_parameters, + data=request.parameters, + files=request.files, + timeout=self.timeout) + + return self.convert_response(response, False) + + def execute_as_binary(self, request): + """Execute a given HttpRequest to get a binary response back + + Args: + request (HttpRequest): The given HttpRequest to execute. + + Returns: + HttpResponse: The response of the HttpRequest. + + """ + response = self.session.request(HttpMethodEnum.to_string(request.http_method), + request.query_url, + headers=request.headers, + params=request.query_parameters, + data=request.parameters, + files=request.files, + timeout=self.timeout) + + return self.convert_response(response, True) + + def convert_response(self, response, binary): + """Converts the Response object of the HttpClient into an + HttpResponse object. + + Args: + response (dynamic): The original response object. + + Returns: + HttpResponse: The converted HttpResponse object. + + """ + if binary: + return HttpResponse(response.status_code, response.headers, response.content) + else: + return HttpResponse(response.status_code, response.headers, response.text) diff --git a/flowroutenumbersandmessaging/http/requests_client.pyc b/flowroutenumbersandmessaging/http/requests_client.pyc new file mode 100644 index 0000000..3c54431 Binary files /dev/null and b/flowroutenumbersandmessaging/http/requests_client.pyc differ diff --git a/flowroutenumbersandmessaging/models/__init__.py b/flowroutenumbersandmessaging/models/__init__.py new file mode 100644 index 0000000..acc3b3a --- /dev/null +++ b/flowroutenumbersandmessaging/models/__init__.py @@ -0,0 +1,20 @@ +__all__ = [ + 'error_84', + 'new_route', + 'links', + 'attributes', + 'attributes_28', + 'data_27', + 'delivery_receipt', + 'message', + 'error_1', + 'account_routes', + 'attributes_62', + 'data_61', + 'number_26', + 'mdr_2', + 'data', + 'route_type_enum', + 'number_type_enum', + 'message_type_enum', +] \ No newline at end of file diff --git a/flowroutenumbersandmessaging/models/__init__.pyc b/flowroutenumbersandmessaging/models/__init__.pyc new file mode 100644 index 0000000..9ef9c71 Binary files /dev/null and b/flowroutenumbersandmessaging/models/__init__.pyc differ diff --git a/flowroutenumbersandmessaging/models/account_routes.py b/flowroutenumbersandmessaging/models/account_routes.py new file mode 100644 index 0000000..589afab --- /dev/null +++ b/flowroutenumbersandmessaging/models/account_routes.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.account_routes + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" + + +class AccountRoutes(object): + + """Implementation of the 'AccountRoutes' model. + + TODO: type model description here. + + Attributes: + data (list of object): TODO: type description here. + links (object): TODO: type description here. + + """ + + # Create a mapping from Model property names to API property names + _names = { + "data" : "data", + "links" : "links" + } + + def __init__(self, + data=None, + links=None): + """Constructor for the AccountRoutes class""" + + # Initialize members of the class + self.data = data + self.links = links + + + @classmethod + def from_dictionary(cls, + dictionary): + """Creates an instance of this model from a dictionary + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + Returns: + object: An instance of this structure class. + + """ + if dictionary is None: + return None + + # Extract variables from the dictionary + data = dictionary.get("data") + links = dictionary.get("links") + + # Return an object of this model + return cls(data, + links) + + diff --git a/flowroutenumbersandmessaging/models/attributes.py b/flowroutenumbersandmessaging/models/attributes.py new file mode 100644 index 0000000..5e405b9 --- /dev/null +++ b/flowroutenumbersandmessaging/models/attributes.py @@ -0,0 +1,129 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.attributes + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" +from flowroutenumbersandmessaging.api_helper import APIHelper +import flowroutenumbersandmessaging.models.delivery_receipt + +class Attributes(object): + + """Implementation of the 'Attributes' model. + + TODO: type model description here. + + Attributes: + amount_display (float): TODO: type description here. + amount_nanodollars (float): TODO: type description here. + body (string): TODO: type description here. + delivery_receipts (list of DeliveryReceipt): TODO: type description + here. + direction (string): TODO: type description here. + mfrom (string): TODO: type description here. + is_mms (bool): TODO: type description here. + message_encoding (int): TODO: type description here. + message_type (MessageTypeEnum): TODO: type description here. + status (string): TODO: type description here. + timestamp (datetime): TODO: type description here. + to (string): TODO: type description here. + + """ + + # Create a mapping from Model property names to API property names + _names = { + "amount_display" : "amount_display", + "amount_nanodollars" : "amount_nanodollars", + "body" : "body", + "delivery_receipts" : "delivery_receipts", + "direction" : "direction", + "mfrom" : "from", + "is_mms" : "is_mms", + "message_encoding" : "message_encoding", + "message_type" : "message_type", + "status" : "status", + "timestamp" : "timestamp", + "to" : "to" + } + + def __init__(self, + amount_display=None, + amount_nanodollars=None, + body=None, + delivery_receipts=None, + direction=None, + mfrom=None, + is_mms=None, + message_encoding=None, + message_type=None, + status=None, + timestamp=None, + to=None): + """Constructor for the Attributes class""" + + # Initialize members of the class + self.amount_display = amount_display + self.amount_nanodollars = amount_nanodollars + self.body = body + self.delivery_receipts = delivery_receipts + self.direction = direction + self.mfrom = mfrom + self.is_mms = is_mms + self.message_encoding = message_encoding + self.message_type = message_type + self.status = status + self.timestamp = APIHelper.RFC3339DateTime(timestamp) if timestamp else None + self.to = to + + + @classmethod + def from_dictionary(cls, + dictionary): + """Creates an instance of this model from a dictionary + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + Returns: + object: An instance of this structure class. + + """ + if dictionary is None: + return None + + # Extract variables from the dictionary + amount_display = dictionary.get("amount_display") + amount_nanodollars = dictionary.get("amount_nanodollars") + body = dictionary.get("body") + delivery_receipts = None + if dictionary.get("delivery_receipts") != None: + delivery_receipts = list() + for structure in dictionary.get("delivery_receipts"): + delivery_receipts.append(flowroutenumbersandmessaging.models.delivery_receipt.DeliveryReceipt.from_dictionary(structure)) + direction = dictionary.get("direction") + mfrom = dictionary.get("from") + is_mms = dictionary.get("is_mms") + message_encoding = dictionary.get("message_encoding") + message_type = dictionary.get("message_type") + status = dictionary.get("status") + timestamp = APIHelper.RFC3339DateTime.from_value(dictionary.get("timestamp")).datetime if dictionary.get("timestamp") else None + to = dictionary.get("to") + + # Return an object of this model + return cls(amount_display, + amount_nanodollars, + body, + delivery_receipts, + direction, + mfrom, + is_mms, + message_encoding, + message_type, + status, + timestamp, + to) + + diff --git a/flowroutenumbersandmessaging/models/attributes.pyc b/flowroutenumbersandmessaging/models/attributes.pyc new file mode 100644 index 0000000..ee663df Binary files /dev/null and b/flowroutenumbersandmessaging/models/attributes.pyc differ diff --git a/flowroutenumbersandmessaging/models/attributes_28.py b/flowroutenumbersandmessaging/models/attributes_28.py new file mode 100644 index 0000000..e777bc4 --- /dev/null +++ b/flowroutenumbersandmessaging/models/attributes_28.py @@ -0,0 +1,87 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.attributes_28 + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" + + +class Attributes28(object): + + """Implementation of the 'Attributes28' model. + + TODO: type model description here. + + Attributes: + alias (string): TODO: type description here. + cnam_lookups_enabled (bool): TODO: type description here. + number_type (NumberTypeEnum): TODO: type description here. + rate_center (string): TODO: type description here. + state (string): TODO: type description here. + value (int): TODO: type description here. + + """ + + # Create a mapping from Model property names to API property names + _names = { + "alias" : "alias", + "cnam_lookups_enabled" : "cnam_lookups_enabled", + "number_type" : "number_type", + "rate_center" : "rate_center", + "state" : "state", + "value" : "value" + } + + def __init__(self, + alias=None, + cnam_lookups_enabled=None, + number_type=None, + rate_center=None, + state=None, + value=None): + """Constructor for the Attributes28 class""" + + # Initialize members of the class + self.alias = alias + self.cnam_lookups_enabled = cnam_lookups_enabled + self.number_type = number_type + self.rate_center = rate_center + self.state = state + self.value = value + + + @classmethod + def from_dictionary(cls, + dictionary): + """Creates an instance of this model from a dictionary + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + Returns: + object: An instance of this structure class. + + """ + if dictionary is None: + return None + + # Extract variables from the dictionary + alias = dictionary.get("alias") + cnam_lookups_enabled = dictionary.get("cnam_lookups_enabled") + number_type = dictionary.get("number_type") + rate_center = dictionary.get("rate_center") + state = dictionary.get("state") + value = dictionary.get("value") + + # Return an object of this model + return cls(alias, + cnam_lookups_enabled, + number_type, + rate_center, + state, + value) + + diff --git a/flowroutenumbersandmessaging/models/attributes_28.pyc b/flowroutenumbersandmessaging/models/attributes_28.pyc new file mode 100644 index 0000000..3524e32 Binary files /dev/null and b/flowroutenumbersandmessaging/models/attributes_28.pyc differ diff --git a/flowroutenumbersandmessaging/models/attributes_62.py b/flowroutenumbersandmessaging/models/attributes_62.py new file mode 100644 index 0000000..51e647b --- /dev/null +++ b/flowroutenumbersandmessaging/models/attributes_62.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.attributes_62 + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" + + +class Attributes62(object): + + """Implementation of the 'Attributes62' model. + + TODO: type model description here. + + Attributes: + alias (string): TODO: type description here. + route_type (RouteTypeEnum): TODO: type description here. + value (string): TODO: type description here. + + """ + + # Create a mapping from Model property names to API property names + _names = { + "alias" : "alias", + "route_type" : "route_type", + "value" : "value" + } + + def __init__(self, + alias=None, + route_type='sip-reg', + value=None): + """Constructor for the Attributes62 class""" + + # Initialize members of the class + self.alias = alias + self.route_type = route_type + self.value = value + + + @classmethod + def from_dictionary(cls, + dictionary): + """Creates an instance of this model from a dictionary + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + Returns: + object: An instance of this structure class. + + """ + if dictionary is None: + return None + + # Extract variables from the dictionary + alias = dictionary.get("alias") + route_type = dictionary.get("route_type") if dictionary.get("route_type") else 'sip-reg' + value = dictionary.get("value") + + # Return an object of this model + return cls(alias, + route_type, + value) + + diff --git a/flowroutenumbersandmessaging/models/data.py b/flowroutenumbersandmessaging/models/data.py new file mode 100644 index 0000000..85c55d9 --- /dev/null +++ b/flowroutenumbersandmessaging/models/data.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.data + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" +import flowroutenumbersandmessaging.models.attributes + +class Data(object): + + """Implementation of the 'Data' model. + + TODO: type model description here. + + Attributes: + attributes (Attributes): TODO: type description here. + id (string): TODO: type description here. + mtype (string): TODO: type description here. + + """ + + # Create a mapping from Model property names to API property names + _names = { + "attributes" : "attributes", + "id" : "id", + "mtype" : "type" + } + + def __init__(self, + attributes=None, + id=None, + mtype='message'): + """Constructor for the Data class""" + + # Initialize members of the class + self.attributes = attributes + self.id = id + self.mtype = mtype + + + @classmethod + def from_dictionary(cls, + dictionary): + """Creates an instance of this model from a dictionary + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + Returns: + object: An instance of this structure class. + + """ + if dictionary is None: + return None + + # Extract variables from the dictionary + attributes = flowroutenumbersandmessaging.models.attributes.Attributes.from_dictionary(dictionary.get("attributes")) if dictionary.get("attributes") else None + id = dictionary.get("id") + mtype = dictionary.get("type") if dictionary.get("type") else 'message' + + # Return an object of this model + return cls(attributes, + id, + mtype) + + diff --git a/flowroutenumbersandmessaging/models/data.pyc b/flowroutenumbersandmessaging/models/data.pyc new file mode 100644 index 0000000..72d415c Binary files /dev/null and b/flowroutenumbersandmessaging/models/data.pyc differ diff --git a/flowroutenumbersandmessaging/models/data_27.py b/flowroutenumbersandmessaging/models/data_27.py new file mode 100644 index 0000000..8b81229 --- /dev/null +++ b/flowroutenumbersandmessaging/models/data_27.py @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.data_27 + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" +import flowroutenumbersandmessaging.models.attributes_28 +import flowroutenumbersandmessaging.models.links + +class Data27(object): + + """Implementation of the 'Data27' model. + + TODO: type model description here. + + Attributes: + attributes (Attributes28): TODO: type description here. + id (string): TODO: type description here. + links (Links): TODO: type description here. + relationships (object): TODO: type description here. + mtype (string): TODO: type description here. + + """ + + # Create a mapping from Model property names to API property names + _names = { + "attributes" : "attributes", + "id" : "id", + "links" : "links", + "relationships" : "relationships", + "mtype" : "type" + } + + def __init__(self, + attributes=None, + id=None, + links=None, + relationships=None, + mtype='number'): + """Constructor for the Data27 class""" + + # Initialize members of the class + self.attributes = attributes + self.id = id + self.links = links + self.relationships = relationships + self.mtype = mtype + + + @classmethod + def from_dictionary(cls, + dictionary): + """Creates an instance of this model from a dictionary + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + Returns: + object: An instance of this structure class. + + """ + if dictionary is None: + return None + + # Extract variables from the dictionary + attributes = flowroutenumbersandmessaging.models.attributes_28.Attributes28.from_dictionary(dictionary.get("attributes")) if dictionary.get("attributes") else None + id = dictionary.get("id") + links = flowroutenumbersandmessaging.models.links.Links.from_dictionary(dictionary.get("links")) if dictionary.get("links") else None + relationships = dictionary.get("relationships") + mtype = dictionary.get("type") if dictionary.get("type") else 'number' + + # Return an object of this model + return cls(attributes, + id, + links, + relationships, + mtype) + + diff --git a/flowroutenumbersandmessaging/models/data_27.pyc b/flowroutenumbersandmessaging/models/data_27.pyc new file mode 100644 index 0000000..3b49135 Binary files /dev/null and b/flowroutenumbersandmessaging/models/data_27.pyc differ diff --git a/flowroutenumbersandmessaging/models/data_61.py b/flowroutenumbersandmessaging/models/data_61.py new file mode 100644 index 0000000..e85c283 --- /dev/null +++ b/flowroutenumbersandmessaging/models/data_61.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.data_61 + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" +import flowroutenumbersandmessaging.models.attributes_62 + +class Data61(object): + + """Implementation of the 'Data61' model. + + TODO: type model description here. + + Attributes: + mtype (string): TODO: type description here. + attributes (Attributes62): TODO: type description here. + + """ + + # Create a mapping from Model property names to API property names + _names = { + "mtype" : "type", + "attributes" : "attributes" + } + + def __init__(self, + mtype='route', + attributes=None): + """Constructor for the Data61 class""" + + # Initialize members of the class + self.mtype = mtype + self.attributes = attributes + + + @classmethod + def from_dictionary(cls, + dictionary): + """Creates an instance of this model from a dictionary + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + Returns: + object: An instance of this structure class. + + """ + if dictionary is None: + return None + + # Extract variables from the dictionary + mtype = dictionary.get("type") if dictionary.get("type") else 'route' + attributes = flowroutenumbersandmessaging.models.attributes_62.Attributes62.from_dictionary(dictionary.get("attributes")) if dictionary.get("attributes") else None + + # Return an object of this model + return cls(mtype, + attributes) + + diff --git a/flowroutenumbersandmessaging/models/delivery_receipt.py b/flowroutenumbersandmessaging/models/delivery_receipt.py new file mode 100644 index 0000000..e53c26d --- /dev/null +++ b/flowroutenumbersandmessaging/models/delivery_receipt.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.delivery_receipt + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" +from flowroutenumbersandmessaging.api_helper import APIHelper + +class DeliveryReceipt(object): + + """Implementation of the 'DeliveryReceipt' model. + + TODO: type model description here. + + Attributes: + level (int): TODO: type description here. + status (string): TODO: type description here. + status_code (int): TODO: type description here. + status_code_description (string): TODO: type description here. + timestamp (datetime): TODO: type description here. + + """ + + # Create a mapping from Model property names to API property names + _names = { + "level" : "level", + "status" : "status", + "status_code" : "status_code", + "status_code_description" : "status_code_description", + "timestamp" : "timestamp" + } + + def __init__(self, + level=None, + status=None, + status_code=None, + status_code_description=None, + timestamp=None): + """Constructor for the DeliveryReceipt class""" + + # Initialize members of the class + self.level = level + self.status = status + self.status_code = status_code + self.status_code_description = status_code_description + self.timestamp = APIHelper.RFC3339DateTime(timestamp) if timestamp else None + + + @classmethod + def from_dictionary(cls, + dictionary): + """Creates an instance of this model from a dictionary + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + Returns: + object: An instance of this structure class. + + """ + if dictionary is None: + return None + + # Extract variables from the dictionary + level = dictionary.get("level") + status = dictionary.get("status") + status_code = dictionary.get("status_code") + status_code_description = dictionary.get("status_code_description") + timestamp = APIHelper.RFC3339DateTime.from_value(dictionary.get("timestamp")).datetime if dictionary.get("timestamp") else None + + # Return an object of this model + return cls(level, + status, + status_code, + status_code_description, + timestamp) + + diff --git a/flowroutenumbersandmessaging/models/delivery_receipt.pyc b/flowroutenumbersandmessaging/models/delivery_receipt.pyc new file mode 100644 index 0000000..67f6ce2 Binary files /dev/null and b/flowroutenumbersandmessaging/models/delivery_receipt.pyc differ diff --git a/flowroutenumbersandmessaging/models/error_1.py b/flowroutenumbersandmessaging/models/error_1.py new file mode 100644 index 0000000..96a3a5e --- /dev/null +++ b/flowroutenumbersandmessaging/models/error_1.py @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.error_1 + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" + + +class Error1(object): + + """Implementation of the 'Error1' model. + + TODO: type model description here. + + Attributes: + id (string): TODO: type description here. + status (int): TODO: type description here. + detail (string): TODO: type description here. + title (string): TODO: type description here. + + """ + + # Create a mapping from Model property names to API property names + _names = { + "id" : "id", + "status" : "status", + "detail" : "detail", + "title" : "title" + } + + def __init__(self, + id=None, + status=None, + detail=None, + title=None): + """Constructor for the Error1 class""" + + # Initialize members of the class + self.id = id + self.status = status + self.detail = detail + self.title = title + + + @classmethod + def from_dictionary(cls, + dictionary): + """Creates an instance of this model from a dictionary + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + Returns: + object: An instance of this structure class. + + """ + if dictionary is None: + return None + + # Extract variables from the dictionary + id = dictionary.get("id") + status = dictionary.get("status") + detail = dictionary.get("detail") + title = dictionary.get("title") + + # Return an object of this model + return cls(id, + status, + detail, + title) + + diff --git a/flowroutenumbersandmessaging/models/error_1.pyc b/flowroutenumbersandmessaging/models/error_1.pyc new file mode 100644 index 0000000..0c2c195 Binary files /dev/null and b/flowroutenumbersandmessaging/models/error_1.pyc differ diff --git a/flowroutenumbersandmessaging/models/error_84.py b/flowroutenumbersandmessaging/models/error_84.py new file mode 100644 index 0000000..6eecae6 --- /dev/null +++ b/flowroutenumbersandmessaging/models/error_84.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.error_84 + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" +import flowroutenumbersandmessaging.models.error_1 + +class Error84(object): + + """Implementation of the 'Error84' model. + + TODO: type model description here. + + Attributes: + errors (list of Error1): TODO: type description here. + + """ + + # Create a mapping from Model property names to API property names + _names = { + "errors" : "errors" + } + + def __init__(self, + errors=None): + """Constructor for the Error84 class""" + + # Initialize members of the class + self.errors = errors + + + @classmethod + def from_dictionary(cls, + dictionary): + """Creates an instance of this model from a dictionary + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + Returns: + object: An instance of this structure class. + + """ + if dictionary is None: + return None + + # Extract variables from the dictionary + errors = None + if dictionary.get("errors") != None: + errors = list() + for structure in dictionary.get("errors"): + errors.append(flowroutenumbersandmessaging.models.error_1.Error1.from_dictionary(structure)) + + # Return an object of this model + return cls(errors) + + diff --git a/flowroutenumbersandmessaging/models/links.py b/flowroutenumbersandmessaging/models/links.py new file mode 100644 index 0000000..4d48afa --- /dev/null +++ b/flowroutenumbersandmessaging/models/links.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.links + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" + + +class Links(object): + + """Implementation of the 'Links' model. + + TODO: type model description here. + + Attributes: + self (string): TODO: type description here. + + """ + + # Create a mapping from Model property names to API property names + _names = { + "self" : "self" + } + + def __init__(self): + """Constructor for the Links class""" + + # Initialize members of the class + self.self = self + + + @classmethod + def from_dictionary(cls, + dictionary): + """Creates an instance of this model from a dictionary + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + Returns: + object: An instance of this structure class. + + """ + if dictionary is None: + return None + + # Extract variables from the dictionary + self = dictionary.get("self") + + # Return an object of this model + return cls(self) + + diff --git a/flowroutenumbersandmessaging/models/links.pyc b/flowroutenumbersandmessaging/models/links.pyc new file mode 100644 index 0000000..28c5d7c Binary files /dev/null and b/flowroutenumbersandmessaging/models/links.pyc differ diff --git a/flowroutenumbersandmessaging/models/mdr_2.py b/flowroutenumbersandmessaging/models/mdr_2.py new file mode 100644 index 0000000..9064144 --- /dev/null +++ b/flowroutenumbersandmessaging/models/mdr_2.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.mdr_2 + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" +import flowroutenumbersandmessaging.models.data + +class MDR2(object): + + """Implementation of the 'MDR2' model. + + TODO: type model description here. + + Attributes: + data (Data): TODO: type description here. + + """ + + # Create a mapping from Model property names to API property names + _names = { + "data" : "data" + } + + def __init__(self, + data=None): + """Constructor for the MDR2 class""" + + # Initialize members of the class + self.data = data + + + @classmethod + def from_dictionary(cls, + dictionary): + """Creates an instance of this model from a dictionary + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + Returns: + object: An instance of this structure class. + + """ + if dictionary is None: + return None + + # Extract variables from the dictionary + data = flowroutenumbersandmessaging.models.data.Data.from_dictionary(dictionary.get("data")) if dictionary.get("data") else None + + # Return an object of this model + return cls(data) + + diff --git a/flowroutenumbersandmessaging/models/mdr_2.pyc b/flowroutenumbersandmessaging/models/mdr_2.pyc new file mode 100644 index 0000000..eb3e2ed Binary files /dev/null and b/flowroutenumbersandmessaging/models/mdr_2.pyc differ diff --git a/flowroutenumbersandmessaging/models/message.py b/flowroutenumbersandmessaging/models/message.py new file mode 100644 index 0000000..380f555 --- /dev/null +++ b/flowroutenumbersandmessaging/models/message.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.message + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" + + +class Message(object): + + """Implementation of the 'Message' model. + + TODO: type model description here. + + Attributes: + mfrom (string): TODO: type description here. + to (string): TODO: type description here. + body (string): TODO: type description here. + media_urls (list of string): TODO: type description here. + is_mms (bool): TODO: type description here. + + """ + + # Create a mapping from Model property names to API property names + _names = { + "mfrom" : "from", + "to" : "to", + "body" : "body", + "media_urls" : "media_urls", + "is_mms" : "is_mms" + } + + def __init__(self, + mfrom=None, + to=None, + body=None, + media_urls=None, + is_mms=None): + """Constructor for the Message class""" + + # Initialize members of the class + self.mfrom = mfrom + self.to = to + self.body = body + self.media_urls = media_urls + self.is_mms = is_mms + + + @classmethod + def from_dictionary(cls, + dictionary): + """Creates an instance of this model from a dictionary + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + Returns: + object: An instance of this structure class. + + """ + if dictionary is None: + return None + + # Extract variables from the dictionary + mfrom = dictionary.get("from") + to = dictionary.get("to") + body = dictionary.get("body") + media_urls = dictionary.get("media_urls") + is_mms = dictionary.get("is_mms") + + # Return an object of this model + return cls(mfrom, + to, + body, + media_urls, + is_mms) + + diff --git a/flowroutenumbersandmessaging/models/message_type_enum.py b/flowroutenumbersandmessaging/models/message_type_enum.py new file mode 100644 index 0000000..03b386c --- /dev/null +++ b/flowroutenumbersandmessaging/models/message_type_enum.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.message_type_enum + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" + +class MessageTypeEnum(object): + + """Implementation of the 'MessageType' enum. + + TODO: type enum description here. + + Attributes: + LONGCODE: TODO: type description here. + TOLLFREE: TODO: type description here. + + """ + + LONGCODE = 'longcode' + + TOLLFREE = 'toll-free' + diff --git a/flowroutenumbersandmessaging/models/new_route.py b/flowroutenumbersandmessaging/models/new_route.py new file mode 100644 index 0000000..495cbb0 --- /dev/null +++ b/flowroutenumbersandmessaging/models/new_route.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.new_route + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" +import flowroutenumbersandmessaging.models.data_61 + +class NewRoute(object): + + """Implementation of the 'NewRoute' model. + + TODO: type model description here. + + Attributes: + data (Data61): TODO: type description here. + + """ + + # Create a mapping from Model property names to API property names + _names = { + "data" : "data" + } + + def __init__(self, + data=None): + """Constructor for the NewRoute class""" + + # Initialize members of the class + self.data = data + + + @classmethod + def from_dictionary(cls, + dictionary): + """Creates an instance of this model from a dictionary + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + Returns: + object: An instance of this structure class. + + """ + if dictionary is None: + return None + + # Extract variables from the dictionary + data = flowroutenumbersandmessaging.models.data_61.Data61.from_dictionary(dictionary.get("data")) if dictionary.get("data") else None + + # Return an object of this model + return cls(data) + + diff --git a/flowroutenumbersandmessaging/models/number_26.py b/flowroutenumbersandmessaging/models/number_26.py new file mode 100644 index 0000000..fe5ddf4 --- /dev/null +++ b/flowroutenumbersandmessaging/models/number_26.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.number_26 + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" +import flowroutenumbersandmessaging.models.data_27 + +class Number26(object): + + """Implementation of the 'Number26' model. + + TODO: type model description here. + + Attributes: + data (Data27): TODO: type description here. + included (list of object): TODO: type description here. + + """ + + # Create a mapping from Model property names to API property names + _names = { + "data" : "data", + "included" : "included" + } + + def __init__(self, + data=None, + included=None): + """Constructor for the Number26 class""" + + # Initialize members of the class + self.data = data + self.included = included + + + @classmethod + def from_dictionary(cls, + dictionary): + """Creates an instance of this model from a dictionary + + Args: + dictionary (dictionary): A dictionary representation of the object as + obtained from the deserialization of the server's response. The keys + MUST match property names in the API description. + + Returns: + object: An instance of this structure class. + + """ + if dictionary is None: + return None + + # Extract variables from the dictionary + data = flowroutenumbersandmessaging.models.data_27.Data27.from_dictionary(dictionary.get("data")) if dictionary.get("data") else None + included = dictionary.get("included") + + # Return an object of this model + return cls(data, + included) + + diff --git a/flowroutenumbersandmessaging/models/number_26.pyc b/flowroutenumbersandmessaging/models/number_26.pyc new file mode 100644 index 0000000..0481600 Binary files /dev/null and b/flowroutenumbersandmessaging/models/number_26.pyc differ diff --git a/flowroutenumbersandmessaging/models/number_type_enum.py b/flowroutenumbersandmessaging/models/number_type_enum.py new file mode 100644 index 0000000..3e5f80f --- /dev/null +++ b/flowroutenumbersandmessaging/models/number_type_enum.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.number_type_enum + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" + +class NumberTypeEnum(object): + + """Implementation of the 'NumberType' enum. + + TODO: type enum description here. + + Attributes: + STANDARD: TODO: type description here. + TOLLFREE: TODO: type description here. + INUM: TODO: type description here. + + """ + + STANDARD = 'standard' + + TOLLFREE = 'tollfree' + + INUM = 'inum' + diff --git a/flowroutenumbersandmessaging/models/route_type_enum.py b/flowroutenumbersandmessaging/models/route_type_enum.py new file mode 100644 index 0000000..c9c6c4a --- /dev/null +++ b/flowroutenumbersandmessaging/models/route_type_enum.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- + +""" + flowroutenumbersandmessaging.models.route_type_enum + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ) +""" + +class RouteTypeEnum(object): + + """Implementation of the 'RouteType' enum. + + TODO: type enum description here. + + Attributes: + SIPREG: TODO: type description here. + HOST: TODO: type description here. + URI: TODO: type description here. + NUMBER: TODO: type description here. + + """ + + SIPREG = 'sip-reg' + + HOST = 'host' + + URI = 'uri' + + NUMBER = 'number' + diff --git a/iptables-rules.txt b/iptables-rules.txt new file mode 100644 index 0000000..fad2aeb --- /dev/null +++ b/iptables-rules.txt @@ -0,0 +1,3 @@ +iptables -A INPUT -s 52.88.246.140 -j ACCEPT +iptables -A INPUT -s 52.10.220.50 -j ACCEPT +iptables -A INPUT -p tcp --dport 8090 -j REJECT \ No newline at end of file diff --git a/smslisten.py b/smslisten.py new file mode 100644 index 0000000..5016705 --- /dev/null +++ b/smslisten.py @@ -0,0 +1,71 @@ +import os +import urllib +import requests +import json +import pprint +import time +from flask import Flask, request +from flowroutenumbersandmessaging.flowroutenumbersandmessaging_client import FlowroutenumbersandmessagingClient +import sys +reload(sys) +sys.setdefaultencoding('utf-8') + +basic_auth_user_name = os.environ.get('FR_ACCESS_KEY') +basic_auth_password = os.environ.get('FR_SECRET_KEY') + +from_number = os.environ.get('FROM_NUMBER') + +client = FlowroutenumbersandmessagingClient(basic_auth_user_name, basic_auth_password) +messages_controller = client.messages + +#Flowroute API endpoint and reply SMS to be sent +fr_api_url = "https://api.flowroute.com/v2.1/messages" +reply_message = 'Thanks for the picture!' + +app = Flask(__name__) +app.debug = True + +@app.route('/inboundsms', methods=['POST']) +def inboundsms(): + + #extract attributes from POSTed JSON of inbound MMS + json_content = request.json + reply_to = json_content['data']['attributes']['from'] + reply_from = json_content['data']['attributes']['to'] + body = json_content['data']['attributes']['body'].decode('utf-8') + + pprint.pprint(body) + + #send a reply SMS from your Flowroute number + sendreply(reply_to, from_number, "You said " + body) + file = open("sms-logs.txt","a") + + file.write(reply_to +': ' + body + "\n") + file.close() + + return '0' + +def sendreply(reply_to, reply_from, msg): + request_body = '{ \ + "data": { \ + "type": "message", \ + "attributes": { \ + "to": "' + str(reply_to) + '", \ + "from": "' + str(reply_from) + '", \ + "body": "' + msg + '", \ + "is_mms": "false" \ + } \ + } \ +}' + + print ("---Send A Message") + result = messages_controller.send_a_message(request_body) + pprint.pprint(result) + + return '0' + +if __name__ == '__main__': + app.run( + host="0.0.0.0", + port=int("8090") + ) \ No newline at end of file diff --git a/smssend.py b/smssend.py new file mode 100644 index 0000000..dd2c0c6 --- /dev/null +++ b/smssend.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +import pprint +import os +import json +import random +import string +from flowroutenumbersandmessaging.flowroutenumbersandmessaging_client import FlowroutenumbersandmessagingClient + +basic_auth_user_name = os.environ.get('FR_ACCESS_KEY') +basic_auth_password = os.environ.get('FR_SECRET_KEY') + +mobile_number = os.environ.get('TO_NUMBER') +from_number = os.environ.get('FROM_NUMBER') + +# Instantiate API client and create controllers for Messages +client = FlowroutenumbersandmessagingClient(basic_auth_user_name, basic_auth_password) +messages_controller = client.messages + +request_body = '{ \ + "data": { \ + "type": "message", \ + "attributes": { \ + "to": "' + str(mobile_number) + '", \ + "from": "' + str(from_number) + '", \ + "body": "Try me", \ + "is_mms": "false" \ + } \ + } \ +}' + +print ("---Send A Message") +result = messages_controller.send_a_message(request_body) +pprint.pprint(result) \ No newline at end of file