From a85b3be9050a29b972faae562d17ad5eddab46d3 Mon Sep 17 00:00:00 2001 From: Hiteshkumar Pandey Date: Mon, 7 Oct 2019 12:57:15 +0530 Subject: [PATCH 1/5] added new parameters --- advanceUsage.md | 69 +++++++++++++++++++++++++++++ pepipost/models/email_body.py | 6 +++ pepipost/models/personalizations.py | 18 ++++++-- 3 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 advanceUsage.md diff --git a/advanceUsage.md b/advanceUsage.md new file mode 100644 index 0000000..d93f7e8 --- /dev/null +++ b/advanceUsage.md @@ -0,0 +1,69 @@ +#### 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.api_helper import APIHelper +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 = APIHelper.json_deserialize('{"name":"pepi","love":"Emails"}') +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 = APIHelper.json_deserialize('{"custom_key1":"custom_value1","custom_key2":"custom_value2"}') + +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 = 'Hello, Welcome to Pepipost Family.
My name is [% name %].
my love is sending [% love %]
' +body.ampcontent = ' Hello, AMP4EMAIL world.' + +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 + +try: + result = email_controller.create_send_email(api_key, body) + 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) + +``` \ No newline at end of file diff --git a/pepipost/models/email_body.py b/pepipost/models/email_body.py index fdba285..26663a2 100644 --- a/pepipost/models/email_body.py +++ b/pepipost/models/email_body.py @@ -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. @@ -38,6 +39,7 @@ class EmailBody(object): "mfrom":'from', "subject":'subject', "content":'content', + "ampcontent":'ampcontent', "attachments":'attachments', "settings":'settings', "reply_to_id":'replyToId', @@ -50,6 +52,7 @@ def __init__(self, mfrom=None, subject=None, content=None, + ampcontent=None, attachments=None, settings=None, reply_to_id=None, @@ -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 @@ -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() @@ -110,6 +115,7 @@ def from_dictionary(cls, mfrom, subject, content, + ampcontent, attachments, settings, reply_to_id, diff --git a/pepipost/models/personalizations.py b/pepipost/models/personalizations.py index 285f8e2..107af5e 100644 --- a/pepipost/models/personalizations.py +++ b/pepipost/models/personalizations.py @@ -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 (list of string): TODO: type description here. """ @@ -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, @@ -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 @@ -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 @@ -79,6 +87,8 @@ 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, @@ -86,6 +96,8 @@ def from_dictionary(cls, x_apiheader, attributes, attachments, - recipient_cc) + recipient_cc, + recipient_bcc, + x_headers) From d7d58d24b311c68e1705335474563a728c4370ff Mon Sep 17 00:00:00 2001 From: Hiteshkumar Pandey Date: Thu, 10 Oct 2019 19:33:44 +0530 Subject: [PATCH 2/5] added new models | updated advadvanceUsage.md --- advanceUsage.md | 7 +++--- pepipost/models/attributes.py | 45 +++++++++++++++++++++++++++++++++++ pepipost/models/xheaders.py | 44 ++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 pepipost/models/attributes.py create mode 100644 pepipost/models/xheaders.py diff --git a/advanceUsage.md b/advanceUsage.md index d93f7e8..ee28141 100644 --- a/advanceUsage.md +++ b/advanceUsage.md @@ -10,7 +10,8 @@ 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.api_helper import APIHelper +from pepipost.models.attributes import Attributes +from pepipost.models.xheaders import Xheaders import jsonpickle client = PepipostClient() @@ -24,14 +25,14 @@ 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 = APIHelper.json_deserialize('{"name":"pepi","love":"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 = APIHelper.json_deserialize('{"custom_key1":"custom_value1","custom_key2":"custom_value2"}') +body.personalizations[0].x_headers = Xheaders('{"custom_key1":"custom_value1","custom_key2":"custom_value2"}').get_xheaders() body.tags = 'tagsPython' body.mfrom = From() diff --git a/pepipost/models/attributes.py b/pepipost/models/attributes.py new file mode 100644 index 0000000..4c255dd --- /dev/null +++ b/pepipost/models/attributes.py @@ -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) + + + + diff --git a/pepipost/models/xheaders.py b/pepipost/models/xheaders.py new file mode 100644 index 0000000..16848a4 --- /dev/null +++ b/pepipost/models/xheaders.py @@ -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) + + From 719fe1654314fca9c32cc0b06965767e1b798241 Mon Sep 17 00:00:00 2001 From: Hiteshkumar Pandey Date: Mon, 14 Oct 2019 14:24:55 +0530 Subject: [PATCH 3/5] updates --- pepipost/models/personalizations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pepipost/models/personalizations.py b/pepipost/models/personalizations.py index 107af5e..fe26ebe 100644 --- a/pepipost/models/personalizations.py +++ b/pepipost/models/personalizations.py @@ -21,7 +21,7 @@ class Personalizations(object): 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 (list of string): TODO: type description here. + x_headers (object): TODO: type description here. """ From 80406c237235804d31510b1c36230943d5b76f94 Mon Sep 17 00:00:00 2001 From: Hiteshkumar Pandey Date: Tue, 22 Oct 2019 18:19:28 +0530 Subject: [PATCH 4/5] added url endpoint option --- advanceUsage.md | 4 +++- pepipost/controllers/email_controller.py | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/advanceUsage.md b/advanceUsage.md index ee28141..d84f7b7 100644 --- a/advanceUsage.md +++ b/advanceUsage.md @@ -58,8 +58,10 @@ body.settings.bcc = 'my-email-bcc-id@domain.com' body.reply_to_id = 'replyto@gmail.com' body.template_id = 11344 +URL = "https://"; + try: - result = email_controller.create_send_email(api_key, body) + 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: diff --git a/pepipost/controllers/email_controller.py b/pepipost/controllers/email_controller.py index 1faa696..799f3be 100644 --- a/pepipost/controllers/email_controller.py +++ b/pepipost/controllers/email_controller.py @@ -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. @@ -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: + _query_builder = url + _query_url = APIHelper.clean_url(_query_builder) # Prepare headers From 925de916501ac3fbf1774f81f3d10a13b1f9ed18 Mon Sep 17 00:00:00 2001 From: Hiteshkumar Pandey Date: Tue, 12 Nov 2019 19:49:43 +0530 Subject: [PATCH 5/5] blank url verification --- pepipost/controllers/email_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pepipost/controllers/email_controller.py b/pepipost/controllers/email_controller.py index 799f3be..23fe1c3 100644 --- a/pepipost/controllers/email_controller.py +++ b/pepipost/controllers/email_controller.py @@ -46,7 +46,7 @@ def create_send_email(self, _query_builder += '/v2/sendEmail' # check if url is passed - if url!=None: + if url!=None and url.strip() != '': _query_builder = url _query_url = APIHelper.clean_url(_query_builder)