diff --git a/CHANGELOG.md b/CHANGELOG.md index 12f3af2ac..0da44773e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Change Log All notable changes to this project will be documented in this file. +## [3.0.6] - 2016-07-12 ## +### Added +- Update docs, unit tests and examples to include Sender ID + ## [3.0.5] - 2016-07-11 ## ### Fixed - Fixed logic errors related to issue #189 diff --git a/USAGE.md b/USAGE.md index a9423c486..013a48e92 100644 --- a/USAGE.md +++ b/USAGE.md @@ -29,6 +29,7 @@ sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) * [MAILBOX PROVIDERS](#mailbox_providers) * [PARTNER SETTINGS](#partner_settings) * [SCOPES](#scopes) +* [SENDERS](#senders) * [STATS](#stats) * [SUBUSERS](#subusers) * [SUPPRESSION](#suppression) @@ -1487,7 +1488,7 @@ The contactdb is a database of your contacts for [SendGrid Marketing Campaigns]( ```python -params = {'%7Bfield_name%7D': 'test_string', '{field_name}': 'test_string'} +params = {'{field_name}': 'test_string'} response = sg.client.contactdb.recipients.search.get(query_params=params) print response.status_code print response.body @@ -2716,6 +2717,141 @@ print response.status_code print response.body print response.headers ``` + +# SENDERS + +## Create a Sender Identity + +**This endpoint allows you to create a new sender identity.** + +*You may create up to 100 unique sender identities.* + +Sender Identities are required to be verified before use. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`. + +### POST /senders + + +```python +data = { + "address": "123 Elm St.", + "address_2": "Apt. 456", + "city": "Denver", + "country": "United States", + "from": { + "email": "from@example.com", + "name": "Example INC" + }, + "nickname": "My Sender ID", + "reply_to": { + "email": "replyto@example.com", + "name": "Example INC" + }, + "state": "Colorado", + "zip": "80202" +} +response = sg.client.senders.post(request_body=data) +print response.status_code +print response.body +print response.headers +``` +## Get all Sender Identities + +**This endpoint allows you to retrieve a list of all sender identities that have been created for your account.** + +Sender Identities are required to be verified before use. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`. + +### GET /senders + + +```python +response = sg.client.senders.get() +print response.status_code +print response.body +print response.headers +``` +## Update a Sender Identity + +**This endpoint allows you to update a sender identity.** + +Updates to `from.email` require re-verification. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`. + +Partial updates are allowed, but fields that are marked as "required" in the POST (create) endpoint must not be nil if that field is included in the PATCH request. + +### PATCH /senders/{sender_id} + + +```python +data = { + "address": "123 Elm St.", + "address_2": "Apt. 456", + "city": "Denver", + "country": "United States", + "from": { + "email": "from@example.com", + "name": "Example INC" + }, + "nickname": "My Sender ID", + "reply_to": { + "email": "replyto@example.com", + "name": "Example INC" + }, + "state": "Colorado", + "zip": "80202" +} +sender_id = "test_url_param" +response = sg.client.senders._(sender_id).patch(request_body=data) +print response.status_code +print response.body +print response.headers +``` +## View a Sender Identity + +**This endpoint allows you to retrieve a specific sender identity.** + +Sender Identities are required to be verified before use. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`. + +### GET /senders/{sender_id} + + +```python +sender_id = "test_url_param" +response = sg.client.senders._(sender_id).get() +print response.status_code +print response.body +print response.headers +``` +## Delete a Sender Identity + +**This endoint allows you to delete one of your sender identities.** + +Sender Identities are required to be verified before use. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`. + +### DELETE /senders/{sender_id} + + +```python +sender_id = "test_url_param" +response = sg.client.senders._(sender_id).delete() +print response.status_code +print response.body +print response.headers +``` +## Resend Sender Identity Verification + +**This enpdoint allows you to resend a sender identity verification email.** + +Sender Identities are required to be verified before use. If your domain has been whitelabeled it will auto verify on creation. Otherwise an email will be sent to the `from.email`. + +### POST /senders/{sender_id}/resend_verification + + +```python +sender_id = "test_url_param" +response = sg.client.senders._(sender_id).resend_verification.post() +print response.status_code +print response.body +print response.headers +``` # STATS diff --git a/examples/contactdb/contactdb.py b/examples/contactdb/contactdb.py index 07e8daa65..59b5b2e42 100644 --- a/examples/contactdb/contactdb.py +++ b/examples/contactdb/contactdb.py @@ -251,7 +251,7 @@ # Retrieve recipients matching search criteria # # GET /contactdb/recipients/search # -params = {'%7Bfield_name%7D': 'test_string', '{field_name}': 'test_string'} +params = {'{field_name}': 'test_string'} response = sg.client.contactdb.recipients.search.get(query_params=params) print(response.status_code) print(response.body) diff --git a/examples/senders/senders.py b/examples/senders/senders.py new file mode 100644 index 000000000..f21459b71 --- /dev/null +++ b/examples/senders/senders.py @@ -0,0 +1,99 @@ +import sendgrid +import json +import os + + +sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) + +################################################## +# Create a Sender Identity # +# POST /senders # + +data = { + "address": "123 Elm St.", + "address_2": "Apt. 456", + "city": "Denver", + "country": "United States", + "from": { + "email": "from@example.com", + "name": "Example INC" + }, + "nickname": "My Sender ID", + "reply_to": { + "email": "replyto@example.com", + "name": "Example INC" + }, + "state": "Colorado", + "zip": "80202" +} +response = sg.client.senders.post(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Get all Sender Identities # +# GET /senders # + +response = sg.client.senders.get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Update a Sender Identity # +# PATCH /senders/{sender_id} # + +data = { + "address": "123 Elm St.", + "address_2": "Apt. 456", + "city": "Denver", + "country": "United States", + "from": { + "email": "from@example.com", + "name": "Example INC" + }, + "nickname": "My Sender ID", + "reply_to": { + "email": "replyto@example.com", + "name": "Example INC" + }, + "state": "Colorado", + "zip": "80202" +} +sender_id = "test_url_param" +response = sg.client.senders._(sender_id).patch(request_body=data) +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# View a Sender Identity # +# GET /senders/{sender_id} # + +sender_id = "test_url_param" +response = sg.client.senders._(sender_id).get() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Delete a Sender Identity # +# DELETE /senders/{sender_id} # + +sender_id = "test_url_param" +response = sg.client.senders._(sender_id).delete() +print(response.status_code) +print(response.body) +print(response.headers) + +################################################## +# Resend Sender Identity Verification # +# POST /senders/{sender_id}/resend_verification # + +sender_id = "test_url_param" +response = sg.client.senders._(sender_id).resend_verification.post() +print(response.status_code) +print(response.body) +print(response.headers) + diff --git a/examples/user/user.py b/examples/user/user.py index fa3da7401..9e3f24766 100644 --- a/examples/user/user.py +++ b/examples/user/user.py @@ -248,36 +248,36 @@ print(response.headers) ################################################## -# Retrieve a specific parse setting # -# GET /user/webhooks/parse/settings/{hostname} # +# Update a parse setting # +# PATCH /user/webhooks/parse/settings/{hostname} # +data = { + "send_raw": True, + "spam_check": False, + "url": "http://newdomain.com/parse" +} hostname = "test_url_param" -response = sg.client.user.webhooks.parse.settings._(hostname).get() +response = sg.client.user.webhooks.parse.settings._(hostname).patch(request_body=data) print(response.status_code) print(response.body) print(response.headers) ################################################## -# Delete a parse setting # -# DELETE /user/webhooks/parse/settings/{hostname} # +# Retrieve a specific parse setting # +# GET /user/webhooks/parse/settings/{hostname} # hostname = "test_url_param" -response = sg.client.user.webhooks.parse.settings._(hostname).delete() +response = sg.client.user.webhooks.parse.settings._(hostname).get() print(response.status_code) print(response.body) print(response.headers) ################################################## -# Update a parse setting # -# PATCH /user/webhooks/parse/settings/{hostname}/ # +# Delete a parse setting # +# DELETE /user/webhooks/parse/settings/{hostname} # -data = { - "send_raw": True, - "spam_check": False, - "url": "http://newdomain.com/parse" -} hostname = "test_url_param" -response = sg.client.user.webhooks.parse.settings._(hostname)..patch(request_body=data) +response = sg.client.user.webhooks.parse.settings._(hostname).delete() print(response.status_code) print(response.body) print(response.headers) diff --git a/sendgrid/version.py b/sendgrid/version.py index 88f89375c..7a00043df 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1,2 +1,2 @@ -version_info = (3, 0, 5) +version_info = (3, 0, 6) __version__ = '.'.join(str(v) for v in version_info) diff --git a/test/test_sendgrid.py b/test/test_sendgrid.py index e822794a3..d9f7774f2 100644 --- a/test/test_sendgrid.py +++ b/test/test_sendgrid.py @@ -603,7 +603,7 @@ def test_contactdb_recipients_count_get(self): self.assertEqual(response.status_code, 200) def test_contactdb_recipients_search_get(self): - params = {'%7Bfield_name%7D': 'test_string', '{field_name}': 'test_string'} + params = {'{field_name}': 'test_string'} headers = {'X-Mock': 200} response = self.sg.client.contactdb.recipients.search.get(query_params=params, request_headers=headers) self.assertEqual(response.status_code, 200) @@ -1132,6 +1132,74 @@ def test_scopes_get(self): response = self.sg.client.scopes.get(request_headers=headers) self.assertEqual(response.status_code, 200) + def test_senders_post(self): + data = { + "address": "123 Elm St.", + "address_2": "Apt. 456", + "city": "Denver", + "country": "United States", + "from": { + "email": "from@example.com", + "name": "Example INC" + }, + "nickname": "My Sender ID", + "reply_to": { + "email": "replyto@example.com", + "name": "Example INC" + }, + "state": "Colorado", + "zip": "80202" +} + headers = {'X-Mock': 201} + response = self.sg.client.senders.post(request_body=data, request_headers=headers) + self.assertEqual(response.status_code, 201) + + def test_senders_get(self): + headers = {'X-Mock': 200} + response = self.sg.client.senders.get(request_headers=headers) + self.assertEqual(response.status_code, 200) + + def test_senders__sender_id__patch(self): + data = { + "address": "123 Elm St.", + "address_2": "Apt. 456", + "city": "Denver", + "country": "United States", + "from": { + "email": "from@example.com", + "name": "Example INC" + }, + "nickname": "My Sender ID", + "reply_to": { + "email": "replyto@example.com", + "name": "Example INC" + }, + "state": "Colorado", + "zip": "80202" +} + sender_id = "test_url_param" + headers = {'X-Mock': 200} + response = self.sg.client.senders._(sender_id).patch(request_body=data, request_headers=headers) + self.assertEqual(response.status_code, 200) + + def test_senders__sender_id__get(self): + sender_id = "test_url_param" + headers = {'X-Mock': 200} + response = self.sg.client.senders._(sender_id).get(request_headers=headers) + self.assertEqual(response.status_code, 200) + + def test_senders__sender_id__delete(self): + sender_id = "test_url_param" + headers = {'X-Mock': 204} + response = self.sg.client.senders._(sender_id).delete(request_headers=headers) + self.assertEqual(response.status_code, 204) + + def test_senders__sender_id__resend_verification_post(self): + sender_id = "test_url_param" + headers = {'X-Mock': 204} + response = self.sg.client.senders._(sender_id).resend_verification.post(request_headers=headers) + self.assertEqual(response.status_code, 204) + def test_stats_get(self): params = {'aggregated_by': 'day', 'limit': 1, 'start_date': '2016-01-01', 'end_date': '2016-04-01', 'offset': 1} headers = {'X-Mock': 200}