-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding examples for the new marketing campaigns
- Loading branch information
Showing
4 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'sendgrid-ruby' | ||
|
||
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) | ||
|
||
################################################## | ||
# Add or Update a Contact # | ||
# POST /marketing/contacts # | ||
|
||
data = JSON.parse('{ | ||
"list_ids": [ | ||
"ca7a3796-e8a8-4029-9ccb-df8937940562" | ||
], | ||
"contacts": [ | ||
{ | ||
"address_line_1": "123 Elm St.", | ||
"address_line_2": "Apt. 456", | ||
"city": "Denver", | ||
"country": "United States", | ||
"email": "[email protected]", | ||
"first_name": "User", | ||
"last_name": "Example" | ||
} | ||
] | ||
}') | ||
|
||
response = sg.client.marketing.contacts.put(request_body: data) | ||
puts response.status_code | ||
puts response.body | ||
puts response.headers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'sendgrid-ruby' | ||
|
||
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) | ||
|
||
################################################## | ||
# Create Custom Field Definition # | ||
# POST /marketing/field_definitions # | ||
|
||
data = JSON.parse('{ | ||
"name": "pet", | ||
"field_type": "Text" | ||
}') | ||
|
||
response = sg.client.marketing.field_definitions.post(request_body: data) | ||
puts response.status_code | ||
puts response.body | ||
puts response.headers | ||
|
||
################################################## | ||
# Get All Field Definitions # | ||
# GET /marketing/field_definitions # | ||
|
||
response = sg.client.marketing.field_definitions.get | ||
puts response.status_code | ||
puts response.body | ||
puts response.headers | ||
|
||
################################################## | ||
# Update Custom Field Definition # | ||
# PATCH /marketing/field_definitions/{custom_field_id} # | ||
|
||
data = JSON.parse('{ | ||
"name": "new_custom_field_name" | ||
}') | ||
custom_field_id = 'e1_T' | ||
response = sg.client.marketing.field_definitions._(custom_field_id).patch(request_body: data) | ||
puts response.status_code | ||
puts response.body | ||
puts response.headers | ||
|
||
################################################## | ||
# Delete Custom Field Definition # | ||
# DELETE /marketing/field_definitions/{custom_field_id} # | ||
|
||
custom_field_id = 'e1_T' | ||
response = sg.client.marketing.field_definitions._(custom_field_id).delete | ||
puts response.status_code | ||
puts response.body | ||
puts response.headers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'sendgrid-ruby' | ||
|
||
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) | ||
|
||
################################################## | ||
# Create List # | ||
# GET /marketing/lists # | ||
|
||
data = JSON.parse('{ | ||
"name": "list-name" | ||
}') | ||
|
||
response = sg.client.marketing.lists.post(request_body: data) | ||
puts response.status_code | ||
puts response.body | ||
puts response.headers | ||
|
||
################################################## | ||
# Get All Lists # | ||
# GET /marketing/lists # | ||
|
||
response = sg.client.marketing.lists.get | ||
puts response.status_code | ||
puts response.body | ||
puts response.headers | ||
|
||
################################################## | ||
# Get a List by ID # | ||
# GET /marketing/lists/{id} # | ||
|
||
list_id = 'ca7a3796-e8a8-4029-9ccb-df8937940562' | ||
response = sg.client.marketing.lists._(list_id).get | ||
puts response.status_code | ||
puts response.body | ||
puts response.headers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'sendgrid-ruby' | ||
|
||
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) | ||
|
||
################################################## | ||
# Create Single Send # | ||
# POST /marketing/singlesends # | ||
|
||
data = JSON.parse('{ | ||
"name": "Example API Created Single Send", | ||
"categories": [ | ||
"unique opens" | ||
], | ||
"send_to": { | ||
"all": true | ||
}, | ||
"email_config": { | ||
"design_id": "<your-design-id>", | ||
"editor": "design", | ||
"suppression_group_id": 12, | ||
"sender_id": 10 | ||
} | ||
}') | ||
|
||
response = sg.client.marketing.singlesends.post(request_body: data) | ||
puts response.status_code | ||
puts response.body | ||
puts response.headers |