Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_resource():
resource = Resource(fake_base_uri, fake_api_key)
resource.key = fake_resource_key
return resource
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
'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
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']
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']
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')
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()
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')