From 97b9c40215910f09917433e59b799443efec444c Mon Sep 17 00:00:00 2001 From: Vikram Date: Tue, 19 May 2020 15:44:45 +0530 Subject: [PATCH] adding pepipost v5 --- pepipost/__init__.py | 10 + pepipost/api_helper.py | 405 +++++++++++++++++++++++ pepipost/configuration.py | 59 ++++ pepipost/controllers/__init__.py | 4 + pepipost/controllers/base_controller.py | 96 ++++++ pepipost/controllers/send_controller.py | 66 ++++ pepipost/decorators.py | 22 ++ pepipost/exceptions/__init__.py | 3 + pepipost/exceptions/api_exception.py | 32 ++ pepipost/http/__init__.py | 10 + pepipost/http/auth/__init__.py | 3 + pepipost/http/auth/custom_header_auth.py | 23 ++ pepipost/http/http_call_back.py | 36 ++ pepipost/http/http_client.py | 199 +++++++++++ pepipost/http/http_context.py | 34 ++ pepipost/http/http_method_enum.py | 48 +++ pepipost/http/http_request.py | 83 +++++ pepipost/http/http_response.py | 37 +++ pepipost/http/requests_client.py | 101 ++++++ pepipost/models/__init__.py | 10 + pepipost/models/attachments.py | 63 ++++ pepipost/models/content.py | 63 ++++ pepipost/models/email_struct.py | 63 ++++ pepipost/models/mfrom.py | 63 ++++ pepipost/models/personalizations.py | 124 +++++++ pepipost/models/send.py | 148 +++++++++ pepipost/models/settings.py | 81 +++++ pepipost/models/type_enum.py | 24 ++ pepipost/pepipost_client.py | 27 ++ 29 files changed, 1937 insertions(+) create mode 100644 pepipost/__init__.py create mode 100644 pepipost/api_helper.py create mode 100644 pepipost/configuration.py create mode 100644 pepipost/controllers/__init__.py create mode 100644 pepipost/controllers/base_controller.py create mode 100644 pepipost/controllers/send_controller.py create mode 100644 pepipost/decorators.py create mode 100644 pepipost/exceptions/__init__.py create mode 100644 pepipost/exceptions/api_exception.py create mode 100644 pepipost/http/__init__.py create mode 100644 pepipost/http/auth/__init__.py create mode 100644 pepipost/http/auth/custom_header_auth.py create mode 100644 pepipost/http/http_call_back.py create mode 100644 pepipost/http/http_client.py create mode 100644 pepipost/http/http_context.py create mode 100644 pepipost/http/http_method_enum.py create mode 100644 pepipost/http/http_request.py create mode 100644 pepipost/http/http_response.py create mode 100644 pepipost/http/requests_client.py create mode 100644 pepipost/models/__init__.py create mode 100644 pepipost/models/attachments.py create mode 100644 pepipost/models/content.py create mode 100644 pepipost/models/email_struct.py create mode 100644 pepipost/models/mfrom.py create mode 100644 pepipost/models/personalizations.py create mode 100644 pepipost/models/send.py create mode 100644 pepipost/models/settings.py create mode 100644 pepipost/models/type_enum.py create mode 100644 pepipost/pepipost_client.py diff --git a/pepipost/__init__.py b/pepipost/__init__.py new file mode 100644 index 0000000..cdbbbe6 --- /dev/null +++ b/pepipost/__init__.py @@ -0,0 +1,10 @@ +__all__ = [ + 'api_helper', + 'configuration', + 'models', + 'controllers', + 'http', + 'exceptions', + 'decorators', + 'pepipost_client', +] \ No newline at end of file diff --git a/pepipost/api_helper.py b/pepipost/api_helper.py new file mode 100644 index 0000000..45f03b7 --- /dev/null +++ b/pepipost/api_helper.py @@ -0,0 +1,405 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +import re +import sys +import datetime +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, encode=True): + """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='') if encode else str(x)) for x in element) + else: + replace_value = quote(str(element), safe='') if encode else str(element) + + 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 + + @staticmethod + def when_defined(func, value): + return func(value) if value else None + + 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): + return date_time.isoformat() + + @classmethod + def from_value(cls, value): + dtime = dateutil.parser.parse(value) + return cls(dtime, value) diff --git a/pepipost/configuration.py b/pepipost/configuration.py new file mode 100644 index 0000000..7968656 --- /dev/null +++ b/pepipost/configuration.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +from pepipost.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" + + # An enum for SDK environments + class Environment(object): + PRODUCTION = 0 + + # An enum for API servers + class Server(object): + SERVER1 = 0 + + # The environment in which the SDK is running + environment = Environment.PRODUCTION + + # Your Pepipost API Key. You will find the api key in the Pepipost + # application in Integrations. + api_key = '4D51B3ECA2D4ED3A67E4E043B3F1A4D1' + + + # All the environments the SDK can run in + environments = { + Environment.PRODUCTION: { + Server.SERVER1: 'https://api.pepipost.com/v5/mail', + }, + } + + @classmethod + def get_base_uri(cls, server=Server.SERVER1): + """Generates the appropriate base URI for the environment and the server. + + Args: + server (Configuration.Server): The server enum for which the base URI is required. + + Returns: + String: The base URI. + + """ + return cls.environments[cls.environment][server] diff --git a/pepipost/controllers/__init__.py b/pepipost/controllers/__init__.py new file mode 100644 index 0000000..b85d63f --- /dev/null +++ b/pepipost/controllers/__init__.py @@ -0,0 +1,4 @@ +__all__ = [ + 'base_controller', + 'send_controller', +] \ No newline at end of file diff --git a/pepipost/controllers/base_controller.py b/pepipost/controllers/base_controller.py new file mode 100644 index 0000000..1a090c9 --- /dev/null +++ b/pepipost/controllers/base_controller.py @@ -0,0 +1,96 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +from pepipost.api_helper import APIHelper +from pepipost.http.http_context import HttpContext +from pepipost.http.requests_client import RequestsClient +from pepipost.exceptions.api_exception import APIException + +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. + global_headers (dict): The global headers of the API which are sent with + every request. + + """ + + http_client = RequestsClient() + + http_call_back = None + + global_headers = { + 'user-agent': 'APIMATIC 2.0' + } + + def __init__(self, client=None, call_back=None): + if client != None: + self.http_client = client + if call_back != None: + self.http_call_back = call_back + + def validate_parameters(self, **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 != 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 != None: + self.http_call_back.on_after_response(context) + + return context + + def validate_response(self, context): + """Validates an HTTP response by checking for global errors. + + Args: + context (HttpContext): The HttpContext of the API call. + + """ + if context.response.status_code == 400: + raise APIException('Bad request', context) + elif (context.response.status_code < 200) or (context.response.status_code > 208): #[200,208] = HTTP OK + raise APIException('HTTP response not OK.', context) diff --git a/pepipost/controllers/send_controller.py b/pepipost/controllers/send_controller.py new file mode 100644 index 0000000..bac799c --- /dev/null +++ b/pepipost/controllers/send_controller.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +from pepipost.api_helper import APIHelper +from pepipost.configuration import Configuration +from pepipost.controllers.base_controller import BaseController +from pepipost.http.auth.custom_header_auth import CustomHeaderAuth +from pepipost.exceptions.api_exception import APIException + +class SendController(BaseController): + + """A Controller to access Endpoints in the pepipost API.""" + + + def create_generate_the_mail_send_request(self, + body): + """Does a POST request to /send. + + The endpoint send is used to generate the request to pepipost server + for sending an email to recipients. + + Args: + body (Send): New mail request will be generated + + Returns: + list of string: Response from the API. API Response + + 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 + _url_path = '/send' + _query_builder = Configuration.get_base_uri(Configuration.Server.SERVER1) + _query_builder += _url_path + _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(body)) + CustomHeaderAuth.apply(_request) + _context = self.execute_request(_request) + + # Endpoint and global error handling using HTTP status codes. + if _context.response.status_code in (400, 401, 403): + return APIHelper.json_deserialize(_context.response.raw_body) + if _context.response.status_code == 405: + raise APIException('Invalid input', _context) + self.validate_response(_context) + + # Return appropriate type + return APIHelper.json_deserialize(_context.response.raw_body) diff --git a/pepipost/decorators.py b/pepipost/decorators.py new file mode 100644 index 0000000..0c8bc76 --- /dev/null +++ b/pepipost/decorators.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + 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/pepipost/exceptions/__init__.py b/pepipost/exceptions/__init__.py new file mode 100644 index 0000000..3c8e725 --- /dev/null +++ b/pepipost/exceptions/__init__.py @@ -0,0 +1,3 @@ +__all__ = [ + 'api_exception', +] \ No newline at end of file diff --git a/pepipost/exceptions/api_exception.py b/pepipost/exceptions/api_exception.py new file mode 100644 index 0000000..7f183c6 --- /dev/null +++ b/pepipost/exceptions/api_exception.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + 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/pepipost/http/__init__.py b/pepipost/http/__init__.py new file mode 100644 index 0000000..fb528a8 --- /dev/null +++ b/pepipost/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/pepipost/http/auth/__init__.py b/pepipost/http/auth/__init__.py new file mode 100644 index 0000000..aaa31be --- /dev/null +++ b/pepipost/http/auth/__init__.py @@ -0,0 +1,3 @@ +__all__ = [ + 'custom_header_auth', +] \ No newline at end of file diff --git a/pepipost/http/auth/custom_header_auth.py b/pepipost/http/auth/custom_header_auth.py new file mode 100644 index 0000000..74d6e1c --- /dev/null +++ b/pepipost/http/auth/custom_header_auth.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +from pepipost.configuration import Configuration + + +class CustomHeaderAuth: + + @staticmethod + def apply(http_request): + """ Add custom authentication to the request. + + Args: + http_request (HttpRequest): The HttpRequest object to which + authentication will be added. + + """ + http_request.add_header("api_key", Configuration.api_key) diff --git a/pepipost/http/http_call_back.py b/pepipost/http/http_call_back.py new file mode 100644 index 0000000..4f4890a --- /dev/null +++ b/pepipost/http/http_call_back.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + 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/pepipost/http/http_client.py b/pepipost/http/http_client.py new file mode 100644 index 0000000..ddcea16 --- /dev/null +++ b/pepipost/http/http_client.py @@ -0,0 +1,199 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +from pepipost.http.http_method_enum import HttpMethodEnum +from pepipost.http.http_request import HttpRequest + + +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 head(self, query_url, + headers={}, + query_parameters={}): + """Create a simple HEAD 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.HEAD, + 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/pepipost/http/http_context.py b/pepipost/http/http_context.py new file mode 100644 index 0000000..afd17b6 --- /dev/null +++ b/pepipost/http/http_context.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + 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/pepipost/http/http_method_enum.py b/pepipost/http/http_method_enum.py new file mode 100644 index 0000000..2b03908 --- /dev/null +++ b/pepipost/http/http_method_enum.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + 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" + + HEAD = "HEAD" + + @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/pepipost/http/http_request.py b/pepipost/http/http_request.py new file mode 100644 index 0000000..a0e70b3 --- /dev/null +++ b/pepipost/http/http_request.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +from pepipost.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/pepipost/http/http_response.py b/pepipost/http/http_response.py new file mode 100644 index 0000000..2bb412f --- /dev/null +++ b/pepipost/http/http_response.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + 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/pepipost/http/requests_client.py b/pepipost/http/requests_client.py new file mode 100644 index 0000000..1822f30 --- /dev/null +++ b/pepipost/http/requests_client.py @@ -0,0 +1,101 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + 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 pepipost.http.http_client import HttpClient +from pepipost.http.http_method_enum import HttpMethodEnum +from pepipost.http.http_response import HttpResponse + + +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/pepipost/models/__init__.py b/pepipost/models/__init__.py new file mode 100644 index 0000000..23be1e8 --- /dev/null +++ b/pepipost/models/__init__.py @@ -0,0 +1,10 @@ +__all__ = [ + 'mfrom', + 'settings', + 'content', + 'attachments', + 'email_struct', + 'personalizations', + 'send', + 'type_enum', +] \ No newline at end of file diff --git a/pepipost/models/attachments.py b/pepipost/models/attachments.py new file mode 100644 index 0000000..32aa67b --- /dev/null +++ b/pepipost/models/attachments.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + + +class Attachments(object): + + """Implementation of the 'Attachments' model. + + Attachments + + Attributes: + content (string): Base64 encoded value of the attached file + name (string): filename of attachments + + """ + + # Create a mapping from Model property names to API property names + _names = { + "content":'content', + "name":'name' + } + + def __init__(self, + content=None, + name=None): + """Constructor for the Attachments class""" + + # Initialize members of the class + self.content = content + self.name = name + + + @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 + content = dictionary.get('content') + name = dictionary.get('name') + + # Return an object of this model + return cls(content, + name) + + diff --git a/pepipost/models/content.py b/pepipost/models/content.py new file mode 100644 index 0000000..c43e48c --- /dev/null +++ b/pepipost/models/content.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + + +class Content(object): + + """Implementation of the 'Content' model. + + AMP, HTML should be provided + + Attributes: + mtype (TypeEnum): content in text/plain format + value (string): HTML content to be sent in your email + + """ + + # Create a mapping from Model property names to API property names + _names = { + "mtype":'type', + "value":'value' + } + + def __init__(self, + mtype=None, + value=None): + """Constructor for the Content class""" + + # Initialize members of the class + self.mtype = mtype + 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 + mtype = dictionary.get('type') + value = dictionary.get('value') + + # Return an object of this model + return cls(mtype, + value) + + diff --git a/pepipost/models/email_struct.py b/pepipost/models/email_struct.py new file mode 100644 index 0000000..240c52c --- /dev/null +++ b/pepipost/models/email_struct.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + + +class EmailStruct(object): + + """Implementation of the 'EmailStruct' model. + + To, CC and Bcc email Address structure + + Attributes: + name (string): Name of recipient + email (string): Email of recipient + + """ + + # Create a mapping from Model property names to API property names + _names = { + "name":'name', + "email":'email' + } + + def __init__(self, + name=None, + email=None): + """Constructor for the EmailStruct class""" + + # Initialize members of the class + self.name = name + self.email = email + + + @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 + name = dictionary.get('name') + email = dictionary.get('email') + + # Return an object of this model + return cls(name, + email) + + diff --git a/pepipost/models/mfrom.py b/pepipost/models/mfrom.py new file mode 100644 index 0000000..03747df --- /dev/null +++ b/pepipost/models/mfrom.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + + +class From(object): + + """Implementation of the 'From' model. + + Email address representing the sender of the mail + + Attributes: + email (string): TODO: type description here. + name (string): TODO: type description here. + + """ + + # Create a mapping from Model property names to API property names + _names = { + "email":'email', + "name":'name' + } + + def __init__(self, + email=None, + name=None): + """Constructor for the From class""" + + # Initialize members of the class + self.email = email + self.name = name + + + @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 + email = dictionary.get('email') + name = dictionary.get('name') + + # Return an object of this model + return cls(email, + name) + + diff --git a/pepipost/models/personalizations.py b/pepipost/models/personalizations.py new file mode 100644 index 0000000..afd3aba --- /dev/null +++ b/pepipost/models/personalizations.py @@ -0,0 +1,124 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +import pepipost.models.attachments +import pepipost.models.email_struct + +class Personalizations(object): + + """Implementation of the 'Personalizations' model. + + Personalizations + + Attributes: + attributes (object): Dynamic attributes + headers (object): Dynamic headers attributes + attachments (list of Attachments): Attachments to individuals + recipient + to (list of EmailStruct): To email-address + cc (list of EmailStruct): CC email-address + bcc (list of EmailStruct): Bcc email-addresses + token_to (string): token to which is json string + token_cc (string): token cc which is json string + token_bcc (string): token bcc which is json string + + """ + + # Create a mapping from Model property names to API property names + _names = { + "to":'to', + "attributes":'attributes', + "headers":'headers', + "attachments":'attachments', + "cc":'cc', + "bcc":'bcc', + "token_to":'token_to', + "token_cc":'token_cc', + "token_bcc":'token_bcc' + } + + def __init__(self, + to=None, + attributes=None, + headers=None, + attachments=None, + cc=None, + bcc=None, + token_to=None, + token_cc=None, + token_bcc=None): + """Constructor for the Personalizations class""" + + # Initialize members of the class + self.attributes = attributes + self.headers = headers + self.attachments = attachments + self.to = to + self.cc = cc + self.bcc = bcc + self.token_to = token_to + self.token_cc = token_cc + self.token_bcc = token_bcc + + + @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 + to = None + if dictionary.get('to') != None: + to = list() + for structure in dictionary.get('to'): + to.append(pepipost.models.email_struct.EmailStruct.from_dictionary(structure)) + attributes = dictionary.get('attributes') + headers = dictionary.get('headers') + attachments = None + if dictionary.get('attachments') != None: + attachments = list() + for structure in dictionary.get('attachments'): + attachments.append(pepipost.models.attachments.Attachments.from_dictionary(structure)) + cc = None + if dictionary.get('cc') != None: + cc = list() + for structure in dictionary.get('cc'): + cc.append(pepipost.models.email_struct.EmailStruct.from_dictionary(structure)) + bcc = None + if dictionary.get('bcc') != None: + bcc = list() + for structure in dictionary.get('bcc'): + bcc.append(pepipost.models.email_struct.EmailStruct.from_dictionary(structure)) + token_to = dictionary.get('token_to') + token_cc = dictionary.get('token_cc') + token_bcc = dictionary.get('token_bcc') + + # Return an object of this model + return cls(to, + attributes, + headers, + attachments, + cc, + bcc, + token_to, + token_cc, + token_bcc) + + diff --git a/pepipost/models/send.py b/pepipost/models/send.py new file mode 100644 index 0000000..ee629ff --- /dev/null +++ b/pepipost/models/send.py @@ -0,0 +1,148 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +import pepipost.models.mfrom +import pepipost.models.content +import pepipost.models.attachments +import pepipost.models.personalizations +import pepipost.models.settings +import pepipost.models.email_struct + +class Send(object): + + """Implementation of the 'Send' model. + + Master modal + + Attributes: + reply_to (string): email address which recipients can reply to. + mfrom (From): email address representing the sender of the mail + subject (string): Subject line of the email + template_id (long|int): ID of the template to be used for sending the + mail + content (list of Content): content in text/plain format + attachments (list of Attachments): attachment information + personalizations (list of Personalizations): to recipient with some + personalized data like to address, attachments and attributes + settings (Settings): Enable/Disable settings like click, open and + unsubscribe track + tags (list of string): define custom tags to organize your emails + lint_payload (bool): TODO: type description here. + schedule (long|int): schedule the time of email delivery + bcc (list of EmailStruct): Global bcc can be defined here + + """ + + # Create a mapping from Model property names to API property names + _names = { + "mfrom":'from', + "subject":'subject', + "content":'content', + "personalizations":'personalizations', + "reply_to":'reply_to', + "template_id":'template_id', + "attachments":'attachments', + "settings":'settings', + "tags":'tags', + "lint_payload":'lint_payload', + "schedule":'schedule', + "bcc":'bcc' + } + + def __init__(self, + mfrom=None, + subject=None, + content=None, + personalizations=None, + reply_to=None, + template_id=None, + attachments=None, + settings=None, + tags=None, + lint_payload=None, + schedule=None, + bcc=None): + """Constructor for the Send class""" + + # Initialize members of the class + self.reply_to = reply_to + self.mfrom = mfrom + self.subject = subject + self.template_id = template_id + self.content = content + self.attachments = attachments + self.personalizations = personalizations + self.settings = settings + self.tags = tags + self.lint_payload = lint_payload + self.schedule = schedule + self.bcc = bcc + + + @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 = pepipost.models.mfrom.From.from_dictionary(dictionary.get('from')) if dictionary.get('from') else None + subject = dictionary.get('subject') + content = None + if dictionary.get('content') != None: + content = list() + for structure in dictionary.get('content'): + content.append(pepipost.models.content.Content.from_dictionary(structure)) + personalizations = None + if dictionary.get('personalizations') != None: + personalizations = list() + for structure in dictionary.get('personalizations'): + personalizations.append(pepipost.models.personalizations.Personalizations.from_dictionary(structure)) + reply_to = dictionary.get('reply_to') + template_id = dictionary.get('template_id') + attachments = None + if dictionary.get('attachments') != None: + attachments = list() + for structure in dictionary.get('attachments'): + attachments.append(pepipost.models.attachments.Attachments.from_dictionary(structure)) + settings = pepipost.models.settings.Settings.from_dictionary(dictionary.get('settings')) if dictionary.get('settings') else None + tags = dictionary.get('tags') + lint_payload = dictionary.get('lint_payload') + schedule = dictionary.get('schedule') + bcc = None + if dictionary.get('bcc') != None: + bcc = list() + for structure in dictionary.get('bcc'): + bcc.append(pepipost.models.email_struct.EmailStruct.from_dictionary(structure)) + + # Return an object of this model + return cls(mfrom, + subject, + content, + personalizations, + reply_to, + template_id, + attachments, + settings, + tags, + lint_payload, + schedule, + bcc) + + diff --git a/pepipost/models/settings.py b/pepipost/models/settings.py new file mode 100644 index 0000000..3afcfdd --- /dev/null +++ b/pepipost/models/settings.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + + +class Settings(object): + + """Implementation of the 'Settings' model. + + TODO: type model description here. + + Attributes: + footer (bool): enable or disable footer + click_track (bool): enable or disable click tracking + open_track (bool): enable or disable open tracking + unsubscribe_track (bool): enable or disable unsubscribe tracking + hepf (bool): TODO: type description here. + + """ + + # Create a mapping from Model property names to API property names + _names = { + "footer":'footer', + "click_track":'click_track', + "open_track":'open_track', + "unsubscribe_track":'unsubscribe_track', + "hepf":'hepf' + } + + def __init__(self, + footer=None, + click_track=None, + open_track=None, + unsubscribe_track=None, + hepf=None): + """Constructor for the Settings class""" + + # Initialize members of the class + self.footer = footer + self.click_track = click_track + self.open_track = open_track + self.unsubscribe_track = unsubscribe_track + self.hepf = hepf + + + @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 + footer = dictionary.get('footer') + click_track = dictionary.get('click_track') + open_track = dictionary.get('open_track') + unsubscribe_track = dictionary.get('unsubscribe_track') + hepf = dictionary.get('hepf') + + # Return an object of this model + return cls(footer, + click_track, + open_track, + unsubscribe_track, + hepf) + + diff --git a/pepipost/models/type_enum.py b/pepipost/models/type_enum.py new file mode 100644 index 0000000..f3f6bc6 --- /dev/null +++ b/pepipost/models/type_enum.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +class TypeEnum(object): + + """Implementation of the 'Type' enum. + + TODO: type enum description here. + + Attributes: + AMP: TODO: type description here. + HTML: TODO: type description here. + + """ + + AMP = 'amp' + + HTML = 'html' + diff --git a/pepipost/pepipost_client.py b/pepipost/pepipost_client.py new file mode 100644 index 0000000..f59c609 --- /dev/null +++ b/pepipost/pepipost_client.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +""" + pepipost + + This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). +""" + +from pepipost.decorators import lazy_property +from pepipost.configuration import Configuration +from pepipost.controllers.send_controller import SendController + + +class PepipostClient(object): + + config = Configuration + + @lazy_property + def send(self): + return SendController() + + + def __init__(self, + api_key='4D51B3ECA2D4ED3A67E4E043B3F1A4D1'): + if api_key is not None: + Configuration.api_key = api_key +