sendgrid-ruby 6.3.4 → 6.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -5
- data/.rubocop_todo.yml +109 -0
- data/.travis.yml +1 -2
- data/CHANGELOG.md +43 -1
- data/CONTRIBUTING.md +2 -5
- data/FIRST_TIMERS.md +7 -7
- data/{LICENSE.md → LICENSE} +1 -1
- data/Makefile +1 -0
- data/PULL_REQUEST_TEMPLATE.md +4 -4
- data/README.md +3 -9
- data/Rakefile +2 -3
- data/USAGE.md +111 -3
- 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 +4 -4
- data/examples/helpers/mail/example.rb +9 -10
- 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 +8 -10
- 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 +5 -2
- data/lib/sendgrid/base_interface.rb +2 -1
- data/lib/sendgrid/helpers/eventwebhook/eventwebhook.rb +4 -6
- data/lib/sendgrid/helpers/inbound/app.rb +2 -2
- data/lib/sendgrid/helpers/inbound/send.rb +3 -3
- data/lib/sendgrid/helpers/ip_management/ip_management.rb +1 -1
- 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 +10 -5
- 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 +32 -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 +8 -20
- data/lib/sendgrid/helpers/permissions/scope.rb +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 +3 -3
- data/sendgrid-ruby.gemspec +7 -8
- data/spec/fixtures/event_webhook.rb +17 -11
- data/spec/rack/sendgrid_webhook_verification_spec.rb +30 -4
- data/spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb +38 -36
- 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 +1 -1
- 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 +17 -10
- data/test/sendgrid/helpers/mail/test_mail.rb +101 -102
- data/test/sendgrid/helpers/mail/test_personalizations.rb +133 -93
- data/test/sendgrid/permissions/test_scopes.rb +1 -3
- data/test/sendgrid/test_sendgrid-ruby.rb +1947 -1948
- data/use-cases/legacy-templates.md +1 -1
- data/use-cases/transactional-templates.md +1 -1
- metadata +39 -37
@@ -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 Tracking Settings #
|
9
7
|
# GET /tracking_settings #
|
@@ -30,7 +28,7 @@ puts response.headers
|
|
30
28
|
# Retrieve Click Track Settings #
|
31
29
|
# GET /tracking_settings/click #
|
32
30
|
|
33
|
-
response = sg.client.tracking_settings.click.get
|
31
|
+
response = sg.client.tracking_settings.click.get
|
34
32
|
puts response.status_code
|
35
33
|
puts response.body
|
36
34
|
puts response.headers
|
@@ -40,11 +38,11 @@ puts response.headers
|
|
40
38
|
# PATCH /tracking_settings/google_analytics #
|
41
39
|
|
42
40
|
data = JSON.parse('{
|
43
|
-
"enabled": true,
|
44
|
-
"utm_campaign": "website",
|
45
|
-
"utm_content": "",
|
46
|
-
"utm_medium": "email",
|
47
|
-
"utm_source": "sendgrid.com",
|
41
|
+
"enabled": true,
|
42
|
+
"utm_campaign": "website",
|
43
|
+
"utm_content": "",
|
44
|
+
"utm_medium": "email",
|
45
|
+
"utm_source": "sendgrid.com",
|
48
46
|
"utm_term": ""
|
49
47
|
}')
|
50
48
|
response = sg.client.tracking_settings.google_analytics.patch(request_body: data)
|
@@ -56,7 +54,7 @@ puts response.headers
|
|
56
54
|
# Retrieve Google Analytics Settings #
|
57
55
|
# GET /tracking_settings/google_analytics #
|
58
56
|
|
59
|
-
response = sg.client.tracking_settings.google_analytics.get
|
57
|
+
response = sg.client.tracking_settings.google_analytics.get
|
60
58
|
puts response.status_code
|
61
59
|
puts response.body
|
62
60
|
puts response.headers
|
@@ -77,7 +75,7 @@ puts response.headers
|
|
77
75
|
# Get Open Tracking Settings #
|
78
76
|
# GET /tracking_settings/open #
|
79
77
|
|
80
|
-
response = sg.client.tracking_settings.open.get
|
78
|
+
response = sg.client.tracking_settings.open.get
|
81
79
|
puts response.status_code
|
82
80
|
puts response.body
|
83
81
|
puts response.headers
|
@@ -87,11 +85,11 @@ puts response.headers
|
|
87
85
|
# PATCH /tracking_settings/subscription #
|
88
86
|
|
89
87
|
data = JSON.parse('{
|
90
|
-
"enabled": true,
|
91
|
-
"html_content": "html content",
|
92
|
-
"landing": "landing page html",
|
93
|
-
"plain_content": "text content",
|
94
|
-
"replace": "replacement tag",
|
88
|
+
"enabled": true,
|
89
|
+
"html_content": "html content",
|
90
|
+
"landing": "landing page html",
|
91
|
+
"plain_content": "text content",
|
92
|
+
"replace": "replacement tag",
|
95
93
|
"url": "url"
|
96
94
|
}')
|
97
95
|
response = sg.client.tracking_settings.subscription.patch(request_body: data)
|
@@ -103,8 +101,7 @@ puts response.headers
|
|
103
101
|
# Retrieve Subscription Tracking Settings #
|
104
102
|
# GET /tracking_settings/subscription #
|
105
103
|
|
106
|
-
response = sg.client.tracking_settings.subscription.get
|
104
|
+
response = sg.client.tracking_settings.subscription.get
|
107
105
|
puts response.status_code
|
108
106
|
puts response.body
|
109
107
|
puts response.headers
|
110
|
-
|
data/examples/user/user.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
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
|
# Get a user's account information. #
|
9
7
|
# GET /user/account #
|
10
8
|
|
11
|
-
response = sg.client.user.account.get
|
9
|
+
response = sg.client.user.account.get
|
12
10
|
puts response.status_code
|
13
11
|
puts response.body
|
14
12
|
puts response.headers
|
@@ -17,7 +15,7 @@ puts response.headers
|
|
17
15
|
# Retrieve your credit balance #
|
18
16
|
# GET /user/credits #
|
19
17
|
|
20
|
-
response = sg.client.user.credits.get
|
18
|
+
response = sg.client.user.credits.get
|
21
19
|
puts response.status_code
|
22
20
|
puts response.body
|
23
21
|
puts response.headers
|
@@ -38,7 +36,7 @@ puts response.headers
|
|
38
36
|
# Retrieve your account email address #
|
39
37
|
# GET /user/email #
|
40
38
|
|
41
|
-
response = sg.client.user.email.get
|
39
|
+
response = sg.client.user.email.get
|
42
40
|
puts response.status_code
|
43
41
|
puts response.body
|
44
42
|
puts response.headers
|
@@ -48,7 +46,7 @@ puts response.headers
|
|
48
46
|
# PUT /user/password #
|
49
47
|
|
50
48
|
data = JSON.parse('{
|
51
|
-
"new_password": "new_password",
|
49
|
+
"new_password": "new_password",
|
52
50
|
"old_password": "old_password"
|
53
51
|
}')
|
54
52
|
response = sg.client.user.password.put(request_body: data)
|
@@ -61,8 +59,8 @@ puts response.headers
|
|
61
59
|
# PATCH /user/profile #
|
62
60
|
|
63
61
|
data = JSON.parse('{
|
64
|
-
"city": "Orange",
|
65
|
-
"first_name": "Example",
|
62
|
+
"city": "Orange",
|
63
|
+
"first_name": "Example",
|
66
64
|
"last_name": "User"
|
67
65
|
}')
|
68
66
|
response = sg.client.user.profile.patch(request_body: data)
|
@@ -74,7 +72,7 @@ puts response.headers
|
|
74
72
|
# Get a user's profile #
|
75
73
|
# GET /user/profile #
|
76
74
|
|
77
|
-
response = sg.client.user.profile.get
|
75
|
+
response = sg.client.user.profile.get
|
78
76
|
puts response.status_code
|
79
77
|
puts response.body
|
80
78
|
puts response.headers
|
@@ -84,7 +82,7 @@ puts response.headers
|
|
84
82
|
# POST /user/scheduled_sends #
|
85
83
|
|
86
84
|
data = JSON.parse('{
|
87
|
-
"batch_id": "YOUR_BATCH_ID",
|
85
|
+
"batch_id": "YOUR_BATCH_ID",
|
88
86
|
"status": "pause"
|
89
87
|
}')
|
90
88
|
response = sg.client.user.scheduled_sends.post(request_body: data)
|
@@ -96,7 +94,7 @@ puts response.headers
|
|
96
94
|
# Retrieve all scheduled sends #
|
97
95
|
# GET /user/scheduled_sends #
|
98
96
|
|
99
|
-
response = sg.client.user.scheduled_sends.get
|
97
|
+
response = sg.client.user.scheduled_sends.get
|
100
98
|
puts response.status_code
|
101
99
|
puts response.body
|
102
100
|
puts response.headers
|
@@ -108,7 +106,7 @@ puts response.headers
|
|
108
106
|
data = JSON.parse('{
|
109
107
|
"status": "pause"
|
110
108
|
}')
|
111
|
-
batch_id =
|
109
|
+
batch_id = 'test_url_param'
|
112
110
|
response = sg.client.user.scheduled_sends._(batch_id).patch(request_body: data)
|
113
111
|
puts response.status_code
|
114
112
|
puts response.body
|
@@ -118,8 +116,8 @@ puts response.headers
|
|
118
116
|
# Retrieve scheduled send #
|
119
117
|
# GET /user/scheduled_sends/{batch_id} #
|
120
118
|
|
121
|
-
batch_id =
|
122
|
-
response = sg.client.user.scheduled_sends._(batch_id).get
|
119
|
+
batch_id = 'test_url_param'
|
120
|
+
response = sg.client.user.scheduled_sends._(batch_id).get
|
123
121
|
puts response.status_code
|
124
122
|
puts response.body
|
125
123
|
puts response.headers
|
@@ -128,8 +126,8 @@ puts response.headers
|
|
128
126
|
# Delete a cancellation or pause of a scheduled send #
|
129
127
|
# DELETE /user/scheduled_sends/{batch_id} #
|
130
128
|
|
131
|
-
batch_id =
|
132
|
-
response = sg.client.user.scheduled_sends._(batch_id).delete
|
129
|
+
batch_id = 'test_url_param'
|
130
|
+
response = sg.client.user.scheduled_sends._(batch_id).delete
|
133
131
|
puts response.status_code
|
134
132
|
puts response.body
|
135
133
|
puts response.headers
|
@@ -139,7 +137,7 @@ puts response.headers
|
|
139
137
|
# PATCH /user/settings/enforced_tls #
|
140
138
|
|
141
139
|
data = JSON.parse('{
|
142
|
-
"require_tls": true,
|
140
|
+
"require_tls": true,
|
143
141
|
"require_valid_cert": false
|
144
142
|
}')
|
145
143
|
response = sg.client.user.settings.enforced_tls.patch(request_body: data)
|
@@ -151,7 +149,7 @@ puts response.headers
|
|
151
149
|
# Retrieve current Enforced TLS settings. #
|
152
150
|
# GET /user/settings/enforced_tls #
|
153
151
|
|
154
|
-
response = sg.client.user.settings.enforced_tls.get
|
152
|
+
response = sg.client.user.settings.enforced_tls.get
|
155
153
|
puts response.status_code
|
156
154
|
puts response.body
|
157
155
|
puts response.headers
|
@@ -172,7 +170,7 @@ puts response.headers
|
|
172
170
|
# Retrieve your username #
|
173
171
|
# GET /user/username #
|
174
172
|
|
175
|
-
response = sg.client.user.username.get
|
173
|
+
response = sg.client.user.username.get
|
176
174
|
puts response.status_code
|
177
175
|
puts response.body
|
178
176
|
puts response.headers
|
@@ -182,18 +180,18 @@ puts response.headers
|
|
182
180
|
# PATCH /user/webhooks/event/settings #
|
183
181
|
|
184
182
|
data = JSON.parse('{
|
185
|
-
"bounce": true,
|
186
|
-
"click": true,
|
187
|
-
"deferred": true,
|
188
|
-
"delivered": true,
|
189
|
-
"dropped": true,
|
190
|
-
"enabled": true,
|
191
|
-
"group_resubscribe": true,
|
192
|
-
"group_unsubscribe": true,
|
193
|
-
"open": true,
|
194
|
-
"processed": true,
|
195
|
-
"spam_report": true,
|
196
|
-
"unsubscribe": true,
|
183
|
+
"bounce": true,
|
184
|
+
"click": true,
|
185
|
+
"deferred": true,
|
186
|
+
"delivered": true,
|
187
|
+
"dropped": true,
|
188
|
+
"enabled": true,
|
189
|
+
"group_resubscribe": true,
|
190
|
+
"group_unsubscribe": true,
|
191
|
+
"open": true,
|
192
|
+
"processed": true,
|
193
|
+
"spam_report": true,
|
194
|
+
"unsubscribe": true,
|
197
195
|
"url": "url"
|
198
196
|
}')
|
199
197
|
response = sg.client.user.webhooks.event.settings.patch(request_body: data)
|
@@ -205,7 +203,7 @@ puts response.headers
|
|
205
203
|
# Retrieve Event Webhook settings #
|
206
204
|
# GET /user/webhooks/event/settings #
|
207
205
|
|
208
|
-
response = sg.client.user.webhooks.event.settings.get
|
206
|
+
response = sg.client.user.webhooks.event.settings.get
|
209
207
|
puts response.status_code
|
210
208
|
puts response.body
|
211
209
|
puts response.headers
|
@@ -227,9 +225,9 @@ puts response.headers
|
|
227
225
|
# POST /user/webhooks/parse/settings #
|
228
226
|
|
229
227
|
data = JSON.parse('{
|
230
|
-
"hostname": "myhostname.com",
|
231
|
-
"send_raw": false,
|
232
|
-
"spam_check": true,
|
228
|
+
"hostname": "myhostname.com",
|
229
|
+
"send_raw": false,
|
230
|
+
"spam_check": true,
|
233
231
|
"url": "http://email.myhosthame.com"
|
234
232
|
}')
|
235
233
|
response = sg.client.user.webhooks.parse.settings.post(request_body: data)
|
@@ -241,7 +239,7 @@ puts response.headers
|
|
241
239
|
# Retrieve all parse settings #
|
242
240
|
# GET /user/webhooks/parse/settings #
|
243
241
|
|
244
|
-
response = sg.client.user.webhooks.parse.settings.get
|
242
|
+
response = sg.client.user.webhooks.parse.settings.get
|
245
243
|
puts response.status_code
|
246
244
|
puts response.body
|
247
245
|
puts response.headers
|
@@ -251,11 +249,11 @@ puts response.headers
|
|
251
249
|
# PATCH /user/webhooks/parse/settings/{hostname} #
|
252
250
|
|
253
251
|
data = JSON.parse('{
|
254
|
-
"send_raw": true,
|
255
|
-
"spam_check": false,
|
252
|
+
"send_raw": true,
|
253
|
+
"spam_check": false,
|
256
254
|
"url": "http://newdomain.com/parse"
|
257
255
|
}')
|
258
|
-
hostname =
|
256
|
+
hostname = 'test_url_param'
|
259
257
|
response = sg.client.user.webhooks.parse.settings._(hostname).patch(request_body: data)
|
260
258
|
puts response.status_code
|
261
259
|
puts response.body
|
@@ -265,8 +263,8 @@ puts response.headers
|
|
265
263
|
# Retrieve a specific parse setting #
|
266
264
|
# GET /user/webhooks/parse/settings/{hostname} #
|
267
265
|
|
268
|
-
hostname =
|
269
|
-
response = sg.client.user.webhooks.parse.settings._(hostname).get
|
266
|
+
hostname = 'test_url_param'
|
267
|
+
response = sg.client.user.webhooks.parse.settings._(hostname).get
|
270
268
|
puts response.status_code
|
271
269
|
puts response.body
|
272
270
|
puts response.headers
|
@@ -275,8 +273,8 @@ puts response.headers
|
|
275
273
|
# Delete a parse setting #
|
276
274
|
# DELETE /user/webhooks/parse/settings/{hostname} #
|
277
275
|
|
278
|
-
hostname =
|
279
|
-
response = sg.client.user.webhooks.parse.settings._(hostname).delete
|
276
|
+
hostname = 'test_url_param'
|
277
|
+
response = sg.client.user.webhooks.parse.settings._(hostname).delete
|
280
278
|
puts response.status_code
|
281
279
|
puts response.body
|
282
280
|
puts response.headers
|
@@ -290,4 +288,3 @@ response = sg.client.user.webhooks.parse.stats.get(query_params: params)
|
|
290
288
|
puts response.status_code
|
291
289
|
puts response.body
|
292
290
|
puts response.headers
|
293
|
-
|
@@ -27,6 +27,7 @@ module Rack
|
|
27
27
|
|
28
28
|
def call(env)
|
29
29
|
return @app.call(env) unless env['PATH_INFO'].match(@path_regex)
|
30
|
+
|
30
31
|
request = Rack::Request.new(env)
|
31
32
|
|
32
33
|
event_webhook = SendGrid::EventWebhook.new
|
@@ -38,10 +39,12 @@ module Rack
|
|
38
39
|
request.env[SendGrid::EventWebhookHeader::TIMESTAMP]
|
39
40
|
)
|
40
41
|
|
42
|
+
request.body.rewind
|
43
|
+
|
41
44
|
if verified
|
42
|
-
|
45
|
+
@app.call(env)
|
43
46
|
else
|
44
|
-
|
47
|
+
[
|
45
48
|
403,
|
46
49
|
{ 'Content-Type' => 'text/plain' },
|
47
50
|
['SendGrid Request Verification Failed.']
|
@@ -5,6 +5,7 @@ require_relative 'version'
|
|
5
5
|
class BaseInterface
|
6
6
|
attr_accessor :client
|
7
7
|
attr_reader :request_headers, :host, :version, :impersonate_subuser
|
8
|
+
|
8
9
|
# * *Args* :
|
9
10
|
# - +auth+ -> authorization header value
|
10
11
|
# - +host+ -> the base URL for the API
|
@@ -17,7 +18,7 @@ class BaseInterface
|
|
17
18
|
def initialize(auth:, host:, request_headers: nil, version: nil, impersonate_subuser: nil)
|
18
19
|
@auth = auth
|
19
20
|
@host = host
|
20
|
-
@version = version
|
21
|
+
@version = version || 'v3'
|
21
22
|
@impersonate_subuser = impersonate_subuser
|
22
23
|
@user_agent = "sendgrid/#{SendGrid::VERSION};ruby"
|
23
24
|
@request_headers = JSON.parse('
|
@@ -25,15 +25,13 @@ module SendGrid
|
|
25
25
|
payload_digest = Digest::SHA256.digest(timestamped_playload)
|
26
26
|
decoded_signature = Base64.decode64(signature)
|
27
27
|
public_key.dsa_verify_asn1(payload_digest, decoded_signature)
|
28
|
-
rescue
|
28
|
+
rescue StandardError
|
29
29
|
false
|
30
30
|
end
|
31
31
|
|
32
32
|
def verify_engine
|
33
33
|
# JRuby does not fully support ECDSA: https://github.com/jruby/jruby-openssl/issues/193
|
34
|
-
if RUBY_PLATFORM == "java"
|
35
|
-
raise NotSupportedError, "Event Webhook verification is not supported by JRuby"
|
36
|
-
end
|
34
|
+
raise NotSupportedError, "Event Webhook verification is not supported by JRuby" if RUBY_PLATFORM == "java"
|
37
35
|
end
|
38
36
|
|
39
37
|
class Error < ::RuntimeError
|
@@ -46,7 +44,7 @@ module SendGrid
|
|
46
44
|
# This class lists headers that get posted to the webhook. Read the docs for
|
47
45
|
# more details: https://sendgrid.com/docs/for-developers/tracking-events/event
|
48
46
|
class EventWebhookHeader
|
49
|
-
SIGNATURE = "HTTP_X_TWILIO_EMAIL_EVENT_WEBHOOK_SIGNATURE"
|
50
|
-
TIMESTAMP = "HTTP_X_TWILIO_EMAIL_EVENT_WEBHOOK_TIMESTAMP"
|
47
|
+
SIGNATURE = "HTTP_X_TWILIO_EMAIL_EVENT_WEBHOOK_SIGNATURE".freeze
|
48
|
+
TIMESTAMP = "HTTP_X_TWILIO_EMAIL_EVENT_WEBHOOK_TIMESTAMP".freeze
|
51
49
|
end
|
52
50
|
end
|
@@ -18,7 +18,7 @@ require 'yaml'
|
|
18
18
|
class Main < Sinatra::Base
|
19
19
|
configure :production, :development do
|
20
20
|
enable :logging
|
21
|
-
set :config, YAML.load_file(File.dirname(__FILE__)
|
21
|
+
set :config, YAML.load_file("#{File.dirname(__FILE__)}/config.yml")
|
22
22
|
end
|
23
23
|
|
24
24
|
get '/' do
|
@@ -26,7 +26,7 @@ class Main < Sinatra::Base
|
|
26
26
|
end
|
27
27
|
|
28
28
|
post settings.config['endpoint'] do
|
29
|
-
filtered = params.select {|k,
|
29
|
+
filtered = params.select { |k, _v| settings.config['keys'].include?(k) }
|
30
30
|
logger.info JSON.pretty_generate(filtered)
|
31
31
|
end
|
32
32
|
end
|
@@ -4,11 +4,11 @@ require 'ruby_http_client'
|
|
4
4
|
require 'yaml'
|
5
5
|
require 'optparse'
|
6
6
|
|
7
|
-
OPTS = {}
|
7
|
+
OPTS = {}.freeze
|
8
8
|
opt = OptionParser.new
|
9
|
-
opt.on('--host=HOST') {|v| OPTS[:host] = v}
|
9
|
+
opt.on('--host=HOST') { |v| OPTS[:host] = v }
|
10
10
|
argv = opt.parse!(ARGV)
|
11
|
-
config = YAML.load_file(File.dirname(__FILE__)
|
11
|
+
config = YAML.load_file("#{File.dirname(__FILE__)}/config.yml")
|
12
12
|
host = OPTS[:host] || config['host']
|
13
13
|
client = SendGrid::Client.new(host: host)
|
14
14
|
File.open(argv[0]) do |file|
|
@@ -1,30 +1,18 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module SendGrid
|
2
4
|
class ASM
|
3
|
-
|
4
|
-
@group_id = group_id
|
5
|
-
@groups_to_display = groups_to_display
|
6
|
-
end
|
5
|
+
attr_accessor :group_id, :groups_to_display
|
7
6
|
|
8
|
-
def
|
7
|
+
def initialize(group_id: nil, groups_to_display: nil)
|
9
8
|
@group_id = group_id
|
10
|
-
end
|
11
|
-
|
12
|
-
def group_id
|
13
|
-
@group_id
|
14
|
-
end
|
15
|
-
|
16
|
-
def groups_to_display=(groups_to_display)
|
17
9
|
@groups_to_display = groups_to_display
|
18
10
|
end
|
19
11
|
|
20
|
-
def groups_to_display
|
21
|
-
@groups_to_display
|
22
|
-
end
|
23
|
-
|
24
12
|
def to_json(*)
|
25
13
|
{
|
26
|
-
'group_id' =>
|
27
|
-
'groups_to_display' =>
|
14
|
+
'group_id' => group_id,
|
15
|
+
'groups_to_display' => groups_to_display
|
28
16
|
}.delete_if { |_, value| value.to_s.strip == '' }
|
29
17
|
end
|
30
18
|
end
|