Esempio n. 1
0
    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)
    def remove_domain_or_email_to_suppression_list(self, body):
        """Does a DELETE request to /suppression.

        Use this API to remove an email address or a recipient domain from the
        suppression list. You can remove multiple email addresses and
        recipient domains together by passing them as values & separating them
        using commas as shown below.

        Args:
            body (RemoveEmailOrDomainToSuppressionList): remove email or
                domain to suppression list

        Returns:
            object: 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 = '/suppression'
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {'content-type': 'application/json; charset=utf-8'}

        # Prepare and execute request
        _request = self.http_client.delete(
            _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 == 400:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 401:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 403:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 405:
            raise APIException('Invalid input', _context)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body
    def get_domain_status_get(self,
                              status=None,
                              domain=None):
        """Does a GET request to /domain/getDomains.

        Lets you fetch status for the domain within pepipost account created
        by you

        Args:
            status (string, optional): TODO: type description here. Example: 
            domain (string, optional): TODO: type description here. Example: 

        Returns:
            object: 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 = '/domain/getDomains'
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_parameters = {
            'status': status,
            'domain': domain
        }
        _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)
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)

        # Endpoint and global error handling using HTTP status codes.
        if _context.response.status_code == 400:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 401:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 403:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 405:
            raise APIException('Invalid input', _context)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body
    def add_domain_or_email_to_suppression_list(self, body):
        """Does a POST request to /suppression.

        This API allows you to suppress an email address and block any future
        email delivery attempts on this email address.

        Args:
            body (AddEmailOrDomainToSuppressionList): add email or domain to
                suppression list

        Returns:
            object: 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 = '/suppression'
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {'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 == 400:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 401:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 403:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 405:
            raise APIException('Invalid input', _context)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body
    def delete_domain(self,
                      body):
        """Does a DELETE request to /domain/delete.

        This endpoint allows you to delete a domain from your Pepipost
        account.

        Args:
            body (DeleteDomain): delete domain

        Returns:
            object: 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 = '/domain/delete'
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'content-type': 'application/json; charset=utf-8'
        }

        # Prepare and execute request
        _request = self.http_client.delete(_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 == 400:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 401:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 403:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 405:
            raise APIException('Invalid input', _context)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body
    def create_subaccounts_create_subaccount_post(self,
                                                  body):
        """Does a POST request to /subaccounts/createSubaccount.

        Subaccount is the same as any regular Pepipost account however the
        credits are managed by the master account.

        Args:
            body (CreateSubaccount): create sub account

        Returns:
            object: 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 = '/subaccounts/createSubaccount'
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            '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 == 400:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 401:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 403:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 405:
            raise APIException('Invalid input', _context)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body
Esempio n. 7
0
    def create_generatethemailsendrequest(self, body):
        """Does a POST request to /mail/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:
            object: 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 = '/mail/send'
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {'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 == 400:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 401:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 403:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 405:
            raise APIException('Invalid input', _context)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body
    def get_template_get(self, template_id):
        """Does a GET request to /template.

        Let's you fetch template data using template_id for your pepipost
        account.

        Args:
            template_id (int): TODO: type description here. Example: 

        Returns:
            object: 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 = '/template'
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_parameters = {'template_id': template_id}
        _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)
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)

        # Endpoint and global error handling using HTTP status codes.
        if _context.response.status_code == 400:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 401:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 403:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 405:
            raise APIException('Invalid input', _context)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body
    def get_stats_get(self,
                      startdate,
                      enddate=None,
                      aggregated_by=None,
                      offset=1,
                      limit=100):
        """Does a GET request to /stats.

        Lets you fetch all the subaccounts created by you

        Args:
            startdate (date): The starting date of the statistics to retrieve.
                Must follow format YYYY-MM-DD.
            enddate (date, optional): The end date of the statistics to
                retrieve. Defaults to today. Must follow format YYYY-MM-DD.
            aggregated_by (AggregatedByEnum, optional): TODO: type description
                here. Example: 
            offset (int, optional): TODO: type description here. Example: 1
            limit (int, optional): TODO: type description here. Example: 100

        Returns:
            object: 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 = '/stats'
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_parameters = {
            'startdate': startdate,
            'enddate': enddate,
            'aggregated_by': aggregated_by,
            'offset': offset,
            'limit': limit
        }
        _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)
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)

        # Endpoint and global error handling using HTTP status codes.
        if _context.response.status_code == 400:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 401:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 403:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 405:
            raise APIException('Invalid input', _context)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body
Esempio n. 10
0
    def get_events_get(self,
                       startdate,
                       events=None,
                       sort=None,
                       enddate=None,
                       offset=0,
                       limit=10,
                       subject=None,
                       xapiheader=None,
                       fromaddress=None,
                       email=None):
        """Does a GET request to /events.

        Lets you to retrieve the email transaction logs.

        Args:
            startdate (date): The starting date of the statistics to retrieve.
                Must follow format YYYY-MM-DD.
            events (EventsEnum, optional): Filter based on different email
                events. If not passed, all events will be fetched. Multiple
                comma separated events are allowed
            sort (SortEnum, optional): Sort based on email sent time
            enddate (date, optional): The end date of the statistics to
                retrieve. Defaults to today. Must follow format YYYY-MM-DD
            offset (int, optional): The point in the list to begin retrieving
                results.
            limit (int, optional): The number of results to return.
            subject (string, optional): Filter logs based on subject
            xapiheader (string, optional): Filter logs based on recipient's
                email
            fromaddress (string, optional): Filter logs based on fromaddress
            email (string, optional): Filter logs based on recipient's email

        Returns:
            object: 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 = '/events'
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_parameters = {
            'startdate': startdate,
            'events': events,
            'sort': sort,
            'enddate': enddate,
            'offset': offset,
            'limit': limit,
            'subject': subject,
            'xapiheader': xapiheader,
            'fromaddress': fromaddress,
            'email': email
        }
        _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)
        CustomHeaderAuth.apply(_request)
        _context = self.execute_request(_request)

        # Endpoint and global error handling using HTTP status codes.
        if _context.response.status_code == 400:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 401:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 403:
            raise APIException('API Response', _context)
        elif _context.response.status_code == 405:
            raise APIException('Invalid input', _context)
        self.validate_response(_context)

        # Return appropriate type
        return _context.response.raw_body