From 0a958777727a3e5b1d41c52c93da75cc87c18484 Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Wed, 22 Nov 2023 14:09:01 +0530 Subject: [PATCH] feat: geolocation setter in sendgrid-python for GDPR compliance --- examples/dataresidency/set_region.py | 23 +++-------------------- sendgrid/base_interface.py | 2 +- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/examples/dataresidency/set_region.py b/examples/dataresidency/set_region.py index aa3d6aa9..9a36248a 100644 --- a/examples/dataresidency/set_region.py +++ b/examples/dataresidency/set_region.py @@ -7,40 +7,23 @@ # setting region to be "global" sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY')) -sg.set_data_residency("global") from_email = Email("example@abc.com") to_email = To("example@abc.com") subject = "Sending with SendGrid is Fun" content = Content("text/plain", "and easy to do anywhere, even with Python") print(sg.client.host) mail = Mail(from_email, to_email, subject, content) +sg.set_sendgrid_data_residency("global") response = sg.client.mail.send.post(request_body=mail.get()) print(response) print(response.status_code) print(response.body) print(response.headers) - # Example 2 -# setting host -sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY')) -sg.set_host("https://api.eu.sendgrid.com") -from_email = Email("example@abc.com") -to_email = To("example@abc.com") -subject = "Sending with SendGrid is Fun" -content = Content("text/plain", "and easy to do anywhere, even with Python") -print(sg.client.host) -mail = Mail(from_email, to_email, subject, content) -response = sg.client.mail.send.post(request_body=mail.get()) -print(response) -print(response.status_code) -print(response.body) -print(response.headers) - -# Example 3 # setting region to "eu" -sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY')) -sg.set_data_residency("eu") +sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY_EU')) +sg.set_sendgrid_data_residency("eu") from_email = Email("example@abc.com") to_email = To("example@abc.com") subject = "Sending with SendGrid is Fun" diff --git a/sendgrid/base_interface.py b/sendgrid/base_interface.py index 0288cdfe..f94f0947 100644 --- a/sendgrid/base_interface.py +++ b/sendgrid/base_interface.py @@ -62,7 +62,7 @@ def send(self, message): return self.client.mail.send.post(request_body=message) - def set_data_residency(self, region): + def set_sendgrid_data_residency(self, region): """ Client libraries contain setters for specifying region/edge. This supports global and eu regions only. This set will likely expand in the future.