sendgrid-ruby 6.2.1 → 6.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -1
- data/.gitignore +1 -1
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +109 -0
- data/.travis.yml +3 -4
- data/CHANGELOG.md +69 -9
- data/CONTRIBUTING.md +11 -21
- data/FIRST_TIMERS.md +79 -0
- data/Gemfile +0 -1
- data/ISSUE_TEMPLATE.md +5 -1
- data/Makefile +4 -2
- data/PULL_REQUEST_TEMPLATE.md +1 -1
- data/README.md +22 -27
- data/Rakefile +2 -3
- data/TROUBLESHOOTING.md +5 -5
- data/USAGE.md +145 -38
- data/examples/accesssettings/accesssettings.rb +9 -12
- data/examples/alerts/alerts.rb +8 -11
- data/examples/apikeys/apikeys.rb +12 -15
- data/examples/asm/asm.rb +27 -30
- data/examples/browsers/browsers.rb +0 -3
- data/examples/campaigns/campaigns.rb +29 -32
- data/examples/categories/categories.rb +0 -3
- data/examples/clients/clients.rb +1 -4
- data/examples/contactdb/contactdb.rb +63 -66
- data/examples/devices/devices.rb +0 -3
- data/examples/emailactivity/emailactivity.rb +52 -0
- data/examples/geo/geo.rb +0 -3
- data/examples/helpers/eventwebhook/example.rb +16 -0
- data/examples/helpers/mail/example.rb +19 -13
- data/examples/helpers/settings/example.rb +1 -1
- data/examples/helpers/stats/example.rb +4 -4
- data/examples/ips/ips.rb +19 -22
- data/examples/mail/mail.rb +72 -75
- data/examples/mailboxproviders/mailboxproviders.rb +0 -3
- data/examples/mailsettings/mailsettings.rb +21 -24
- data/examples/partnersettings/partnersettings.rb +3 -6
- data/examples/scopes/scopes.rb +7 -9
- data/examples/senderauthentication/senderauthentication.rb +41 -44
- data/examples/senders/senders.rb +28 -31
- data/examples/stats/stats.rb +0 -3
- data/examples/subusers/subusers.rb +17 -20
- data/examples/suppression/suppression.rb +15 -18
- data/examples/templates/templates.rb +29 -31
- data/examples/trackingsettings/trackingsettings.rb +14 -17
- data/examples/user/user.rb +41 -44
- data/lib/rack/sendgrid_webhook_verification.rb +53 -0
- data/lib/sendgrid-ruby.rb +2 -0
- data/lib/sendgrid/base_interface.rb +1 -1
- data/lib/sendgrid/helpers/eventwebhook/eventwebhook.rb +50 -0
- data/lib/sendgrid/helpers/inbound/README.md +5 -5
- data/lib/sendgrid/helpers/inbound/app.rb +1 -1
- data/lib/sendgrid/helpers/inbound/public/index.html +1 -1
- data/lib/sendgrid/helpers/inbound/send.rb +2 -2
- data/lib/sendgrid/helpers/ip_management/ip_management.rb +1 -1
- data/lib/sendgrid/helpers/mail/README.md +3 -3
- data/lib/sendgrid/helpers/mail/asm.rb +6 -18
- data/lib/sendgrid/helpers/mail/attachment.rb +12 -42
- data/lib/sendgrid/helpers/mail/bcc_settings.rb +6 -18
- data/lib/sendgrid/helpers/mail/bypass_list_management.rb +8 -18
- data/lib/sendgrid/helpers/mail/category.rb +2 -2
- data/lib/sendgrid/helpers/mail/click_tracking.rb +6 -18
- data/lib/sendgrid/helpers/mail/content.rb +4 -3
- data/lib/sendgrid/helpers/mail/custom_arg.rb +6 -10
- data/lib/sendgrid/helpers/mail/email.rb +5 -4
- data/lib/sendgrid/helpers/mail/footer.rb +7 -27
- data/lib/sendgrid/helpers/mail/ganalytics.rb +10 -54
- data/lib/sendgrid/helpers/mail/header.rb +6 -10
- data/lib/sendgrid/helpers/mail/mail.rb +30 -48
- data/lib/sendgrid/helpers/mail/mail_settings.rb +9 -25
- data/lib/sendgrid/helpers/mail/open_tracking.rb +6 -18
- data/lib/sendgrid/helpers/mail/personalization.rb +34 -27
- data/lib/sendgrid/helpers/mail/section.rb +6 -10
- data/lib/sendgrid/helpers/mail/spam_check.rb +7 -27
- data/lib/sendgrid/helpers/mail/subscription_tracking.rb +8 -36
- data/lib/sendgrid/helpers/mail/substitution.rb +6 -10
- data/lib/sendgrid/helpers/mail/tracking_settings.rb +7 -20
- data/lib/sendgrid/helpers/permissions/scope.rb +1 -1
- data/lib/sendgrid/helpers/settings/README.md +2 -2
- data/lib/sendgrid/helpers/settings/settings.rb +1 -1
- data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +3 -5
- data/lib/sendgrid/helpers/stats/metrics.rb +5 -5
- data/lib/sendgrid/sendgrid.rb +1 -1
- data/lib/sendgrid/twilio_email.rb +1 -1
- data/lib/sendgrid/version.rb +1 -1
- data/mail_helper_v3.md +12 -12
- data/sendgrid-ruby.gemspec +8 -7
- data/spec/fixtures/event_webhook.rb +22 -0
- data/spec/rack/sendgrid_webhook_verification_spec.rb +116 -0
- data/spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb +105 -0
- data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +1 -1
- data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +1 -1
- data/spec/sendgrid/helpers/settings/settings_spec.rb +2 -2
- data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +1 -1
- data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +1 -1
- data/spec/sendgrid/helpers/stats/email_stats_spec.rb +22 -23
- data/spec/sendgrid/helpers/stats/metrics_spec.rb +19 -20
- data/spec/sendgrid/helpers/stats/stats_response_spec.rb +22 -23
- data/spec/spec_helper.rb +3 -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 +4 -6
- data/test/sendgrid/helpers/mail/test_category.rb +0 -2
- data/test/sendgrid/helpers/mail/test_email.rb +9 -11
- data/test/sendgrid/helpers/mail/test_mail.rb +101 -102
- data/test/sendgrid/helpers/mail/test_personalizations.rb +106 -93
- data/test/sendgrid/permissions/test_scopes.rb +0 -2
- data/test/sendgrid/test_sendgrid-ruby.rb +1948 -1958
- data/twilio_sendgrid_logo.png +0 -0
- data/use-cases/README.md +16 -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/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 +73 -24
- data/USE_CASES.md +0 -405
- data/docker/Dockerfile +0 -12
- data/docker/README.md +0 -30
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'sendgrid-ruby'
|
2
2
|
|
3
|
-
|
4
3
|
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
5
4
|
|
6
|
-
|
7
5
|
##################################################
|
8
6
|
# Retrieve all recent access attempts #
|
9
7
|
# GET /access_settings/activity #
|
@@ -22,10 +20,10 @@ data = JSON.parse('{
|
|
22
20
|
"ips": [
|
23
21
|
{
|
24
22
|
"ip": "192.168.1.1"
|
25
|
-
},
|
23
|
+
},
|
26
24
|
{
|
27
25
|
"ip": "192.*.*.*"
|
28
|
-
},
|
26
|
+
},
|
29
27
|
{
|
30
28
|
"ip": "192.168.1.3/32"
|
31
29
|
}
|
@@ -40,7 +38,7 @@ puts response.headers
|
|
40
38
|
# Retrieve a list of currently whitelisted IPs #
|
41
39
|
# GET /access_settings/whitelist #
|
42
40
|
|
43
|
-
response = sg.client.access_settings.whitelist.get
|
41
|
+
response = sg.client.access_settings.whitelist.get
|
44
42
|
puts response.status_code
|
45
43
|
puts response.body
|
46
44
|
puts response.headers
|
@@ -51,8 +49,8 @@ puts response.headers
|
|
51
49
|
|
52
50
|
data = JSON.parse('{
|
53
51
|
"ids": [
|
54
|
-
1,
|
55
|
-
2,
|
52
|
+
1,
|
53
|
+
2,
|
56
54
|
3
|
57
55
|
]
|
58
56
|
}')
|
@@ -65,8 +63,8 @@ puts response.headers
|
|
65
63
|
# Retrieve a specific whitelisted IP #
|
66
64
|
# GET /access_settings/whitelist/{rule_id} #
|
67
65
|
|
68
|
-
rule_id =
|
69
|
-
response = sg.client.access_settings.whitelist._(rule_id).get
|
66
|
+
rule_id = 'test_url_param'
|
67
|
+
response = sg.client.access_settings.whitelist._(rule_id).get
|
70
68
|
puts response.status_code
|
71
69
|
puts response.body
|
72
70
|
puts response.headers
|
@@ -75,9 +73,8 @@ puts response.headers
|
|
75
73
|
# Remove a specific IP from the whitelist #
|
76
74
|
# DELETE /access_settings/whitelist/{rule_id} #
|
77
75
|
|
78
|
-
rule_id =
|
79
|
-
response = sg.client.access_settings.whitelist._(rule_id).delete
|
76
|
+
rule_id = 'test_url_param'
|
77
|
+
response = sg.client.access_settings.whitelist._(rule_id).delete
|
80
78
|
puts response.status_code
|
81
79
|
puts response.body
|
82
80
|
puts response.headers
|
83
|
-
|
data/examples/alerts/alerts.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
require 'sendgrid-ruby'
|
2
2
|
|
3
|
-
|
4
3
|
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
5
4
|
|
6
|
-
|
7
5
|
##################################################
|
8
6
|
# Create a new Alert #
|
9
7
|
# POST /alerts #
|
10
8
|
|
11
9
|
data = JSON.parse('{
|
12
|
-
"email_to": "example@example.com",
|
13
|
-
"frequency": "daily",
|
10
|
+
"email_to": "example@example.com",
|
11
|
+
"frequency": "daily",
|
14
12
|
"type": "stats_notification"
|
15
13
|
}')
|
16
14
|
response = sg.client.alerts.post(request_body: data)
|
@@ -22,7 +20,7 @@ puts response.headers
|
|
22
20
|
# Retrieve all alerts #
|
23
21
|
# GET /alerts #
|
24
22
|
|
25
|
-
response = sg.client.alerts.get
|
23
|
+
response = sg.client.alerts.get
|
26
24
|
puts response.status_code
|
27
25
|
puts response.body
|
28
26
|
puts response.headers
|
@@ -34,7 +32,7 @@ puts response.headers
|
|
34
32
|
data = JSON.parse('{
|
35
33
|
"email_to": "example@example.com"
|
36
34
|
}')
|
37
|
-
alert_id =
|
35
|
+
alert_id = 'test_url_param'
|
38
36
|
response = sg.client.alerts._(alert_id).patch(request_body: data)
|
39
37
|
puts response.status_code
|
40
38
|
puts response.body
|
@@ -44,8 +42,8 @@ puts response.headers
|
|
44
42
|
# Retrieve a specific alert #
|
45
43
|
# GET /alerts/{alert_id} #
|
46
44
|
|
47
|
-
alert_id =
|
48
|
-
response = sg.client.alerts._(alert_id).get
|
45
|
+
alert_id = 'test_url_param'
|
46
|
+
response = sg.client.alerts._(alert_id).get
|
49
47
|
puts response.status_code
|
50
48
|
puts response.body
|
51
49
|
puts response.headers
|
@@ -54,9 +52,8 @@ puts response.headers
|
|
54
52
|
# Delete an alert #
|
55
53
|
# DELETE /alerts/{alert_id} #
|
56
54
|
|
57
|
-
alert_id =
|
58
|
-
response = sg.client.alerts._(alert_id).delete
|
55
|
+
alert_id = 'test_url_param'
|
56
|
+
response = sg.client.alerts._(alert_id).delete
|
59
57
|
puts response.status_code
|
60
58
|
puts response.body
|
61
59
|
puts response.headers
|
62
|
-
|
data/examples/apikeys/apikeys.rb
CHANGED
@@ -1,19 +1,17 @@
|
|
1
1
|
require 'sendgrid-ruby'
|
2
2
|
|
3
|
-
|
4
3
|
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
5
4
|
|
6
|
-
|
7
5
|
##################################################
|
8
6
|
# Create API keys #
|
9
7
|
# POST /api_keys #
|
10
8
|
|
11
9
|
data = JSON.parse('{
|
12
|
-
"name": "My API Key",
|
13
|
-
"sample": "data",
|
10
|
+
"name": "My API Key",
|
11
|
+
"sample": "data",
|
14
12
|
"scopes": [
|
15
|
-
"mail.send",
|
16
|
-
"alerts.create",
|
13
|
+
"mail.send",
|
14
|
+
"alerts.create",
|
17
15
|
"alerts.read"
|
18
16
|
]
|
19
17
|
}')
|
@@ -37,13 +35,13 @@ puts response.headers
|
|
37
35
|
# PUT /api_keys/{api_key_id} #
|
38
36
|
|
39
37
|
data = JSON.parse('{
|
40
|
-
"name": "A New Hope",
|
38
|
+
"name": "A New Hope",
|
41
39
|
"scopes": [
|
42
|
-
"user.profile.read",
|
40
|
+
"user.profile.read",
|
43
41
|
"user.profile.update"
|
44
42
|
]
|
45
43
|
}')
|
46
|
-
api_key_id =
|
44
|
+
api_key_id = 'test_url_param'
|
47
45
|
response = sg.client.api_keys._(api_key_id).put(request_body: data)
|
48
46
|
puts response.status_code
|
49
47
|
puts response.body
|
@@ -56,7 +54,7 @@ puts response.headers
|
|
56
54
|
data = JSON.parse('{
|
57
55
|
"name": "A New Hope"
|
58
56
|
}')
|
59
|
-
api_key_id =
|
57
|
+
api_key_id = 'test_url_param'
|
60
58
|
response = sg.client.api_keys._(api_key_id).patch(request_body: data)
|
61
59
|
puts response.status_code
|
62
60
|
puts response.body
|
@@ -66,8 +64,8 @@ puts response.headers
|
|
66
64
|
# Retrieve an existing API Key #
|
67
65
|
# GET /api_keys/{api_key_id} #
|
68
66
|
|
69
|
-
api_key_id =
|
70
|
-
response = sg.client.api_keys._(api_key_id).get
|
67
|
+
api_key_id = 'test_url_param'
|
68
|
+
response = sg.client.api_keys._(api_key_id).get
|
71
69
|
puts response.status_code
|
72
70
|
puts response.body
|
73
71
|
puts response.headers
|
@@ -76,9 +74,8 @@ puts response.headers
|
|
76
74
|
# Delete API keys #
|
77
75
|
# DELETE /api_keys/{api_key_id} #
|
78
76
|
|
79
|
-
api_key_id =
|
80
|
-
response = sg.client.api_keys._(api_key_id).delete
|
77
|
+
api_key_id = 'test_url_param'
|
78
|
+
response = sg.client.api_keys._(api_key_id).delete
|
81
79
|
puts response.status_code
|
82
80
|
puts response.body
|
83
81
|
puts response.headers
|
84
|
-
|
data/examples/asm/asm.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
require 'sendgrid-ruby'
|
2
2
|
|
3
|
-
|
4
3
|
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
5
4
|
|
6
|
-
|
7
5
|
##################################################
|
8
6
|
# Create a new suppression group #
|
9
7
|
# POST /asm/groups #
|
10
8
|
|
11
9
|
data = JSON.parse('{
|
12
|
-
"description": "Suggestions for products our users might like.",
|
13
|
-
"is_default": true,
|
10
|
+
"description": "Suggestions for products our users might like.",
|
11
|
+
"is_default": true,
|
14
12
|
"name": "Product Suggestions"
|
15
13
|
}')
|
16
14
|
response = sg.client.asm.groups.post(request_body: data)
|
@@ -33,11 +31,11 @@ puts response.headers
|
|
33
31
|
# PATCH /asm/groups/{group_id} #
|
34
32
|
|
35
33
|
data = JSON.parse('{
|
36
|
-
"description": "Suggestions for items our users might like.",
|
37
|
-
"id": 103,
|
34
|
+
"description": "Suggestions for items our users might like.",
|
35
|
+
"id": 103,
|
38
36
|
"name": "Item Suggestions"
|
39
37
|
}')
|
40
|
-
group_id =
|
38
|
+
group_id = 'test_url_param'
|
41
39
|
response = sg.client.asm.groups._(group_id).patch(request_body: data)
|
42
40
|
puts response.status_code
|
43
41
|
puts response.body
|
@@ -47,8 +45,8 @@ puts response.headers
|
|
47
45
|
# Get information on a single suppression group. #
|
48
46
|
# GET /asm/groups/{group_id} #
|
49
47
|
|
50
|
-
group_id =
|
51
|
-
response = sg.client.asm.groups._(group_id).get
|
48
|
+
group_id = 'test_url_param'
|
49
|
+
response = sg.client.asm.groups._(group_id).get
|
52
50
|
puts response.status_code
|
53
51
|
puts response.body
|
54
52
|
puts response.headers
|
@@ -57,8 +55,8 @@ puts response.headers
|
|
57
55
|
# Delete a suppression group. #
|
58
56
|
# DELETE /asm/groups/{group_id} #
|
59
57
|
|
60
|
-
group_id =
|
61
|
-
response = sg.client.asm.groups._(group_id).delete
|
58
|
+
group_id = 'test_url_param'
|
59
|
+
response = sg.client.asm.groups._(group_id).delete
|
62
60
|
puts response.status_code
|
63
61
|
puts response.body
|
64
62
|
puts response.headers
|
@@ -69,11 +67,11 @@ puts response.headers
|
|
69
67
|
|
70
68
|
data = JSON.parse('{
|
71
69
|
"recipient_emails": [
|
72
|
-
"test1@example.com",
|
70
|
+
"test1@example.com",
|
73
71
|
"test2@example.com"
|
74
72
|
]
|
75
73
|
}')
|
76
|
-
group_id =
|
74
|
+
group_id = 'test_url_param'
|
77
75
|
response = sg.client.asm.groups._(group_id).suppressions.post(request_body: data)
|
78
76
|
puts response.status_code
|
79
77
|
puts response.body
|
@@ -83,8 +81,8 @@ puts response.headers
|
|
83
81
|
# Retrieve all suppressions for a suppression group #
|
84
82
|
# GET /asm/groups/{group_id}/suppressions #
|
85
83
|
|
86
|
-
group_id =
|
87
|
-
response = sg.client.asm.groups._(group_id).suppressions.get
|
84
|
+
group_id = 'test_url_param'
|
85
|
+
response = sg.client.asm.groups._(group_id).suppressions.get
|
88
86
|
puts response.status_code
|
89
87
|
puts response.body
|
90
88
|
puts response.headers
|
@@ -95,12 +93,12 @@ puts response.headers
|
|
95
93
|
|
96
94
|
data = JSON.parse('{
|
97
95
|
"recipient_emails": [
|
98
|
-
"exists1@example.com",
|
99
|
-
"exists2@example.com",
|
96
|
+
"exists1@example.com",
|
97
|
+
"exists2@example.com",
|
100
98
|
"doesnotexists@example.com"
|
101
99
|
]
|
102
100
|
}')
|
103
|
-
group_id =
|
101
|
+
group_id = 'test_url_param'
|
104
102
|
response = sg.client.asm.groups._(group_id).suppressions.search.post(request_body: data)
|
105
103
|
puts response.status_code
|
106
104
|
puts response.body
|
@@ -110,9 +108,9 @@ puts response.headers
|
|
110
108
|
# Delete a suppression from a suppression group #
|
111
109
|
# DELETE /asm/groups/{group_id}/suppressions/{email} #
|
112
110
|
|
113
|
-
group_id =
|
114
|
-
email =
|
115
|
-
response = sg.client.asm.groups._(group_id).suppressions._(email).delete
|
111
|
+
group_id = 'test_url_param'
|
112
|
+
email = 'test_url_param'
|
113
|
+
response = sg.client.asm.groups._(group_id).suppressions._(email).delete
|
116
114
|
puts response.status_code
|
117
115
|
puts response.body
|
118
116
|
puts response.headers
|
@@ -121,7 +119,7 @@ puts response.headers
|
|
121
119
|
# Retrieve all suppressions #
|
122
120
|
# GET /asm/suppressions #
|
123
121
|
|
124
|
-
response = sg.client.asm.suppressions.get
|
122
|
+
response = sg.client.asm.suppressions.get
|
125
123
|
puts response.status_code
|
126
124
|
puts response.body
|
127
125
|
puts response.headers
|
@@ -132,7 +130,7 @@ puts response.headers
|
|
132
130
|
|
133
131
|
data = JSON.parse('{
|
134
132
|
"recipient_emails": [
|
135
|
-
"test1@example.com",
|
133
|
+
"test1@example.com",
|
136
134
|
"test2@example.com"
|
137
135
|
]
|
138
136
|
}')
|
@@ -145,8 +143,8 @@ puts response.headers
|
|
145
143
|
# Retrieve a Global Suppression #
|
146
144
|
# GET /asm/suppressions/global/{email} #
|
147
145
|
|
148
|
-
email =
|
149
|
-
response = sg.client.asm.suppressions.global._(email).get
|
146
|
+
email = 'test_url_param'
|
147
|
+
response = sg.client.asm.suppressions.global._(email).get
|
150
148
|
puts response.status_code
|
151
149
|
puts response.body
|
152
150
|
puts response.headers
|
@@ -155,8 +153,8 @@ puts response.headers
|
|
155
153
|
# Delete a Global Suppression #
|
156
154
|
# DELETE /asm/suppressions/global/{email} #
|
157
155
|
|
158
|
-
email =
|
159
|
-
response = sg.client.asm.suppressions.global._(email).delete
|
156
|
+
email = 'test_url_param'
|
157
|
+
response = sg.client.asm.suppressions.global._(email).delete
|
160
158
|
puts response.status_code
|
161
159
|
puts response.body
|
162
160
|
puts response.headers
|
@@ -165,9 +163,8 @@ puts response.headers
|
|
165
163
|
# Retrieve all suppression groups for an email address #
|
166
164
|
# GET /asm/suppressions/{email} #
|
167
165
|
|
168
|
-
email =
|
169
|
-
response = sg.client.asm.suppressions._(email).get
|
166
|
+
email = 'test_url_param'
|
167
|
+
response = sg.client.asm.suppressions._(email).get
|
170
168
|
puts response.status_code
|
171
169
|
puts response.body
|
172
170
|
puts response.headers
|
173
|
-
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'sendgrid-ruby'
|
2
2
|
|
3
|
-
|
4
3
|
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
5
4
|
|
6
|
-
|
7
5
|
##################################################
|
8
6
|
# Retrieve email statistics by browser. #
|
9
7
|
# GET /browsers/stats #
|
@@ -13,4 +11,3 @@ response = sg.client.browsers.stats.get(query_params: params)
|
|
13
11
|
puts response.status_code
|
14
12
|
puts response.body
|
15
13
|
puts response.headers
|
16
|
-
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'sendgrid-ruby'
|
2
2
|
|
3
|
-
|
4
3
|
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
5
4
|
|
6
|
-
|
7
5
|
##################################################
|
8
6
|
# Create a Campaign #
|
9
7
|
# POST /campaigns #
|
@@ -11,21 +9,21 @@ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
|
|
11
9
|
data = JSON.parse('{
|
12
10
|
"categories": [
|
13
11
|
"spring line"
|
14
|
-
],
|
15
|
-
"custom_unsubscribe_url": "",
|
16
|
-
"html_content": "<html><head><title></title></head><body><p>Check out our spring line!</p></body></html>",
|
17
|
-
"ip_pool": "marketing",
|
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",
|
18
16
|
"list_ids": [
|
19
|
-
110,
|
17
|
+
110,
|
20
18
|
124
|
21
|
-
],
|
22
|
-
"plain_content": "Check out our spring line!",
|
19
|
+
],
|
20
|
+
"plain_content": "Check out our spring line!",
|
23
21
|
"segment_ids": [
|
24
22
|
110
|
25
|
-
],
|
26
|
-
"sender_id": 124451,
|
27
|
-
"subject": "New Products for Spring!",
|
28
|
-
"suppression_group_id": 42,
|
23
|
+
],
|
24
|
+
"sender_id": 124451,
|
25
|
+
"subject": "New Products for Spring!",
|
26
|
+
"suppression_group_id": 42,
|
29
27
|
"title": "March Newsletter"
|
30
28
|
}')
|
31
29
|
response = sg.client.campaigns.post(request_body: data)
|
@@ -50,13 +48,13 @@ puts response.headers
|
|
50
48
|
data = JSON.parse('{
|
51
49
|
"categories": [
|
52
50
|
"summer line"
|
53
|
-
],
|
54
|
-
"html_content": "<html><head><title></title></head><body><p>Check out our summer line!</p></body></html>",
|
55
|
-
"plain_content": "Check out our summer line!",
|
56
|
-
"subject": "New Products for Summer!",
|
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!",
|
57
55
|
"title": "May Newsletter"
|
58
56
|
}')
|
59
|
-
campaign_id =
|
57
|
+
campaign_id = 'test_url_param'
|
60
58
|
response = sg.client.campaigns._(campaign_id).patch(request_body: data)
|
61
59
|
puts response.status_code
|
62
60
|
puts response.body
|
@@ -66,8 +64,8 @@ puts response.headers
|
|
66
64
|
# Retrieve a single campaign #
|
67
65
|
# GET /campaigns/{campaign_id} #
|
68
66
|
|
69
|
-
campaign_id =
|
70
|
-
response = sg.client.campaigns._(campaign_id).get
|
67
|
+
campaign_id = 'test_url_param'
|
68
|
+
response = sg.client.campaigns._(campaign_id).get
|
71
69
|
puts response.status_code
|
72
70
|
puts response.body
|
73
71
|
puts response.headers
|
@@ -76,8 +74,8 @@ puts response.headers
|
|
76
74
|
# Delete a Campaign #
|
77
75
|
# DELETE /campaigns/{campaign_id} #
|
78
76
|
|
79
|
-
campaign_id =
|
80
|
-
response = sg.client.campaigns._(campaign_id).delete
|
77
|
+
campaign_id = 'test_url_param'
|
78
|
+
response = sg.client.campaigns._(campaign_id).delete
|
81
79
|
puts response.status_code
|
82
80
|
puts response.body
|
83
81
|
puts response.headers
|
@@ -89,7 +87,7 @@ puts response.headers
|
|
89
87
|
data = JSON.parse('{
|
90
88
|
"send_at": 1489451436
|
91
89
|
}')
|
92
|
-
campaign_id =
|
90
|
+
campaign_id = 'test_url_param'
|
93
91
|
response = sg.client.campaigns._(campaign_id).schedules.patch(request_body: data)
|
94
92
|
puts response.status_code
|
95
93
|
puts response.body
|
@@ -102,7 +100,7 @@ puts response.headers
|
|
102
100
|
data = JSON.parse('{
|
103
101
|
"send_at": 1489771528
|
104
102
|
}')
|
105
|
-
campaign_id =
|
103
|
+
campaign_id = 'test_url_param'
|
106
104
|
response = sg.client.campaigns._(campaign_id).schedules.post(request_body: data)
|
107
105
|
puts response.status_code
|
108
106
|
puts response.body
|
@@ -112,8 +110,8 @@ puts response.headers
|
|
112
110
|
# View Scheduled Time of a Campaign #
|
113
111
|
# GET /campaigns/{campaign_id}/schedules #
|
114
112
|
|
115
|
-
campaign_id =
|
116
|
-
response = sg.client.campaigns._(campaign_id).schedules.get
|
113
|
+
campaign_id = 'test_url_param'
|
114
|
+
response = sg.client.campaigns._(campaign_id).schedules.get
|
117
115
|
puts response.status_code
|
118
116
|
puts response.body
|
119
117
|
puts response.headers
|
@@ -122,8 +120,8 @@ puts response.headers
|
|
122
120
|
# Unschedule a Scheduled Campaign #
|
123
121
|
# DELETE /campaigns/{campaign_id}/schedules #
|
124
122
|
|
125
|
-
campaign_id =
|
126
|
-
response = sg.client.campaigns._(campaign_id).schedules.delete
|
123
|
+
campaign_id = 'test_url_param'
|
124
|
+
response = sg.client.campaigns._(campaign_id).schedules.delete
|
127
125
|
puts response.status_code
|
128
126
|
puts response.body
|
129
127
|
puts response.headers
|
@@ -132,8 +130,8 @@ puts response.headers
|
|
132
130
|
# Send a Campaign #
|
133
131
|
# POST /campaigns/{campaign_id}/schedules/now #
|
134
132
|
|
135
|
-
campaign_id =
|
136
|
-
response = sg.client.campaigns._(campaign_id).schedules.now.post
|
133
|
+
campaign_id = 'test_url_param'
|
134
|
+
response = sg.client.campaigns._(campaign_id).schedules.now.post
|
137
135
|
puts response.status_code
|
138
136
|
puts response.body
|
139
137
|
puts response.headers
|
@@ -145,9 +143,8 @@ puts response.headers
|
|
145
143
|
data = JSON.parse('{
|
146
144
|
"to": "your.email@example.com"
|
147
145
|
}')
|
148
|
-
campaign_id =
|
146
|
+
campaign_id = 'test_url_param'
|
149
147
|
response = sg.client.campaigns._(campaign_id).schedules.test.post(request_body: data)
|
150
148
|
puts response.status_code
|
151
149
|
puts response.body
|
152
150
|
puts response.headers
|
153
|
-
|