Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sendgrid/sendgrid-ruby in…
Browse files Browse the repository at this point in the history
…to patch-3
  • Loading branch information
rakvium committed Jul 13, 2016
2 parents ea755c0 + 50ab1bb commit 5dc56c9
Show file tree
Hide file tree
Showing 6 changed files with 317 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log
All notable changes to this project will be documented in this file.

## [3.0.6] - 2016-07-05 ##
### Added
- Update docs, unit tests and examples to include Sender ID

## [3.0.5] - 2016-07-05 ##
### Added
- Accept: application/json header per https://sendgrid.com/docs/API_Reference/Web_API_v3/How_To_Use_The_Web_API_v3/requests.html
Expand Down
138 changes: 137 additions & 1 deletion USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
* [MAILBOX PROVIDERS](#mailbox_providers)
* [PARTNER SETTINGS](#partner_settings)
* [SCOPES](#scopes)
* [SENDERS](#senders)
* [STATS](#stats)
* [SUBUSERS](#subusers)
* [SUPPRESSION](#suppression)
Expand Down Expand Up @@ -1469,7 +1470,7 @@ The contactdb is a database of your contacts for [SendGrid Marketing Campaigns](


```ruby
params = JSON.parse('{"%7Bfield_name%7D": "test_string", "{field_name}": "test_string"}')
params = JSON.parse('{"{field_name}": "test_string"}')
response = sg.client.contactdb.recipients.search.get(query_params: params)
puts response.status_code
puts response.body
Expand Down Expand Up @@ -2698,6 +2699,141 @@ puts response.status_code
puts response.body
puts response.headers
```
<a name="senders"></a>
# 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


```ruby
data = JSON.parse('{
"address": "123 Elm St.",
"address_2": "Apt. 456",
"city": "Denver",
"country": "United States",
"from": {
"email": "[email protected]",
"name": "Example INC"
},
"nickname": "My Sender ID",
"reply_to": {
"email": "[email protected]",
"name": "Example INC"
},
"state": "Colorado",
"zip": "80202"
}')
response = sg.client.senders.post(request_body: data)
puts response.status_code
puts response.body
puts 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


```ruby
response = sg.client.senders.get()
puts response.status_code
puts response.body
puts 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}


```ruby
data = JSON.parse('{
"address": "123 Elm St.",
"address_2": "Apt. 456",
"city": "Denver",
"country": "United States",
"from": {
"email": "[email protected]",
"name": "Example INC"
},
"nickname": "My Sender ID",
"reply_to": {
"email": "[email protected]",
"name": "Example INC"
},
"state": "Colorado",
"zip": "80202"
}')
sender_id = "test_url_param"
response = sg.client.senders._(sender_id).patch(request_body: data)
puts response.status_code
puts response.body
puts 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}


```ruby
sender_id = "test_url_param"
response = sg.client.senders._(sender_id).get()
puts response.status_code
puts response.body
puts 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}


```ruby
sender_id = "test_url_param"
response = sg.client.senders._(sender_id).delete()
puts response.status_code
puts response.body
puts 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


```ruby
sender_id = "test_url_param"
response = sg.client.senders._(sender_id).resend_verification.post()
puts response.status_code
puts response.body
puts response.headers
```
<a name="stats"></a>
# STATS

Expand Down
2 changes: 1 addition & 1 deletion examples/contactdb/contactdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
# Retrieve recipients matching search criteria #
# GET /contactdb/recipients/search #

params = JSON.parse('{"%7Bfield_name%7D": "test_string", "{field_name}": "test_string"}')
params = JSON.parse('{"{field_name}": "test_string"}')
response = sg.client.contactdb.recipients.search.get(query_params: params)
puts response.status_code
puts response.body
Expand Down
98 changes: 98 additions & 0 deletions examples/senders/senders.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
require 'sendgrid-ruby'


sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])


##################################################
# Create a Sender Identity #
# POST /senders #

data = JSON.parse('{
"address": "123 Elm St.",
"address_2": "Apt. 456",
"city": "Denver",
"country": "United States",
"from": {
"email": "[email protected]",
"name": "Example INC"
},
"nickname": "My Sender ID",
"reply_to": {
"email": "[email protected]",
"name": "Example INC"
},
"state": "Colorado",
"zip": "80202"
}')
response = sg.client.senders.post(request_body: data)
puts response.status_code
puts response.body
puts response.headers

##################################################
# Get all Sender Identities #
# GET /senders #

response = sg.client.senders.get()
puts response.status_code
puts response.body
puts response.headers

##################################################
# Update a Sender Identity #
# PATCH /senders/{sender_id} #

data = JSON.parse('{
"address": "123 Elm St.",
"address_2": "Apt. 456",
"city": "Denver",
"country": "United States",
"from": {
"email": "[email protected]",
"name": "Example INC"
},
"nickname": "My Sender ID",
"reply_to": {
"email": "[email protected]",
"name": "Example INC"
},
"state": "Colorado",
"zip": "80202"
}')
sender_id = "test_url_param"
response = sg.client.senders._(sender_id).patch(request_body: data)
puts response.status_code
puts response.body
puts response.headers

##################################################
# View a Sender Identity #
# GET /senders/{sender_id} #

sender_id = "test_url_param"
response = sg.client.senders._(sender_id).get()
puts response.status_code
puts response.body
puts response.headers

##################################################
# Delete a Sender Identity #
# DELETE /senders/{sender_id} #

sender_id = "test_url_param"
response = sg.client.senders._(sender_id).delete()
puts response.status_code
puts response.body
puts 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()
puts response.status_code
puts response.body
puts response.headers

2 changes: 1 addition & 1 deletion lib/sendgrid/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SendGrid
VERSION = '3.0.5'
VERSION = '3.0.6'
end
78 changes: 76 additions & 2 deletions test/sendgrid/test_sendgrid-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_init
')
assert_equal(test_headers, sg.request_headers)
assert_equal("v3", sg.version)
assert_equal("3.0.5", SendGrid::VERSION)
assert_equal("3.0.6", SendGrid::VERSION)
assert_instance_of(SendGrid::Client, sg.client)
end

Expand Down Expand Up @@ -659,7 +659,7 @@ def test_contactdb_recipients_count_get
end

def test_contactdb_recipients_search_get
params = JSON.parse('{"%7Bfield_name%7D": "test_string", "{field_name}": "test_string"}')
params = JSON.parse('{"{field_name}": "test_string"}')
headers = JSON.parse('{"X-Mock": 200}')
response = @sg.client.contactdb.recipients.search.get(query_params: params, request_headers: headers)
self.assert_equal(response.status_code, "200")
Expand Down Expand Up @@ -1242,6 +1242,80 @@ def test_scopes_get
self.assert_equal(response.status_code, "200")
end

def test_senders_post
data = JSON.parse('{
"address": "123 Elm St.",
"address_2": "Apt. 456",
"city": "Denver",
"country": "United States",
"from": {
"email": "[email protected]",
"name": "Example INC"
},
"nickname": "My Sender ID",
"reply_to": {
"email": "[email protected]",
"name": "Example INC"
},
"state": "Colorado",
"zip": "80202"
}')
headers = JSON.parse('{"X-Mock": 201}')
response = @sg.client.senders.post(request_body: data, request_headers: headers)
self.assert_equal(response.status_code, "201")
end

def test_senders_get
headers = JSON.parse('{"X-Mock": 200}')
response = @sg.client.senders.get(request_headers: headers)
self.assert_equal(response.status_code, "200")
end

def test_senders__sender_id__patch
data = JSON.parse('{
"address": "123 Elm St.",
"address_2": "Apt. 456",
"city": "Denver",
"country": "United States",
"from": {
"email": "[email protected]",
"name": "Example INC"
},
"nickname": "My Sender ID",
"reply_to": {
"email": "[email protected]",
"name": "Example INC"
},
"state": "Colorado",
"zip": "80202"
}')
sender_id = "test_url_param"
headers = JSON.parse('{"X-Mock": 200}')
response = @sg.client.senders._(sender_id).patch(request_body: data, request_headers: headers)
self.assert_equal(response.status_code, "200")
end

def test_senders__sender_id__get
sender_id = "test_url_param"
headers = JSON.parse('{"X-Mock": 200}')
response = @sg.client.senders._(sender_id).get(request_headers: headers)
self.assert_equal(response.status_code, "200")
end

def test_senders__sender_id__delete
sender_id = "test_url_param"
headers = JSON.parse('{"X-Mock": 204}')
response = @sg.client.senders._(sender_id).delete(request_headers: headers)
self.assert_equal(response.status_code, "204")
end

def test_senders__sender_id__resend_verification_post
sender_id = "test_url_param"
headers = JSON.parse('{"X-Mock": 204}')
response = @sg.client.senders._(sender_id).resend_verification.post(request_headers: headers)
self.assert_equal(response.status_code, "204")
end

def test_stats_get
params = JSON.parse('{"aggregated_by": "day", "limit": 1, "start_date": "2016-01-01", "end_date": "2016-04-01", "offset": 1}')
headers = JSON.parse('{"X-Mock": 200}')
Expand Down

0 comments on commit 5dc56c9

Please sign in to comment.