Skip to content

Commit

Permalink
Merge pull request #5 from pepipost/param_updates
Browse files Browse the repository at this point in the history
Param updates -- approved
  • Loading branch information
ivikramsahu authored Nov 13, 2019
2 parents 6d460f7 + 925de91 commit f4cdd54
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 4 deletions.
72 changes: 72 additions & 0 deletions advanceUsage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#### Example of Advance Usage

```python
# -*- coding: utf-8 -*-
from pepipost.pepipost_client import PepipostClient
from pepipost.models.email_body import EmailBody
from pepipost.models.personalizations import Personalizations
from pepipost.models.attachments import Attachments
from pepipost.models.mfrom import From
from pepipost.models.email_body_attachments import EmailBodyAttachments
from pepipost.models.settings import Settings
from pepipost.exceptions.api_exception import APIException
from pepipost.models.attributes import Attributes
from pepipost.models.xheaders import Xheaders
import jsonpickle

client = PepipostClient()
email_controller = client.email
body = EmailBody()
body.personalizations = []

api_key = 'pass api-key here'
body.personalizations.append(Personalizations())

body.personalizations[0].recipient = 'my-email-id@domain.com'
body.personalizations[0].x_apiheader_cc = 'x api header cc content'
body.personalizations[0].x_apiheader = 'xapi header for emails'
body.personalizations[0].attributes = Attributes('{"name":"pepi","love":"Emails"}').get_attributes()
body.personalizations[0].attachments = []
body.personalizations[0].attachments.append(Attachments())
body.personalizations[0].attachments[0].file_content = '"SGVsbG8sIHRoaXMgZmlsZSBpcyBhbiBpbmZvcm1hdGlvbmFsIGZpbGU6OiBTZW5kaW5nIGVtYWlscyB0byB0aGUgaW5ib3ggaXMgd2hhdCB3ZSBkbywgYnV0IHRoYXTigJlzIG5vdCB0aGUgb25seSByZWFzb24gd2h5IGRldmVsb3BlcnMgYW5kIGVudGVycHJpc2VzIGxvdmUgdXMuIFdlIGFyZSB0aGUgb25seSBFU1AgdGhhdCBkb2VzbuKAmXQgY2hhcmdlIGZvciBlbWFpbHMgb3BlbmVkLg=="'
body.personalizations[0].attachments[0].file_name = 'pepipost.txt'
body.personalizations[0].recipient_cc = ['my-cc-emailid@gmail.com']
body.personalizations[0].recipient_bcc = ['my-email-bcc-id@domain.com']
body.personalizations[0].x_headers = Xheaders('{"custom_key1":"custom_value1","custom_key2":"custom_value2"}').get_xheaders()

body.tags = 'tagsPython'
body.mfrom = From()

body.mfrom.from_email = 'pepi@net.xyz'
body.mfrom.from_name = 'i am pepi'
body.subject = 'Pepipost mail through php sdk'
body.content = '<html><body>Hello, Welcome to Pepipost Family.<br>My name is [% name %].<br>my love is sending [% love %]</body> <br></html>'
body.ampcontent = '<!doctype html><html ⚡4email><head><meta charset="utf-8"><script async src="https://cdn.ampproject.org/v0.js"></script><style amp4email-boilerplate>body{visibility:hidden}</style></head><body> Hello, AMP4EMAIL world.</body></html>'

body.attachments = []
body.attachments.append(EmailBodyAttachments())
body.attachments[0].file_content = '"SGVsbG8sIHRoaXMgZmlsZSBpcyBhbiBpbmZvcm1hdGlvbmFsIGZpbGU6OiBTZW5kaW5nIGVtYWlscyB0byB0aGUgaW5ib3ggaXMgd2hhdCB3ZSBkbywgYnV0IHRoYXTigJlzIG5vdCB0aGUgb25seSByZWFzb24gd2h5IGRldmVsb3BlcnMgYW5kIGVudGVycHJpc2VzIGxvdmUgdXMuIFdlIGFyZSB0aGUgb25seSBFU1AgdGhhdCBkb2VzbuKAmXQgY2hhcmdlIGZvciBlbWFpbHMgb3BlbmVkLg=="'
body.attachments[0].file_name = 'pepipost_1.txt'

body.settings = Settings()

body.settings.footer = 1
body.settings.clicktrack = 1
body.settings.opentrack = 1
body.settings.unsubscribe = 1
body.settings.bcc = 'my-email-bcc-id@domain.com'
body.reply_to_id = 'replyto@gmail.com'
body.template_id = 11344

URL = "https://<api-endpoint>";

try:
result = email_controller.create_send_email(api_key, body, URL)
if not (result.error_info is None):
print("Reason :: " + str(result.error_info.error_message) + "\n" + "Message :: " + str(result.message))
else:
print("Message :: " + result.message)
except APIException as e:
print(e)

```
8 changes: 7 additions & 1 deletion pepipost/controllers/email_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class EmailController(BaseController):

def create_send_email(self,
api_key=None,
body=None):
body=None,
url=None):
"""Does a POST request to /v2/sendEmail.
This Endpoint sends emails with the credentials passed.
Expand All @@ -43,6 +44,11 @@ def create_send_email(self,
# Prepare query URL
_query_builder = Configuration.base_uri
_query_builder += '/v2/sendEmail'

# check if url is passed
if url!=None and url.strip() != '':
_query_builder = url

_query_url = APIHelper.clean_url(_query_builder)

# Prepare headers
Expand Down
45 changes: 45 additions & 0 deletions pepipost/models/attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-

"""
pepipost.models.attributes
This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io )
"""

from ..api_helper import APIHelper
class Attributes:

"""Implementation of the 'Attributes' model.
TODO: type model description here.
Attributes:
attributes (string): TODO: type description here.
"""

def __init__(self,
attributes):
"""Constructor for the Attributes class"""

# Initialize members of the class
self.attributes = attributes


def get_attributes(self):
"""Creates an instance of this model from a dictionary
Args:
JSON (string): A key value pair json string.
Returns:
dictionary : dictionary mapping of passed attributes
"""
if self.attributes == "" or self.attributes == None:
return None

return APIHelper.json_deserialize(self.attributes)




6 changes: 6 additions & 0 deletions pepipost/models/email_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class EmailBody(object):
mfrom (From): TODO: type description here.
subject (string): TODO: type description here.
content (string): TODO: type description here.
ampcontent (string): TODO: type description here.
attachments (list of EmailBodyAttachments): TODO: type description
here.
settings (Settings): TODO: type description here.
Expand All @@ -38,6 +39,7 @@ class EmailBody(object):
"mfrom":'from',
"subject":'subject',
"content":'content',
"ampcontent":'ampcontent',
"attachments":'attachments',
"settings":'settings',
"reply_to_id":'replyToId',
Expand All @@ -50,6 +52,7 @@ def __init__(self,
mfrom=None,
subject=None,
content=None,
ampcontent=None,
attachments=None,
settings=None,
reply_to_id=None,
Expand All @@ -62,6 +65,7 @@ def __init__(self,
self.mfrom = mfrom
self.subject = subject
self.content = content
self.ampcontent = ampcontent
self.attachments = attachments
self.settings = settings
self.reply_to_id = reply_to_id
Expand Down Expand Up @@ -95,6 +99,7 @@ def from_dictionary(cls,
mfrom = pepipost.models.mfrom.From.from_dictionary(dictionary.get('from')) if dictionary.get('from') else None
subject = dictionary.get('subject')
content = dictionary.get('content')
ampcontent = dictionary.get('ampcontent')
attachments = None
if dictionary.get('attachments') != None:
attachments = list()
Expand All @@ -110,6 +115,7 @@ def from_dictionary(cls,
mfrom,
subject,
content,
ampcontent,
attachments,
settings,
reply_to_id,
Expand Down
18 changes: 15 additions & 3 deletions pepipost/models/personalizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Personalizations(object):
attributes (object): TODO: type description here.
attachments (list of Attachments): TODO: type description here.
recipient_cc (list of string): TODO: type description here.
recipient_bcc (list of string): TODO: type description here.
x_headers (object): TODO: type description here.
"""

Expand All @@ -30,7 +32,9 @@ class Personalizations(object):
"x_apiheader":'x-apiheader',
"attributes":'attributes',
"attachments":'attachments',
"recipient_cc":'recipient_cc'
"recipient_cc":'recipient_cc',
"recipient_bcc":'recipient_bcc',
"x_headers":'x-headers'
}

def __init__(self,
Expand All @@ -39,7 +43,9 @@ def __init__(self,
x_apiheader=None,
attributes=None,
attachments=None,
recipient_cc=None):
recipient_cc=None,
recipient_bcc=None,
x_headers=None):
"""Constructor for the Personalizations class"""

# Initialize members of the class
Expand All @@ -49,6 +55,8 @@ def __init__(self,
self.attributes = attributes
self.attachments = attachments
self.recipient_cc = recipient_cc
self.recipient_bcc = recipient_bcc
self.x_headers = x_headers


@classmethod
Expand Down Expand Up @@ -79,13 +87,17 @@ def from_dictionary(cls,
for structure in dictionary.get('attachments'):
attachments.append(pepipost.models.attachments.Attachments.from_dictionary(structure))
recipient_cc = dictionary.get('recipient_cc')
recipient_bcc = dictionary.get('recipient_bcc')
x_headers = dictionary.get('x-headers')

# Return an object of this model
return cls(recipient,
x_apiheader_cc,
x_apiheader,
attributes,
attachments,
recipient_cc)
recipient_cc,
recipient_bcc,
x_headers)


44 changes: 44 additions & 0 deletions pepipost/models/xheaders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-

"""
pepipost.models.attributes
This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io )
"""

from ..api_helper import APIHelper
class Xheaders:

"""Implementation of the 'Attributes' model.
TODO: type model description here.
Attributes:
xheaders (string): TODO: type description here.
"""

def __init__(self,
xheaders):
"""Constructor for the xheaders class"""

# Initialize members of the class
self.xheaders = xheaders


def get_xheaders(self):
"""Creates an instance of this model from a dictionary
Args:
JSON (string): A key value pair json string.
Returns:
dictionary : dictionary mapping of passed xheaders
"""

if self.xheaders == "" or self.xheaders == None:
return None

return APIHelper.json_deserialize(self.xheaders)


0 comments on commit f4cdd54

Please sign in to comment.