How to use the sparkpost.base.Resource function in sparkpost

To help you get started, we’ve selected a few sparkpost examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SparkPost / python-sparkpost / test / test_base.py View on Github external
def create_resource():
    resource = Resource(fake_base_uri, fake_api_key)
    resource.key = fake_resource_key
    return resource
github SparkPost / python-sparkpost / sparkpost / suppression_list.py View on Github external
import json

from .base import Resource


class SuppressionList(Resource):
    """
    SuppressionList class used to search, get and modify suppression status.
    For detailed request and response formats, see the `Suppresion List API
    documentation
    `_.
    """

    key = 'suppression-list'

    def list(self, **kwargs):
        """
        List supression list entries based on the supplied parameters

        :param datetime from_date: DateTime to start listing
        :param datetime to_date: DateTime to end listing
        :param list types: Types of entries to return
github SparkPost / python-sparkpost / sparkpost / transmissions.py View on Github external
'custom_headers': 'content/headers',
    'use_draft_template': 'content/use_draft_template',
    'reply_to': 'content/reply_to',
    'subject': 'content/subject',
    'from_email': 'content/from',
    'html': 'content/html',
    'text': 'content/text',
    'template': 'content/template_id',
    'attachments': 'content/attachments',
    'inline_images': 'content/inline_images',
    'recipient_list': 'recipients/list_id',
}
model_remap_keys = frozenset(model_remap.keys())


class Transmissions(Resource):
    """
    Transmission class used to send, list and get transmissions. For detailed
    request and response formats, see the `Transmissions API documentation
    `_.
    """

    key = 'transmissions'

    def _translate_keys(self, **kwargs):
        model = copy.deepcopy(kwargs)

        # Intersection of keys that need to be remapped
        data_remap_keys = model_remap_keys.intersection(model.keys())

        for from_key in data_remap_keys:
            # Remap model keys to match API
github SparkPost / python-sparkpost / sparkpost / metrics.py View on Github external
def __init__(self, base_uri, api_key, transport_class=RequestsTransport):
        self.base_uri = "%s/%s" % (base_uri, 'metrics')
        self.campaigns = Campaigns(self.base_uri, api_key, transport_class)
        self.domains = Domains(self.base_uri, api_key, transport_class)


class Campaigns(Resource):
    key = 'campaigns'

    def list(self, **kwargs):
        results = self.request('GET', self.uri, **kwargs)
        return results['campaigns']


class Domains(Resource):
    key = 'domains'

    def list(self, **kwargs):
        results = self.request('GET', self.uri, **kwargs)
        return results['domains']
github SparkPost / python-sparkpost / sparkpost / metrics.py View on Github external
from .base import Resource, RequestsTransport


class Metrics(object):
    "Wrapper for sub-resources"

    def __init__(self, base_uri, api_key, transport_class=RequestsTransport):
        self.base_uri = "%s/%s" % (base_uri, 'metrics')
        self.campaigns = Campaigns(self.base_uri, api_key, transport_class)
        self.domains = Domains(self.base_uri, api_key, transport_class)


class Campaigns(Resource):
    key = 'campaigns'

    def list(self, **kwargs):
        results = self.request('GET', self.uri, **kwargs)
        return results['campaigns']


class Domains(Resource):
    key = 'domains'

    def list(self, **kwargs):
        results = self.request('GET', self.uri, **kwargs)
        return results['domains']
github SparkPost / python-sparkpost / sparkpost / templates.py View on Github external
import json

from .base import Resource


class Templates(Resource):
    """
    Templates class used to create, update, delete, list and get templates. For
    detailed request and response formats, see the `Templates API documentation
    `_.
    """

    key = 'templates'

    def _translate_keys(self, **kwargs):
        model = {
            'content': {},
            'options': {}
        }

        if 'id' in kwargs:
            model['id'] = kwargs.get('id')
github SparkPost / python-sparkpost / sparkpost / sending_domains.py View on Github external
import json
from datetime import datetime

from Crypto.PublicKey import RSA

from .base import Resource


class SendingDomains(Resource):
    """
    SendingDomains class used to manage custom sending domains. For detailed
    request and response formats, see the `Sending Domains API documentation
    `_.
    """

    key = 'sending-domains'

    def _generate_key_pair(self):
        # TODO strip out ---public|private--- bits
        private = RSA.generate(1024)
        public = private.publickey()
        return private.exportKey(), public.exportKey()

    def _generate_selector(self):
        now = datetime.now()
github SparkPost / python-sparkpost / sparkpost / recipient_lists.py View on Github external
import json

from .base import Resource


class RecipientLists(Resource):
    """
    RecipientLists class used to create, update, delete, list and get recipient
    lists. For detailed request and response formats, see the `Recipient Lists
    API documentation
    `_.
    """

    key = 'recipient-lists'

    def _translate_keys(self, **kwargs):
        model = {}

        if 'id' in kwargs:
            model['id'] = kwargs.get('id')
        model['name'] = kwargs.get('name')
        model['description'] = kwargs.get('description')