sendgrid-ruby 1.1.6 → 6.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.env_sample +1 -3
- data/.github/ISSUE_TEMPLATE/config.yml +10 -0
- data/.github/workflows/test-and-deploy.yml +120 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +5 -27
- data/.rubocop_todo.yml +127 -0
- data/CHANGELOG.md +417 -1
- data/CODE_OF_CONDUCT.md +73 -0
- data/CONTRIBUTING.md +202 -0
- data/Dockerfile +14 -0
- data/FIRST_TIMERS.md +79 -0
- data/Gemfile +4 -4
- data/ISSUE_TEMPLATE.md +30 -0
- data/LICENSE +21 -0
- data/Makefile +14 -0
- data/PULL_REQUEST_TEMPLATE.md +31 -0
- data/README.md +153 -229
- data/Rakefile +9 -3
- data/TROUBLESHOOTING.md +151 -0
- data/UPGRADE.md +5 -0
- data/USAGE.md +5144 -0
- data/config.ru +4 -0
- data/examples/accesssettings/accesssettings.rb +80 -0
- data/examples/alerts/alerts.rb +59 -0
- data/examples/apikeys/apikeys.rb +81 -0
- data/examples/asm/asm.rb +170 -0
- data/examples/browsers/browsers.rb +13 -0
- data/examples/campaigns/campaigns.rb +150 -0
- data/examples/categories/categories.rb +33 -0
- data/examples/clients/clients.rb +24 -0
- data/examples/contactdb/contactdb.rb +392 -0
- data/examples/devices/devices.rb +13 -0
- data/examples/emailactivity/emailactivity.rb +52 -0
- data/examples/geo/geo.rb +13 -0
- data/examples/helpers/eventwebhook/example.rb +16 -0
- data/examples/helpers/mail/example.rb +158 -0
- data/examples/helpers/settings/example.rb +23 -0
- data/examples/helpers/stats/example.rb +42 -0
- data/examples/ips/ips.rb +164 -0
- data/examples/mail/mail.rb +170 -0
- data/examples/mailboxproviders/mailboxproviders.rb +13 -0
- data/examples/mailsettings/mailsettings.rb +216 -0
- data/examples/partnersettings/partnersettings.rb +36 -0
- data/examples/scopes/scopes.rb +59 -0
- data/examples/senderauthentication/senderauthentication.rb +307 -0
- data/examples/senders/senders.rb +95 -0
- data/examples/stats/stats.rb +13 -0
- data/examples/subusers/subusers.rb +166 -0
- data/examples/suppression/suppression.rb +198 -0
- data/examples/templates/templates.rb +127 -0
- data/examples/trackingsettings/trackingsettings.rb +107 -0
- data/examples/user/user.rb +290 -0
- data/gemfiles/Sinatra_1.gemfile +6 -0
- data/gemfiles/Sinatra_2.gemfile +6 -0
- data/lib/rack/sendgrid_webhook_verification.rb +55 -0
- data/lib/sendgrid/base_interface.rb +40 -0
- data/lib/sendgrid/helpers/eventwebhook/eventwebhook.rb +50 -0
- data/lib/sendgrid/helpers/inbound/README.md +98 -0
- data/lib/sendgrid/helpers/inbound/app.rb +32 -0
- data/lib/sendgrid/helpers/inbound/config.yml +26 -0
- data/lib/sendgrid/helpers/inbound/public/index.html +10 -0
- data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +58 -0
- data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +57 -0
- data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +298 -0
- data/lib/sendgrid/helpers/inbound/send.rb +26 -0
- data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
- data/lib/sendgrid/helpers/mail/README.md +14 -0
- data/lib/sendgrid/helpers/mail/asm.rb +19 -0
- data/lib/sendgrid/helpers/mail/attachment.rb +55 -0
- data/lib/sendgrid/helpers/mail/bcc_settings.rb +19 -0
- data/lib/sendgrid/helpers/mail/bypass_list_management.rb +31 -0
- data/lib/sendgrid/helpers/mail/category.rb +18 -0
- data/lib/sendgrid/helpers/mail/click_tracking.rb +19 -0
- data/lib/sendgrid/helpers/mail/content.rb +19 -0
- data/lib/sendgrid/helpers/mail/custom_arg.rb +18 -0
- data/lib/sendgrid/helpers/mail/email.rb +32 -0
- data/lib/sendgrid/helpers/mail/footer.rb +21 -0
- data/lib/sendgrid/helpers/mail/ganalytics.rb +28 -0
- data/lib/sendgrid/helpers/mail/header.rb +18 -0
- data/lib/sendgrid/helpers/mail/mail.rb +122 -0
- data/lib/sendgrid/helpers/mail/mail_settings.rb +45 -0
- data/lib/sendgrid/helpers/mail/open_tracking.rb +19 -0
- data/lib/sendgrid/helpers/mail/personalization.rb +93 -0
- data/lib/sendgrid/helpers/mail/section.rb +18 -0
- data/lib/sendgrid/helpers/mail/spam_check.rb +21 -0
- data/lib/sendgrid/helpers/mail/subscription_tracking.rb +23 -0
- data/lib/sendgrid/helpers/mail/substitution.rb +18 -0
- data/lib/sendgrid/helpers/mail/tracking_settings.rb +39 -0
- data/lib/sendgrid/helpers/permissions/scope.rb +28 -0
- data/lib/sendgrid/helpers/permissions/scopes.yml +309 -0
- data/lib/sendgrid/helpers/settings/README.md +14 -0
- data/lib/sendgrid/helpers/settings/mail_settings_dto.rb +13 -0
- data/lib/sendgrid/helpers/settings/partner_settings_dto.rb +13 -0
- data/lib/sendgrid/helpers/settings/settings.rb +28 -0
- data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +22 -0
- data/lib/sendgrid/helpers/settings/user_settings_dto.rb +13 -0
- data/lib/sendgrid/helpers/stats/email_stats.rb +46 -0
- data/lib/sendgrid/helpers/stats/metrics.rb +33 -0
- data/lib/sendgrid/helpers/stats/stats_response.rb +29 -0
- data/lib/sendgrid/sendgrid.rb +21 -0
- data/lib/sendgrid/twilio_email.rb +21 -0
- data/lib/sendgrid/version.rb +1 -1
- data/lib/sendgrid-ruby.rb +32 -7
- data/mail_helper_v3.md +390 -0
- data/sendgrid-ruby.gemspec +16 -20
- data/spec/fixtures/event_webhook.rb +22 -0
- data/spec/rack/sendgrid_webhook_verification_spec.rb +142 -0
- data/spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb +105 -0
- data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
- data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +32 -0
- data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +24 -0
- data/spec/sendgrid/helpers/settings/settings_spec.rb +25 -0
- data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +27 -0
- data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +24 -0
- data/spec/sendgrid/helpers/stats/email_stats_spec.rb +111 -0
- data/spec/sendgrid/helpers/stats/metrics_spec.rb +45 -0
- data/spec/sendgrid/helpers/stats/stats_response_spec.rb +75 -0
- data/spec/sendgrid/sendgrid_spec.rb +11 -0
- data/spec/sendgrid/twilio_email_spec.rb +11 -0
- data/spec/spec_helper.rb +12 -1
- data/static/img/github-fork.png +0 -0
- data/static/img/github-sign-up.png +0 -0
- data/test/sendgrid/helpers/mail/test_attachment.rb +33 -0
- data/test/sendgrid/helpers/mail/test_category.rb +25 -0
- data/test/sendgrid/helpers/mail/test_email.rb +41 -0
- data/test/sendgrid/helpers/mail/test_mail.rb +260 -0
- data/test/sendgrid/helpers/mail/test_personalizations.rb +214 -0
- data/test/sendgrid/permissions/test_scopes.rb +36 -0
- data/test/sendgrid/test_sendgrid-ruby.rb +2729 -0
- data/twilio_sendgrid_logo.png +0 -0
- data/use-cases/README.md +17 -0
- data/use-cases/domain-authentication.md +5 -0
- data/use-cases/email-statistics.md +52 -0
- data/use-cases/legacy-templates.md +98 -0
- data/use-cases/personalizations.md +34 -0
- data/use-cases/sms.md +39 -0
- data/use-cases/transactional-templates.md +111 -0
- data/use-cases/twilio-email.md +13 -0
- data/use-cases/twilio-setup.md +54 -0
- metadata +187 -112
- data/.rspec +0 -2
- data/.travis.yml +0 -20
- data/FETCH_HEAD +0 -0
- data/Guardfile +0 -10
- data/LICENSE.txt +0 -22
- data/example.rb +0 -41
- data/lib/sendgrid/client.rb +0 -62
- data/lib/sendgrid/exceptions.rb +0 -7
- data/lib/sendgrid/mail.rb +0 -182
- data/lib/sendgrid/recipient.rb +0 -29
- data/lib/sendgrid/response.rb +0 -14
- data/lib/sendgrid/template.rb +0 -26
- data/lib/sendgrid/template_mailer.rb +0 -59
- data/spec/lib/sendgrid/client_spec.rb +0 -87
- data/spec/lib/sendgrid/mail_spec.rb +0 -151
- data/spec/lib/sendgrid/recipient_spec.rb +0 -91
- data/spec/lib/sendgrid/template_mailer_spec.rb +0 -86
- data/spec/lib/sendgrid/template_spec.rb +0 -61
- data/spec/lib/sendgrid_spec.rb +0 -7
data/config.ru
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
require 'sendgrid-ruby'
|
|
2
|
+
|
|
3
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
4
|
+
|
|
5
|
+
##################################################
|
|
6
|
+
# Retrieve all recent access attempts #
|
|
7
|
+
# GET /access_settings/activity #
|
|
8
|
+
|
|
9
|
+
params = JSON.parse('{"limit": 1}')
|
|
10
|
+
response = sg.client.access_settings.activity.get(query_params: params)
|
|
11
|
+
puts response.status_code
|
|
12
|
+
puts response.body
|
|
13
|
+
puts response.headers
|
|
14
|
+
|
|
15
|
+
##################################################
|
|
16
|
+
# Add one or more IPs to the whitelist #
|
|
17
|
+
# POST /access_settings/whitelist #
|
|
18
|
+
|
|
19
|
+
data = JSON.parse('{
|
|
20
|
+
"ips": [
|
|
21
|
+
{
|
|
22
|
+
"ip": "192.168.1.1"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"ip": "192.*.*.*"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"ip": "192.168.1.3/32"
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}')
|
|
32
|
+
response = sg.client.access_settings.whitelist.post(request_body: data)
|
|
33
|
+
puts response.status_code
|
|
34
|
+
puts response.body
|
|
35
|
+
puts response.headers
|
|
36
|
+
|
|
37
|
+
##################################################
|
|
38
|
+
# Retrieve a list of currently whitelisted IPs #
|
|
39
|
+
# GET /access_settings/whitelist #
|
|
40
|
+
|
|
41
|
+
response = sg.client.access_settings.whitelist.get
|
|
42
|
+
puts response.status_code
|
|
43
|
+
puts response.body
|
|
44
|
+
puts response.headers
|
|
45
|
+
|
|
46
|
+
##################################################
|
|
47
|
+
# Remove one or more IPs from the whitelist #
|
|
48
|
+
# DELETE /access_settings/whitelist #
|
|
49
|
+
|
|
50
|
+
data = JSON.parse('{
|
|
51
|
+
"ids": [
|
|
52
|
+
1,
|
|
53
|
+
2,
|
|
54
|
+
3
|
|
55
|
+
]
|
|
56
|
+
}')
|
|
57
|
+
response = sg.client.access_settings.whitelist.delete(request_body: data)
|
|
58
|
+
puts response.status_code
|
|
59
|
+
puts response.body
|
|
60
|
+
puts response.headers
|
|
61
|
+
|
|
62
|
+
##################################################
|
|
63
|
+
# Retrieve a specific whitelisted IP #
|
|
64
|
+
# GET /access_settings/whitelist/{rule_id} #
|
|
65
|
+
|
|
66
|
+
rule_id = 'test_url_param'
|
|
67
|
+
response = sg.client.access_settings.whitelist._(rule_id).get
|
|
68
|
+
puts response.status_code
|
|
69
|
+
puts response.body
|
|
70
|
+
puts response.headers
|
|
71
|
+
|
|
72
|
+
##################################################
|
|
73
|
+
# Remove a specific IP from the whitelist #
|
|
74
|
+
# DELETE /access_settings/whitelist/{rule_id} #
|
|
75
|
+
|
|
76
|
+
rule_id = 'test_url_param'
|
|
77
|
+
response = sg.client.access_settings.whitelist._(rule_id).delete
|
|
78
|
+
puts response.status_code
|
|
79
|
+
puts response.body
|
|
80
|
+
puts response.headers
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require 'sendgrid-ruby'
|
|
2
|
+
|
|
3
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
4
|
+
|
|
5
|
+
##################################################
|
|
6
|
+
# Create a new Alert #
|
|
7
|
+
# POST /alerts #
|
|
8
|
+
|
|
9
|
+
data = JSON.parse('{
|
|
10
|
+
"email_to": "example@example.com",
|
|
11
|
+
"frequency": "daily",
|
|
12
|
+
"type": "stats_notification"
|
|
13
|
+
}')
|
|
14
|
+
response = sg.client.alerts.post(request_body: data)
|
|
15
|
+
puts response.status_code
|
|
16
|
+
puts response.body
|
|
17
|
+
puts response.headers
|
|
18
|
+
|
|
19
|
+
##################################################
|
|
20
|
+
# Retrieve all alerts #
|
|
21
|
+
# GET /alerts #
|
|
22
|
+
|
|
23
|
+
response = sg.client.alerts.get
|
|
24
|
+
puts response.status_code
|
|
25
|
+
puts response.body
|
|
26
|
+
puts response.headers
|
|
27
|
+
|
|
28
|
+
##################################################
|
|
29
|
+
# Update an alert #
|
|
30
|
+
# PATCH /alerts/{alert_id} #
|
|
31
|
+
|
|
32
|
+
data = JSON.parse('{
|
|
33
|
+
"email_to": "example@example.com"
|
|
34
|
+
}')
|
|
35
|
+
alert_id = 'test_url_param'
|
|
36
|
+
response = sg.client.alerts._(alert_id).patch(request_body: data)
|
|
37
|
+
puts response.status_code
|
|
38
|
+
puts response.body
|
|
39
|
+
puts response.headers
|
|
40
|
+
|
|
41
|
+
##################################################
|
|
42
|
+
# Retrieve a specific alert #
|
|
43
|
+
# GET /alerts/{alert_id} #
|
|
44
|
+
|
|
45
|
+
alert_id = 'test_url_param'
|
|
46
|
+
response = sg.client.alerts._(alert_id).get
|
|
47
|
+
puts response.status_code
|
|
48
|
+
puts response.body
|
|
49
|
+
puts response.headers
|
|
50
|
+
|
|
51
|
+
##################################################
|
|
52
|
+
# Delete an alert #
|
|
53
|
+
# DELETE /alerts/{alert_id} #
|
|
54
|
+
|
|
55
|
+
alert_id = 'test_url_param'
|
|
56
|
+
response = sg.client.alerts._(alert_id).delete
|
|
57
|
+
puts response.status_code
|
|
58
|
+
puts response.body
|
|
59
|
+
puts response.headers
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
require 'sendgrid-ruby'
|
|
2
|
+
|
|
3
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
4
|
+
|
|
5
|
+
##################################################
|
|
6
|
+
# Create API keys #
|
|
7
|
+
# POST /api_keys #
|
|
8
|
+
|
|
9
|
+
data = JSON.parse('{
|
|
10
|
+
"name": "My API Key",
|
|
11
|
+
"sample": "data",
|
|
12
|
+
"scopes": [
|
|
13
|
+
"mail.send",
|
|
14
|
+
"alerts.create",
|
|
15
|
+
"alerts.read"
|
|
16
|
+
]
|
|
17
|
+
}')
|
|
18
|
+
response = sg.client.api_keys.post(request_body: data)
|
|
19
|
+
puts response.status_code
|
|
20
|
+
puts response.body
|
|
21
|
+
puts response.headers
|
|
22
|
+
|
|
23
|
+
##################################################
|
|
24
|
+
# Retrieve all API Keys belonging to the authenticated user #
|
|
25
|
+
# GET /api_keys #
|
|
26
|
+
|
|
27
|
+
params = JSON.parse('{"limit": 1}')
|
|
28
|
+
response = sg.client.api_keys.get(query_params: params)
|
|
29
|
+
puts response.status_code
|
|
30
|
+
puts response.body
|
|
31
|
+
puts response.headers
|
|
32
|
+
|
|
33
|
+
##################################################
|
|
34
|
+
# Update the name & scopes of an API Key #
|
|
35
|
+
# PUT /api_keys/{api_key_id} #
|
|
36
|
+
|
|
37
|
+
data = JSON.parse('{
|
|
38
|
+
"name": "A New Hope",
|
|
39
|
+
"scopes": [
|
|
40
|
+
"user.profile.read",
|
|
41
|
+
"user.profile.update"
|
|
42
|
+
]
|
|
43
|
+
}')
|
|
44
|
+
api_key_id = 'test_url_param'
|
|
45
|
+
response = sg.client.api_keys._(api_key_id).put(request_body: data)
|
|
46
|
+
puts response.status_code
|
|
47
|
+
puts response.body
|
|
48
|
+
puts response.headers
|
|
49
|
+
|
|
50
|
+
##################################################
|
|
51
|
+
# Update API keys #
|
|
52
|
+
# PATCH /api_keys/{api_key_id} #
|
|
53
|
+
|
|
54
|
+
data = JSON.parse('{
|
|
55
|
+
"name": "A New Hope"
|
|
56
|
+
}')
|
|
57
|
+
api_key_id = 'test_url_param'
|
|
58
|
+
response = sg.client.api_keys._(api_key_id).patch(request_body: data)
|
|
59
|
+
puts response.status_code
|
|
60
|
+
puts response.body
|
|
61
|
+
puts response.headers
|
|
62
|
+
|
|
63
|
+
##################################################
|
|
64
|
+
# Retrieve an existing API Key #
|
|
65
|
+
# GET /api_keys/{api_key_id} #
|
|
66
|
+
|
|
67
|
+
api_key_id = 'test_url_param'
|
|
68
|
+
response = sg.client.api_keys._(api_key_id).get
|
|
69
|
+
puts response.status_code
|
|
70
|
+
puts response.body
|
|
71
|
+
puts response.headers
|
|
72
|
+
|
|
73
|
+
##################################################
|
|
74
|
+
# Delete API keys #
|
|
75
|
+
# DELETE /api_keys/{api_key_id} #
|
|
76
|
+
|
|
77
|
+
api_key_id = 'test_url_param'
|
|
78
|
+
response = sg.client.api_keys._(api_key_id).delete
|
|
79
|
+
puts response.status_code
|
|
80
|
+
puts response.body
|
|
81
|
+
puts response.headers
|
data/examples/asm/asm.rb
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
require 'sendgrid-ruby'
|
|
2
|
+
|
|
3
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
4
|
+
|
|
5
|
+
##################################################
|
|
6
|
+
# Create a new suppression group #
|
|
7
|
+
# POST /asm/groups #
|
|
8
|
+
|
|
9
|
+
data = JSON.parse('{
|
|
10
|
+
"description": "Suggestions for products our users might like.",
|
|
11
|
+
"is_default": true,
|
|
12
|
+
"name": "Product Suggestions"
|
|
13
|
+
}')
|
|
14
|
+
response = sg.client.asm.groups.post(request_body: data)
|
|
15
|
+
puts response.status_code
|
|
16
|
+
puts response.body
|
|
17
|
+
puts response.headers
|
|
18
|
+
|
|
19
|
+
##################################################
|
|
20
|
+
# Retrieve information about multiple suppression groups #
|
|
21
|
+
# GET /asm/groups #
|
|
22
|
+
|
|
23
|
+
params = JSON.parse('{"id": 1}')
|
|
24
|
+
response = sg.client.asm.groups.get(query_params: params)
|
|
25
|
+
puts response.status_code
|
|
26
|
+
puts response.body
|
|
27
|
+
puts response.headers
|
|
28
|
+
|
|
29
|
+
##################################################
|
|
30
|
+
# Update a suppression group. #
|
|
31
|
+
# PATCH /asm/groups/{group_id} #
|
|
32
|
+
|
|
33
|
+
data = JSON.parse('{
|
|
34
|
+
"description": "Suggestions for items our users might like.",
|
|
35
|
+
"id": 103,
|
|
36
|
+
"name": "Item Suggestions"
|
|
37
|
+
}')
|
|
38
|
+
group_id = 'test_url_param'
|
|
39
|
+
response = sg.client.asm.groups._(group_id).patch(request_body: data)
|
|
40
|
+
puts response.status_code
|
|
41
|
+
puts response.body
|
|
42
|
+
puts response.headers
|
|
43
|
+
|
|
44
|
+
##################################################
|
|
45
|
+
# Get information on a single suppression group. #
|
|
46
|
+
# GET /asm/groups/{group_id} #
|
|
47
|
+
|
|
48
|
+
group_id = 'test_url_param'
|
|
49
|
+
response = sg.client.asm.groups._(group_id).get
|
|
50
|
+
puts response.status_code
|
|
51
|
+
puts response.body
|
|
52
|
+
puts response.headers
|
|
53
|
+
|
|
54
|
+
##################################################
|
|
55
|
+
# Delete a suppression group. #
|
|
56
|
+
# DELETE /asm/groups/{group_id} #
|
|
57
|
+
|
|
58
|
+
group_id = 'test_url_param'
|
|
59
|
+
response = sg.client.asm.groups._(group_id).delete
|
|
60
|
+
puts response.status_code
|
|
61
|
+
puts response.body
|
|
62
|
+
puts response.headers
|
|
63
|
+
|
|
64
|
+
##################################################
|
|
65
|
+
# Add suppressions to a suppression group #
|
|
66
|
+
# POST /asm/groups/{group_id}/suppressions #
|
|
67
|
+
|
|
68
|
+
data = JSON.parse('{
|
|
69
|
+
"recipient_emails": [
|
|
70
|
+
"test1@example.com",
|
|
71
|
+
"test2@example.com"
|
|
72
|
+
]
|
|
73
|
+
}')
|
|
74
|
+
group_id = 'test_url_param'
|
|
75
|
+
response = sg.client.asm.groups._(group_id).suppressions.post(request_body: data)
|
|
76
|
+
puts response.status_code
|
|
77
|
+
puts response.body
|
|
78
|
+
puts response.headers
|
|
79
|
+
|
|
80
|
+
##################################################
|
|
81
|
+
# Retrieve all suppressions for a suppression group #
|
|
82
|
+
# GET /asm/groups/{group_id}/suppressions #
|
|
83
|
+
|
|
84
|
+
group_id = 'test_url_param'
|
|
85
|
+
response = sg.client.asm.groups._(group_id).suppressions.get
|
|
86
|
+
puts response.status_code
|
|
87
|
+
puts response.body
|
|
88
|
+
puts response.headers
|
|
89
|
+
|
|
90
|
+
##################################################
|
|
91
|
+
# Search for suppressions within a group #
|
|
92
|
+
# POST /asm/groups/{group_id}/suppressions/search #
|
|
93
|
+
|
|
94
|
+
data = JSON.parse('{
|
|
95
|
+
"recipient_emails": [
|
|
96
|
+
"exists1@example.com",
|
|
97
|
+
"exists2@example.com",
|
|
98
|
+
"doesnotexists@example.com"
|
|
99
|
+
]
|
|
100
|
+
}')
|
|
101
|
+
group_id = 'test_url_param'
|
|
102
|
+
response = sg.client.asm.groups._(group_id).suppressions.search.post(request_body: data)
|
|
103
|
+
puts response.status_code
|
|
104
|
+
puts response.body
|
|
105
|
+
puts response.headers
|
|
106
|
+
|
|
107
|
+
##################################################
|
|
108
|
+
# Delete a suppression from a suppression group #
|
|
109
|
+
# DELETE /asm/groups/{group_id}/suppressions/{email} #
|
|
110
|
+
|
|
111
|
+
group_id = 'test_url_param'
|
|
112
|
+
email = 'test_url_param'
|
|
113
|
+
response = sg.client.asm.groups._(group_id).suppressions._(email).delete
|
|
114
|
+
puts response.status_code
|
|
115
|
+
puts response.body
|
|
116
|
+
puts response.headers
|
|
117
|
+
|
|
118
|
+
##################################################
|
|
119
|
+
# Retrieve all suppressions #
|
|
120
|
+
# GET /asm/suppressions #
|
|
121
|
+
|
|
122
|
+
response = sg.client.asm.suppressions.get
|
|
123
|
+
puts response.status_code
|
|
124
|
+
puts response.body
|
|
125
|
+
puts response.headers
|
|
126
|
+
|
|
127
|
+
##################################################
|
|
128
|
+
# Add recipient addresses to the global suppression group. #
|
|
129
|
+
# POST /asm/suppressions/global #
|
|
130
|
+
|
|
131
|
+
data = JSON.parse('{
|
|
132
|
+
"recipient_emails": [
|
|
133
|
+
"test1@example.com",
|
|
134
|
+
"test2@example.com"
|
|
135
|
+
]
|
|
136
|
+
}')
|
|
137
|
+
response = sg.client.asm.suppressions.global.post(request_body: data)
|
|
138
|
+
puts response.status_code
|
|
139
|
+
puts response.body
|
|
140
|
+
puts response.headers
|
|
141
|
+
|
|
142
|
+
##################################################
|
|
143
|
+
# Retrieve a Global Suppression #
|
|
144
|
+
# GET /asm/suppressions/global/{email} #
|
|
145
|
+
|
|
146
|
+
email = 'test_url_param'
|
|
147
|
+
response = sg.client.asm.suppressions.global._(email).get
|
|
148
|
+
puts response.status_code
|
|
149
|
+
puts response.body
|
|
150
|
+
puts response.headers
|
|
151
|
+
|
|
152
|
+
##################################################
|
|
153
|
+
# Delete a Global Suppression #
|
|
154
|
+
# DELETE /asm/suppressions/global/{email} #
|
|
155
|
+
|
|
156
|
+
email = 'test_url_param'
|
|
157
|
+
response = sg.client.asm.suppressions.global._(email).delete
|
|
158
|
+
puts response.status_code
|
|
159
|
+
puts response.body
|
|
160
|
+
puts response.headers
|
|
161
|
+
|
|
162
|
+
##################################################
|
|
163
|
+
# Retrieve all suppression groups for an email address #
|
|
164
|
+
# GET /asm/suppressions/{email} #
|
|
165
|
+
|
|
166
|
+
email = 'test_url_param'
|
|
167
|
+
response = sg.client.asm.suppressions._(email).get
|
|
168
|
+
puts response.status_code
|
|
169
|
+
puts response.body
|
|
170
|
+
puts response.headers
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'sendgrid-ruby'
|
|
2
|
+
|
|
3
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
4
|
+
|
|
5
|
+
##################################################
|
|
6
|
+
# Retrieve email statistics by browser. #
|
|
7
|
+
# GET /browsers/stats #
|
|
8
|
+
|
|
9
|
+
params = JSON.parse('{"end_date": "2016-04-01", "aggregated_by": "day", "browsers": "test_string", "limit": "test_string", "offset": "test_string", "start_date": "2016-01-01"}')
|
|
10
|
+
response = sg.client.browsers.stats.get(query_params: params)
|
|
11
|
+
puts response.status_code
|
|
12
|
+
puts response.body
|
|
13
|
+
puts response.headers
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
require 'sendgrid-ruby'
|
|
2
|
+
|
|
3
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
4
|
+
|
|
5
|
+
##################################################
|
|
6
|
+
# Create a Campaign #
|
|
7
|
+
# POST /campaigns #
|
|
8
|
+
|
|
9
|
+
data = JSON.parse('{
|
|
10
|
+
"categories": [
|
|
11
|
+
"spring line"
|
|
12
|
+
],
|
|
13
|
+
"custom_unsubscribe_url": "",
|
|
14
|
+
"html_content": "<html><head><title></title></head><body><p>Check out our spring line!</p></body></html>",
|
|
15
|
+
"ip_pool": "marketing",
|
|
16
|
+
"list_ids": [
|
|
17
|
+
110,
|
|
18
|
+
124
|
|
19
|
+
],
|
|
20
|
+
"plain_content": "Check out our spring line!",
|
|
21
|
+
"segment_ids": [
|
|
22
|
+
110
|
|
23
|
+
],
|
|
24
|
+
"sender_id": 124451,
|
|
25
|
+
"subject": "New Products for Spring!",
|
|
26
|
+
"suppression_group_id": 42,
|
|
27
|
+
"title": "March Newsletter"
|
|
28
|
+
}')
|
|
29
|
+
response = sg.client.campaigns.post(request_body: data)
|
|
30
|
+
puts response.status_code
|
|
31
|
+
puts response.body
|
|
32
|
+
puts response.headers
|
|
33
|
+
|
|
34
|
+
##################################################
|
|
35
|
+
# Retrieve all Campaigns #
|
|
36
|
+
# GET /campaigns #
|
|
37
|
+
|
|
38
|
+
params = JSON.parse('{"limit": 1, "offset": 1}')
|
|
39
|
+
response = sg.client.campaigns.get(query_params: params)
|
|
40
|
+
puts response.status_code
|
|
41
|
+
puts response.body
|
|
42
|
+
puts response.headers
|
|
43
|
+
|
|
44
|
+
##################################################
|
|
45
|
+
# Update a Campaign #
|
|
46
|
+
# PATCH /campaigns/{campaign_id} #
|
|
47
|
+
|
|
48
|
+
data = JSON.parse('{
|
|
49
|
+
"categories": [
|
|
50
|
+
"summer line"
|
|
51
|
+
],
|
|
52
|
+
"html_content": "<html><head><title></title></head><body><p>Check out our summer line!</p></body></html>",
|
|
53
|
+
"plain_content": "Check out our summer line!",
|
|
54
|
+
"subject": "New Products for Summer!",
|
|
55
|
+
"title": "May Newsletter"
|
|
56
|
+
}')
|
|
57
|
+
campaign_id = 'test_url_param'
|
|
58
|
+
response = sg.client.campaigns._(campaign_id).patch(request_body: data)
|
|
59
|
+
puts response.status_code
|
|
60
|
+
puts response.body
|
|
61
|
+
puts response.headers
|
|
62
|
+
|
|
63
|
+
##################################################
|
|
64
|
+
# Retrieve a single campaign #
|
|
65
|
+
# GET /campaigns/{campaign_id} #
|
|
66
|
+
|
|
67
|
+
campaign_id = 'test_url_param'
|
|
68
|
+
response = sg.client.campaigns._(campaign_id).get
|
|
69
|
+
puts response.status_code
|
|
70
|
+
puts response.body
|
|
71
|
+
puts response.headers
|
|
72
|
+
|
|
73
|
+
##################################################
|
|
74
|
+
# Delete a Campaign #
|
|
75
|
+
# DELETE /campaigns/{campaign_id} #
|
|
76
|
+
|
|
77
|
+
campaign_id = 'test_url_param'
|
|
78
|
+
response = sg.client.campaigns._(campaign_id).delete
|
|
79
|
+
puts response.status_code
|
|
80
|
+
puts response.body
|
|
81
|
+
puts response.headers
|
|
82
|
+
|
|
83
|
+
##################################################
|
|
84
|
+
# Update a Scheduled Campaign #
|
|
85
|
+
# PATCH /campaigns/{campaign_id}/schedules #
|
|
86
|
+
|
|
87
|
+
data = JSON.parse('{
|
|
88
|
+
"send_at": 1489451436
|
|
89
|
+
}')
|
|
90
|
+
campaign_id = 'test_url_param'
|
|
91
|
+
response = sg.client.campaigns._(campaign_id).schedules.patch(request_body: data)
|
|
92
|
+
puts response.status_code
|
|
93
|
+
puts response.body
|
|
94
|
+
puts response.headers
|
|
95
|
+
|
|
96
|
+
##################################################
|
|
97
|
+
# Schedule a Campaign #
|
|
98
|
+
# POST /campaigns/{campaign_id}/schedules #
|
|
99
|
+
|
|
100
|
+
data = JSON.parse('{
|
|
101
|
+
"send_at": 1489771528
|
|
102
|
+
}')
|
|
103
|
+
campaign_id = 'test_url_param'
|
|
104
|
+
response = sg.client.campaigns._(campaign_id).schedules.post(request_body: data)
|
|
105
|
+
puts response.status_code
|
|
106
|
+
puts response.body
|
|
107
|
+
puts response.headers
|
|
108
|
+
|
|
109
|
+
##################################################
|
|
110
|
+
# View Scheduled Time of a Campaign #
|
|
111
|
+
# GET /campaigns/{campaign_id}/schedules #
|
|
112
|
+
|
|
113
|
+
campaign_id = 'test_url_param'
|
|
114
|
+
response = sg.client.campaigns._(campaign_id).schedules.get
|
|
115
|
+
puts response.status_code
|
|
116
|
+
puts response.body
|
|
117
|
+
puts response.headers
|
|
118
|
+
|
|
119
|
+
##################################################
|
|
120
|
+
# Unschedule a Scheduled Campaign #
|
|
121
|
+
# DELETE /campaigns/{campaign_id}/schedules #
|
|
122
|
+
|
|
123
|
+
campaign_id = 'test_url_param'
|
|
124
|
+
response = sg.client.campaigns._(campaign_id).schedules.delete
|
|
125
|
+
puts response.status_code
|
|
126
|
+
puts response.body
|
|
127
|
+
puts response.headers
|
|
128
|
+
|
|
129
|
+
##################################################
|
|
130
|
+
# Send a Campaign #
|
|
131
|
+
# POST /campaigns/{campaign_id}/schedules/now #
|
|
132
|
+
|
|
133
|
+
campaign_id = 'test_url_param'
|
|
134
|
+
response = sg.client.campaigns._(campaign_id).schedules.now.post
|
|
135
|
+
puts response.status_code
|
|
136
|
+
puts response.body
|
|
137
|
+
puts response.headers
|
|
138
|
+
|
|
139
|
+
##################################################
|
|
140
|
+
# Send a Test Campaign #
|
|
141
|
+
# POST /campaigns/{campaign_id}/schedules/test #
|
|
142
|
+
|
|
143
|
+
data = JSON.parse('{
|
|
144
|
+
"to": "your.email@example.com"
|
|
145
|
+
}')
|
|
146
|
+
campaign_id = 'test_url_param'
|
|
147
|
+
response = sg.client.campaigns._(campaign_id).schedules.test.post(request_body: data)
|
|
148
|
+
puts response.status_code
|
|
149
|
+
puts response.body
|
|
150
|
+
puts response.headers
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'sendgrid-ruby'
|
|
2
|
+
|
|
3
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
4
|
+
|
|
5
|
+
##################################################
|
|
6
|
+
# Retrieve all categories #
|
|
7
|
+
# GET /categories #
|
|
8
|
+
|
|
9
|
+
params = JSON.parse('{"category": "test_string", "limit": 1, "offset": 1}')
|
|
10
|
+
response = sg.client.categories.get(query_params: params)
|
|
11
|
+
puts response.status_code
|
|
12
|
+
puts response.body
|
|
13
|
+
puts response.headers
|
|
14
|
+
|
|
15
|
+
##################################################
|
|
16
|
+
# Retrieve Email Statistics for Categories #
|
|
17
|
+
# GET /categories/stats #
|
|
18
|
+
|
|
19
|
+
params = JSON.parse('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01", "categories": "test_string"}')
|
|
20
|
+
response = sg.client.categories.stats.get(query_params: params)
|
|
21
|
+
puts response.status_code
|
|
22
|
+
puts response.body
|
|
23
|
+
puts response.headers
|
|
24
|
+
|
|
25
|
+
##################################################
|
|
26
|
+
# Retrieve sums of email stats for each category [Needs: Stats object defined, has category ID?] #
|
|
27
|
+
# GET /categories/stats/sums #
|
|
28
|
+
|
|
29
|
+
params = JSON.parse('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "sort_by_metric": "test_string", "offset": 1, "start_date": "2016-01-01", "sort_by_direction": "asc"}')
|
|
30
|
+
response = sg.client.categories.stats.sums.get(query_params: params)
|
|
31
|
+
puts response.status_code
|
|
32
|
+
puts response.body
|
|
33
|
+
puts response.headers
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'sendgrid-ruby'
|
|
2
|
+
|
|
3
|
+
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
4
|
+
|
|
5
|
+
##################################################
|
|
6
|
+
# Retrieve email statistics by client type. #
|
|
7
|
+
# GET /clients/stats #
|
|
8
|
+
|
|
9
|
+
params = JSON.parse('{"aggregated_by": "day", "start_date": "2016-01-01", "end_date": "2016-04-01"}')
|
|
10
|
+
response = sg.client.clients.stats.get(query_params: params)
|
|
11
|
+
puts response.status_code
|
|
12
|
+
puts response.body
|
|
13
|
+
puts response.headers
|
|
14
|
+
|
|
15
|
+
##################################################
|
|
16
|
+
# Retrieve stats by a specific client type. #
|
|
17
|
+
# GET /clients/{client_type}/stats #
|
|
18
|
+
|
|
19
|
+
params = JSON.parse('{"aggregated_by": "day", "start_date": "2016-01-01", "end_date": "2016-04-01"}')
|
|
20
|
+
client_type = 'test_url_param'
|
|
21
|
+
response = sg.client.clients._(client_type).stats.get(query_params: params)
|
|
22
|
+
puts response.status_code
|
|
23
|
+
puts response.body
|
|
24
|
+
puts response.headers
|