sendgrid-ruby 1.1.6 → 6.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +21 -0
  3. data/.env_sample +1 -3
  4. data/.gitignore +1 -0
  5. data/.travis.yml +28 -17
  6. data/CHANGELOG.md +231 -1
  7. data/CODE_OF_CONDUCT.md +73 -0
  8. data/CONTRIBUTING.md +214 -0
  9. data/Gemfile +5 -4
  10. data/ISSUE_TEMPLATE.md +26 -0
  11. data/LICENSE.md +21 -0
  12. data/Makefile +7 -0
  13. data/PULL_REQUEST_TEMPLATE.md +31 -0
  14. data/README.md +161 -225
  15. data/Rakefile +9 -2
  16. data/TROUBLESHOOTING.md +137 -0
  17. data/UPGRADE.md +5 -0
  18. data/USAGE.md +5037 -0
  19. data/USE_CASES.md +377 -0
  20. data/config.ru +4 -0
  21. data/docker/Dockerfile +12 -0
  22. data/docker/README.md +30 -0
  23. data/examples/accesssettings/accesssettings.rb +83 -0
  24. data/examples/alerts/alerts.rb +62 -0
  25. data/examples/apikeys/apikeys.rb +84 -0
  26. data/examples/asm/asm.rb +173 -0
  27. data/examples/browsers/browsers.rb +16 -0
  28. data/examples/campaigns/campaigns.rb +153 -0
  29. data/examples/categories/categories.rb +36 -0
  30. data/examples/clients/clients.rb +27 -0
  31. data/examples/contactdb/contactdb.rb +395 -0
  32. data/examples/devices/devices.rb +16 -0
  33. data/examples/geo/geo.rb +16 -0
  34. data/examples/helpers/mail/example.rb +147 -0
  35. data/examples/helpers/settings/example.rb +23 -0
  36. data/examples/helpers/stats/example.rb +42 -0
  37. data/examples/ips/ips.rb +167 -0
  38. data/examples/mail/mail.rb +173 -0
  39. data/examples/mailboxproviders/mailboxproviders.rb +16 -0
  40. data/examples/mailsettings/mailsettings.rb +219 -0
  41. data/examples/partnersettings/partnersettings.rb +39 -0
  42. data/examples/scopes/scopes.rb +61 -0
  43. data/examples/senderauthentication/senderauthentication.rb +310 -0
  44. data/examples/senders/senders.rb +98 -0
  45. data/examples/stats/stats.rb +16 -0
  46. data/examples/subusers/subusers.rb +169 -0
  47. data/examples/suppression/suppression.rb +201 -0
  48. data/examples/templates/templates.rb +129 -0
  49. data/examples/trackingsettings/trackingsettings.rb +110 -0
  50. data/examples/user/user.rb +293 -0
  51. data/gemfiles/Sinatra_1.gemfile +6 -0
  52. data/gemfiles/Sinatra_2.gemfile +6 -0
  53. data/lib/sendgrid/client.rb +33 -57
  54. data/lib/sendgrid/helpers/inbound/README.md +98 -0
  55. data/lib/sendgrid/helpers/inbound/app.rb +32 -0
  56. data/lib/sendgrid/helpers/inbound/config.yml +26 -0
  57. data/lib/sendgrid/helpers/inbound/public/index.html +10 -0
  58. data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +58 -0
  59. data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +57 -0
  60. data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +298 -0
  61. data/lib/sendgrid/helpers/inbound/send.rb +26 -0
  62. data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
  63. data/lib/sendgrid/helpers/mail/README.md +14 -0
  64. data/lib/sendgrid/helpers/mail/asm.rb +33 -0
  65. data/lib/sendgrid/helpers/mail/attachment.rb +86 -0
  66. data/lib/sendgrid/helpers/mail/bcc_settings.rb +33 -0
  67. data/lib/sendgrid/helpers/mail/bypass_list_management.rb +43 -0
  68. data/lib/sendgrid/helpers/mail/category.rb +20 -0
  69. data/lib/sendgrid/helpers/mail/click_tracking.rb +33 -0
  70. data/lib/sendgrid/helpers/mail/content.rb +20 -0
  71. data/lib/sendgrid/helpers/mail/custom_arg.rb +24 -0
  72. data/lib/sendgrid/helpers/mail/email.rb +29 -0
  73. data/lib/sendgrid/helpers/mail/footer.rb +43 -0
  74. data/lib/sendgrid/helpers/mail/ganalytics.rb +74 -0
  75. data/lib/sendgrid/helpers/mail/header.rb +24 -0
  76. data/lib/sendgrid/helpers/mail/mail.rb +140 -0
  77. data/lib/sendgrid/helpers/mail/mail_settings.rb +63 -0
  78. data/lib/sendgrid/helpers/mail/open_tracking.rb +33 -0
  79. data/lib/sendgrid/helpers/mail/personalization.rb +82 -0
  80. data/lib/sendgrid/helpers/mail/section.rb +24 -0
  81. data/lib/sendgrid/helpers/mail/spam_check.rb +43 -0
  82. data/lib/sendgrid/helpers/mail/subscription_tracking.rb +53 -0
  83. data/lib/sendgrid/helpers/mail/substitution.rb +24 -0
  84. data/lib/sendgrid/helpers/mail/tracking_settings.rb +53 -0
  85. data/lib/sendgrid/helpers/permissions/scope.rb +28 -0
  86. data/lib/sendgrid/helpers/permissions/scopes.yml +309 -0
  87. data/lib/sendgrid/helpers/settings/README.md +14 -0
  88. data/lib/sendgrid/helpers/settings/mail_settings_dto.rb +13 -0
  89. data/lib/sendgrid/helpers/settings/partner_settings_dto.rb +13 -0
  90. data/lib/sendgrid/helpers/settings/settings.rb +28 -0
  91. data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +24 -0
  92. data/lib/sendgrid/helpers/settings/user_settings_dto.rb +13 -0
  93. data/lib/sendgrid/helpers/stats/email_stats.rb +46 -0
  94. data/lib/sendgrid/helpers/stats/metrics.rb +35 -0
  95. data/lib/sendgrid/helpers/stats/stats_response.rb +31 -0
  96. data/lib/sendgrid/version.rb +1 -1
  97. data/lib/sendgrid-ruby.rb +27 -6
  98. data/mail_helper_v3.md +390 -0
  99. data/sendgrid-ruby.gemspec +13 -17
  100. data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
  101. data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +32 -0
  102. data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +24 -0
  103. data/spec/sendgrid/helpers/settings/settings_spec.rb +25 -0
  104. data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +27 -0
  105. data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +24 -0
  106. data/spec/sendgrid/helpers/stats/email_stats_spec.rb +112 -0
  107. data/spec/sendgrid/helpers/stats/metrics_spec.rb +46 -0
  108. data/spec/sendgrid/helpers/stats/stats_response_spec.rb +76 -0
  109. data/spec/spec_helper.rb +10 -1
  110. data/test/prism.sh +42 -0
  111. data/test/sendgrid/helpers/mail/test_attachment.rb +35 -0
  112. data/test/sendgrid/helpers/mail/test_category.rb +27 -0
  113. data/test/sendgrid/helpers/mail/test_email.rb +34 -0
  114. data/test/sendgrid/helpers/mail/test_mail.rb +261 -0
  115. data/test/sendgrid/helpers/mail/test_personalizations.rb +161 -0
  116. data/test/sendgrid/permissions/test_scopes.rb +38 -0
  117. data/test/sendgrid/test_sendgrid-ruby.rb +2751 -0
  118. metadata +149 -115
  119. data/.rspec +0 -2
  120. data/.rubocop.yml +0 -30
  121. data/FETCH_HEAD +0 -0
  122. data/Guardfile +0 -10
  123. data/LICENSE.txt +0 -22
  124. data/example.rb +0 -41
  125. data/lib/sendgrid/exceptions.rb +0 -7
  126. data/lib/sendgrid/mail.rb +0 -182
  127. data/lib/sendgrid/recipient.rb +0 -29
  128. data/lib/sendgrid/response.rb +0 -14
  129. data/lib/sendgrid/template.rb +0 -26
  130. data/lib/sendgrid/template_mailer.rb +0 -59
  131. data/spec/lib/sendgrid/client_spec.rb +0 -87
  132. data/spec/lib/sendgrid/mail_spec.rb +0 -151
  133. data/spec/lib/sendgrid/recipient_spec.rb +0 -91
  134. data/spec/lib/sendgrid/template_mailer_spec.rb +0 -86
  135. data/spec/lib/sendgrid/template_spec.rb +0 -61
  136. data/spec/lib/sendgrid_spec.rb +0 -7
@@ -0,0 +1,293 @@
1
+ require 'sendgrid-ruby'
2
+
3
+
4
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
+
6
+
7
+ ##################################################
8
+ # Get a user's account information. #
9
+ # GET /user/account #
10
+
11
+ response = sg.client.user.account.get()
12
+ puts response.status_code
13
+ puts response.body
14
+ puts response.headers
15
+
16
+ ##################################################
17
+ # Retrieve your credit balance #
18
+ # GET /user/credits #
19
+
20
+ response = sg.client.user.credits.get()
21
+ puts response.status_code
22
+ puts response.body
23
+ puts response.headers
24
+
25
+ ##################################################
26
+ # Update your account email address #
27
+ # PUT /user/email #
28
+
29
+ data = JSON.parse('{
30
+ "email": "example@example.com"
31
+ }')
32
+ response = sg.client.user.email.put(request_body: data)
33
+ puts response.status_code
34
+ puts response.body
35
+ puts response.headers
36
+
37
+ ##################################################
38
+ # Retrieve your account email address #
39
+ # GET /user/email #
40
+
41
+ response = sg.client.user.email.get()
42
+ puts response.status_code
43
+ puts response.body
44
+ puts response.headers
45
+
46
+ ##################################################
47
+ # Update your password #
48
+ # PUT /user/password #
49
+
50
+ data = JSON.parse('{
51
+ "new_password": "new_password",
52
+ "old_password": "old_password"
53
+ }')
54
+ response = sg.client.user.password.put(request_body: data)
55
+ puts response.status_code
56
+ puts response.body
57
+ puts response.headers
58
+
59
+ ##################################################
60
+ # Update a user's profile #
61
+ # PATCH /user/profile #
62
+
63
+ data = JSON.parse('{
64
+ "city": "Orange",
65
+ "first_name": "Example",
66
+ "last_name": "User"
67
+ }')
68
+ response = sg.client.user.profile.patch(request_body: data)
69
+ puts response.status_code
70
+ puts response.body
71
+ puts response.headers
72
+
73
+ ##################################################
74
+ # Get a user's profile #
75
+ # GET /user/profile #
76
+
77
+ response = sg.client.user.profile.get()
78
+ puts response.status_code
79
+ puts response.body
80
+ puts response.headers
81
+
82
+ ##################################################
83
+ # Cancel or pause a scheduled send #
84
+ # POST /user/scheduled_sends #
85
+
86
+ data = JSON.parse('{
87
+ "batch_id": "YOUR_BATCH_ID",
88
+ "status": "pause"
89
+ }')
90
+ response = sg.client.user.scheduled_sends.post(request_body: data)
91
+ puts response.status_code
92
+ puts response.body
93
+ puts response.headers
94
+
95
+ ##################################################
96
+ # Retrieve all scheduled sends #
97
+ # GET /user/scheduled_sends #
98
+
99
+ response = sg.client.user.scheduled_sends.get()
100
+ puts response.status_code
101
+ puts response.body
102
+ puts response.headers
103
+
104
+ ##################################################
105
+ # Update user scheduled send information #
106
+ # PATCH /user/scheduled_sends/{batch_id} #
107
+
108
+ data = JSON.parse('{
109
+ "status": "pause"
110
+ }')
111
+ batch_id = "test_url_param"
112
+ response = sg.client.user.scheduled_sends._(batch_id).patch(request_body: data)
113
+ puts response.status_code
114
+ puts response.body
115
+ puts response.headers
116
+
117
+ ##################################################
118
+ # Retrieve scheduled send #
119
+ # GET /user/scheduled_sends/{batch_id} #
120
+
121
+ batch_id = "test_url_param"
122
+ response = sg.client.user.scheduled_sends._(batch_id).get()
123
+ puts response.status_code
124
+ puts response.body
125
+ puts response.headers
126
+
127
+ ##################################################
128
+ # Delete a cancellation or pause of a scheduled send #
129
+ # DELETE /user/scheduled_sends/{batch_id} #
130
+
131
+ batch_id = "test_url_param"
132
+ response = sg.client.user.scheduled_sends._(batch_id).delete()
133
+ puts response.status_code
134
+ puts response.body
135
+ puts response.headers
136
+
137
+ ##################################################
138
+ # Update Enforced TLS settings #
139
+ # PATCH /user/settings/enforced_tls #
140
+
141
+ data = JSON.parse('{
142
+ "require_tls": true,
143
+ "require_valid_cert": false
144
+ }')
145
+ response = sg.client.user.settings.enforced_tls.patch(request_body: data)
146
+ puts response.status_code
147
+ puts response.body
148
+ puts response.headers
149
+
150
+ ##################################################
151
+ # Retrieve current Enforced TLS settings. #
152
+ # GET /user/settings/enforced_tls #
153
+
154
+ response = sg.client.user.settings.enforced_tls.get()
155
+ puts response.status_code
156
+ puts response.body
157
+ puts response.headers
158
+
159
+ ##################################################
160
+ # Update your username #
161
+ # PUT /user/username #
162
+
163
+ data = JSON.parse('{
164
+ "username": "test_username"
165
+ }')
166
+ response = sg.client.user.username.put(request_body: data)
167
+ puts response.status_code
168
+ puts response.body
169
+ puts response.headers
170
+
171
+ ##################################################
172
+ # Retrieve your username #
173
+ # GET /user/username #
174
+
175
+ response = sg.client.user.username.get()
176
+ puts response.status_code
177
+ puts response.body
178
+ puts response.headers
179
+
180
+ ##################################################
181
+ # Update Event Notification Settings #
182
+ # PATCH /user/webhooks/event/settings #
183
+
184
+ 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,
197
+ "url": "url"
198
+ }')
199
+ response = sg.client.user.webhooks.event.settings.patch(request_body: data)
200
+ puts response.status_code
201
+ puts response.body
202
+ puts response.headers
203
+
204
+ ##################################################
205
+ # Retrieve Event Webhook settings #
206
+ # GET /user/webhooks/event/settings #
207
+
208
+ response = sg.client.user.webhooks.event.settings.get()
209
+ puts response.status_code
210
+ puts response.body
211
+ puts response.headers
212
+
213
+ ##################################################
214
+ # Test Event Notification Settings #
215
+ # POST /user/webhooks/event/test #
216
+
217
+ data = JSON.parse('{
218
+ "url": "url"
219
+ }')
220
+ response = sg.client.user.webhooks.event.test.post(request_body: data)
221
+ puts response.status_code
222
+ puts response.body
223
+ puts response.headers
224
+
225
+ ##################################################
226
+ # Create a parse setting #
227
+ # POST /user/webhooks/parse/settings #
228
+
229
+ data = JSON.parse('{
230
+ "hostname": "myhostname.com",
231
+ "send_raw": false,
232
+ "spam_check": true,
233
+ "url": "http://email.myhosthame.com"
234
+ }')
235
+ response = sg.client.user.webhooks.parse.settings.post(request_body: data)
236
+ puts response.status_code
237
+ puts response.body
238
+ puts response.headers
239
+
240
+ ##################################################
241
+ # Retrieve all parse settings #
242
+ # GET /user/webhooks/parse/settings #
243
+
244
+ response = sg.client.user.webhooks.parse.settings.get()
245
+ puts response.status_code
246
+ puts response.body
247
+ puts response.headers
248
+
249
+ ##################################################
250
+ # Update a parse setting #
251
+ # PATCH /user/webhooks/parse/settings/{hostname} #
252
+
253
+ data = JSON.parse('{
254
+ "send_raw": true,
255
+ "spam_check": false,
256
+ "url": "http://newdomain.com/parse"
257
+ }')
258
+ hostname = "test_url_param"
259
+ response = sg.client.user.webhooks.parse.settings._(hostname).patch(request_body: data)
260
+ puts response.status_code
261
+ puts response.body
262
+ puts response.headers
263
+
264
+ ##################################################
265
+ # Retrieve a specific parse setting #
266
+ # GET /user/webhooks/parse/settings/{hostname} #
267
+
268
+ hostname = "test_url_param"
269
+ response = sg.client.user.webhooks.parse.settings._(hostname).get()
270
+ puts response.status_code
271
+ puts response.body
272
+ puts response.headers
273
+
274
+ ##################################################
275
+ # Delete a parse setting #
276
+ # DELETE /user/webhooks/parse/settings/{hostname} #
277
+
278
+ hostname = "test_url_param"
279
+ response = sg.client.user.webhooks.parse.settings._(hostname).delete()
280
+ puts response.status_code
281
+ puts response.body
282
+ puts response.headers
283
+
284
+ ##################################################
285
+ # Retrieves Inbound Parse Webhook statistics. #
286
+ # GET /user/webhooks/parse/stats #
287
+
288
+ params = JSON.parse('{"aggregated_by": "day", "limit": "test_string", "start_date": "2016-01-01", "end_date": "2016-04-01", "offset": "test_string"}')
289
+ response = sg.client.user.webhooks.parse.stats.get(query_params: params)
290
+ puts response.status_code
291
+ puts response.body
292
+ puts response.headers
293
+
@@ -0,0 +1,6 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'ruby_http_client'
6
+ gem 'sinatra', '~> 1.4'
@@ -0,0 +1,6 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'ruby_http_client'
6
+ gem 'sinatra', '>= 2.0.0.rc2'
@@ -1,62 +1,38 @@
1
- require 'faraday'
1
+ # Quickly and easily access the Twilio SendGrid API.
2
+ require 'ruby_http_client'
3
+ require_relative 'version'
2
4
 
3
5
  module SendGrid
4
- class Client
5
- attr_accessor :api_user, :api_key, :protocol, :host, :port, :url, :endpoint,
6
- :user_agent, :template
7
- attr_writer :adapter, :conn, :raise_exceptions
8
-
9
- def initialize(params = {})
10
- self.api_user = params.fetch(:api_user, nil)
11
- self.api_key = params.fetch(:api_key, nil)
12
- self.protocol = params.fetch(:protocol, 'https')
13
- self.host = params.fetch(:host, 'api.sendgrid.com')
14
- self.port = params.fetch(:port, nil)
15
- self.url = params.fetch(:url, protocol + '://' + host + (port ? ":#{port}" : ''))
16
- self.endpoint = params.fetch(:endpoint, '/api/mail.send.json')
17
- self.adapter = params.fetch(:adapter, adapter)
18
- self.conn = params.fetch(:conn, conn)
19
- self.user_agent = params.fetch(:user_agent, "sendgrid/#{SendGrid::VERSION};ruby")
20
- self.raise_exceptions = params.fetch(:raise_exceptions, true)
21
- yield self if block_given?
22
- end
23
-
24
- def send(mail)
25
- res = conn.post do |req|
26
- payload = mail.to_h
27
- req.url(endpoint)
28
-
29
- # Check if using username + password or API key
30
- if api_user
31
- # Username + password
32
- payload = payload.merge(api_user: api_user, api_key: api_key)
33
- else
34
- # API key
35
- req.headers['Authorization'] = "Bearer #{api_key}"
36
- end
37
-
38
- req.body = payload
39
- end
40
-
41
- fail SendGrid::Exception, res.body if raise_exceptions? && res.status != 200
42
-
43
- SendGrid::Response.new(code: res.status, headers: res.headers, body: res.body)
44
- end
45
-
46
- def conn
47
- @conn ||= Faraday.new(url: url) do |conn|
48
- conn.request :multipart
49
- conn.request :url_encoded
50
- conn.adapter adapter
51
- end
52
- end
53
-
54
- def adapter
55
- @adapter ||= Faraday.default_adapter
56
- end
57
-
58
- def raise_exceptions?
59
- @raise_exceptions
6
+ # Initialize the HTTP client
7
+ class API
8
+ attr_accessor :client
9
+ attr_reader :request_headers, :host, :version, :impersonate_subuser
10
+ # * *Args* :
11
+ # - +api_key+ -> your Twilio SendGrid API key
12
+ # - +host+ -> the base URL for the API
13
+ # - +request_headers+ -> any headers that you want to be globally applied
14
+ # - +version+ -> the version of the API you wish to access,
15
+ # currently only "v3" is supported
16
+ #
17
+ def initialize(api_key: '', host: nil, request_headers: nil, version: nil, impersonate_subuser: nil)
18
+ @api_key = api_key
19
+ @host = host ? host : 'https://api.sendgrid.com'
20
+ @version = version ? version : 'v3'
21
+ @impersonate_subuser = impersonate_subuser
22
+ @user_agent = "sendgrid/#{SendGrid::VERSION};ruby"
23
+ @request_headers = JSON.parse('
24
+ {
25
+ "Authorization": "Bearer ' + @api_key + '",
26
+ "Accept": "application/json",
27
+ "User-agent": "' + @user_agent + '"
28
+ }
29
+ ')
30
+ @request_headers['On-Behalf-Of'] = @impersonate_subuser if @impersonate_subuser
31
+
32
+
33
+ @request_headers = @request_headers.merge(request_headers) if request_headers
34
+ @client = Client.new(host: "#{@host}/#{@version}",
35
+ request_headers: @request_headers)
60
36
  end
61
37
  end
62
38
  end
@@ -0,0 +1,98 @@
1
+ **This helper is a stand alone module to help get you started consuming and processing Inbound Parse data.**
2
+
3
+ ## Table of Contents
4
+
5
+ - [Installation](#installation)
6
+ - [Quick Start for Local Testing with Sample Data](#quick-start-for-local-testing-with-sample-data)
7
+ - [Quick Start for Local Testing with Real Data](#quick-start-for-local-testing-with-real-data)
8
+ - [Code Walkthrough](#code-walkthrough)
9
+ - [app.rb](#apprb)
10
+ - [config.yml](#configyml)
11
+ - [send.rb & /sample_data](#sendrb--sampledata)
12
+ - [Contributing](#contributing)
13
+
14
+ <a name="quick_start_local_sample"></a>
15
+
16
+
17
+ # Installation
18
+
19
+ In addition to the installation instructions in
20
+ [the main readme](https://github.com/sendgrid/sendgrid-ruby/tree/master/#installation),
21
+ you must also add sinatra to your Gemfile:
22
+
23
+ ```
24
+ gem 'sinatra', '>= 1.4.7', '< 3'
25
+ ```
26
+
27
+
28
+ # Quick Start for Local Testing with Sample Data
29
+
30
+ ```bash
31
+ git clone https://github.com/sendgrid/sendgrid-ruby.git
32
+ cd sendgrid-ruby
33
+ bundle install
34
+ ```
35
+
36
+ Run the Inbound Parse listener in your terminal:
37
+
38
+ ```ruby
39
+ rackup
40
+ ```
41
+
42
+ In another terminal, run the test data sender:
43
+
44
+ ```bash
45
+ cd [path to sendgrid-ruby]
46
+ bundle install
47
+ ruby ./lib/sendgrid/helpers/inbound/send.rb ./lib/sendgrid/helpers/inbound/sample_data/default_data.txt
48
+ ```
49
+
50
+ More sample data can be found [here](https://github.com/sendgrid/sendgrid-ruby/tree/master/lib/sendgrid/helpers/inbound/sample_data).
51
+
52
+ View the results in the first terminal.
53
+
54
+ <a name="quick_start_local_real"></a>
55
+ # Quick Start for Local Testing with Real Data
56
+
57
+ [Setup your MX records.](https://sendgrid.com/docs/Classroom/Basics/Inbound_Parse_Webhook/setting_up_the_inbound_parse_webhook.html#-Setup) Depending on your domain name host, you may need to wait up to 48 hours for the settings to propagate.
58
+
59
+ Run the Inbound Parse listener in your terminal:
60
+
61
+ ```bash
62
+ git clone https://github.com/sendgrid/sendgrid-ruby.git
63
+ cd sendgrid-ruby
64
+ bundle install
65
+ rackup
66
+ ```
67
+
68
+ In another terminal, use [ngrok](https://ngrok.com/) to allow external access to your machine:
69
+ ```bash
70
+ ngrok http 9292
71
+ ```
72
+
73
+ Update your Twilio SendGrid Incoming Parse settings: [Settings Page](https://app.sendgrid.com/settings/parse) | [Docs](https://sendgrid.com/docs/Classroom/Basics/Inbound_Parse_Webhook/setting_up_the_inbound_parse_webhook.html#-Pointing-to-a-Hostname-and-URL)
74
+
75
+ - For the HOSTNAME field, use the domain that you changed the MX records (e.g. inbound.yourdomain.com)
76
+ - For the URL field, use the URL generated by ngrok + /inbound, e.g http://XXXXXXX.ngrok.io/inbound
77
+
78
+ Next, send an email to [anything]@inbound.yourdomain.com, then look at the terminal where you started the Inbound Parse listener.
79
+
80
+ <a name="code_walkthrough"></a>
81
+ # Code Walkthrough
82
+
83
+ ## app.rb
84
+
85
+ This module runs a [Sinatra](http://www.sinatrarb.com/) server, that by default (you can change those settings [here](https://github.com/sendgrid/sendgrid-ruby/blob/master/sendgrid/helpers/inbound/config.yml)), listens for POSTs on http://localhost:9292. When the server receives the POST, it parses and prints the key/value data.
86
+
87
+ ## config.yml
88
+
89
+ This module loads application environment variables (located in [config.yml](https://github.com/sendgrid/sendgrid-ruby/blob/master/sendgrid/helpers/inbound/config.yml)).
90
+
91
+ ## send.rb & /sample_data
92
+
93
+ This module is used to send sample test data. It is useful for testing and development, particularly while you wait for your MX records to propagate.
94
+
95
+ <a name="contributing"></a>
96
+ # Contributing
97
+
98
+ If you would like to contribute to this project, please see our [contributing guide](https://github.com/sendgrid/sendgrid-ruby/blob/master/CONTRIBUTING.md). Thanks!
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'sinatra'
3
+ rescue LoadError
4
+ puts <<-NOTE
5
+ As of sengrid verison 6, sinatra is no longer specified as a dependency of
6
+ the sendgrid gem. All the functionality of the inbound server is still the same
7
+ and fully supported, but you just need to include the sinatra dependency in your gemfile
8
+ yourself, like so:
9
+
10
+ gem 'sinatra', '>= 1.4.7', '< 3'
11
+ NOTE
12
+ raise
13
+ end
14
+ require 'logger'
15
+ require 'json'
16
+ require 'yaml'
17
+
18
+ class Main < Sinatra::Base
19
+ configure :production, :development do
20
+ enable :logging
21
+ set :config, YAML.load_file(File.dirname(__FILE__) + '/config.yml')
22
+ end
23
+
24
+ get '/' do
25
+ redirect to('index.html')
26
+ end
27
+
28
+ post settings.config['endpoint'] do
29
+ filtered = params.select {|k, v| settings.config['keys'].include?(k)}
30
+ logger.info JSON.pretty_generate(filtered)
31
+ end
32
+ end
@@ -0,0 +1,26 @@
1
+ # Incoming Parse endpoint for receiver
2
+ endpoint: '/inbound'
3
+
4
+ # List all Incoming Parse fields you would like parsed
5
+ # Reference: https://sendgrid.com/docs/Classroom/Basics/Inbound_Parse_Webhook/setting_up_the_inbound_parse_webhook.html
6
+ keys:
7
+ - from
8
+ - attachments
9
+ - headers
10
+ - text
11
+ - envelope
12
+ - to
13
+ - html
14
+ - sender_ip
15
+ - attachment-info
16
+ - subject
17
+ - dkim
18
+ - SPF
19
+ - charsets
20
+ - content-ids
21
+ - spam_report
22
+ - spam_score
23
+ - email
24
+
25
+ # URL that the sender will POST to
26
+ host: 'http://127.0.0.1:9292/inbound'
@@ -0,0 +1,10 @@
1
+ <html>
2
+ <head>
3
+ <title>Twilio SendGrid Incoming Parse</title>
4
+ </head>
5
+ <body>
6
+ <h1>You have successfuly launched the server!</h1>
7
+
8
+ Check out <a href="https://github.com/sendgrid/sendgrid-ruby/tree/master/sendgrid/helpers/inbound">the documentation</a> on how to use this software to utilize the SendGrid Inbound Parse webhook.
9
+ </body>
10
+ </html>
@@ -0,0 +1,58 @@
1
+ --xYzZY
2
+ Content-Disposition: form-data; name="headers"
3
+
4
+ MIME-Version: 1.0
5
+ Received: by 0.0.0.0 with HTTP; Wed, 10 Aug 2016 18:10:13 -0700 (PDT)
6
+ From: Example User <test@example.com>
7
+ Date: Wed, 10 Aug 2016 18:10:13 -0700
8
+ Subject: Inbound Parse Test Data
9
+ To: inbound@inbound.example.com
10
+ Content-Type: multipart/alternative; boundary=001a113df448cad2d00539c16e89
11
+
12
+ --xYzZY
13
+ Content-Disposition: form-data; name="dkim"
14
+
15
+ {@sendgrid.com : pass}
16
+ --xYzZY
17
+ Content-Disposition: form-data; name="to"
18
+
19
+ inbound@inbound.example.com
20
+ --xYzZY
21
+ Content-Disposition: form-data; name="html"
22
+
23
+ <html><body><strong>Hello Twilio SendGrid!</body></html>
24
+
25
+ --xYzZY
26
+ Content-Disposition: form-data; name="from"
27
+
28
+ Example User <test@example.com>
29
+ --xYzZY
30
+ Content-Disposition: form-data; name="text"
31
+
32
+ Hello Twilio SendGrid!
33
+
34
+ --xYzZY
35
+ Content-Disposition: form-data; name="sender_ip"
36
+
37
+ 0.0.0.0
38
+ --xYzZY
39
+ Content-Disposition: form-data; name="envelope"
40
+
41
+ {"to":["inbound@inbound.example.com"],"from":"test@example.com"}
42
+ --xYzZY
43
+ Content-Disposition: form-data; name="attachments"
44
+
45
+ 0
46
+ --xYzZY
47
+ Content-Disposition: form-data; name="subject"
48
+
49
+ Testing non-raw
50
+ --xYzZY
51
+ Content-Disposition: form-data; name="charsets"
52
+
53
+ {"to":"UTF-8","html":"UTF-8","subject":"UTF-8","from":"UTF-8","text":"UTF-8"}
54
+ --xYzZY
55
+ Content-Disposition: form-data; name="SPF"
56
+
57
+ pass
58
+ --xYzZY--
@@ -0,0 +1,57 @@
1
+ --xYzZY
2
+ Content-Disposition: form-data; name="dkim"
3
+
4
+ {@sendgrid.com : pass}
5
+ --xYzZY
6
+ Content-Disposition: form-data; name="email"
7
+
8
+ MIME-Version: 1.0
9
+ Received: by 0.0.0.0 with HTTP; Wed, 10 Aug 2016 14:44:21 -0700 (PDT)
10
+ From: Example User <test@example.com>
11
+ Date: Wed, 10 Aug 2016 14:44:21 -0700
12
+ Subject: Inbound Parse Test Raw Data
13
+ To: inbound@inbound.inbound.com
14
+ Content-Type: multipart/alternative; boundary=001a113ee97c89842f0539be8e7a
15
+
16
+ --001a113ee97c89842f0539be8e7a
17
+ Content-Type: text/plain; charset=UTF-8
18
+
19
+ Hello Twilio SendGrid!
20
+
21
+ --001a113ee97c89842f0539be8e7a
22
+ Content-Type: text/html; charset=UTF-8
23
+ Content-Transfer-Encoding: quoted-printable
24
+
25
+ <html><body><strong>Hello Twilio SendGrid!</body></html>
26
+
27
+ --001a113ee97c89842f0539be8e7a--
28
+
29
+ --xYzZY
30
+ Content-Disposition: form-data; name="to"
31
+
32
+ inbound@inbound.inbound.com
33
+ --xYzZY
34
+ Content-Disposition: form-data; name="from"
35
+
36
+ Example User <test@example.com>
37
+ --xYzZY
38
+ Content-Disposition: form-data; name="sender_ip"
39
+
40
+ 0.0.0.0
41
+ --xYzZY
42
+ Content-Disposition: form-data; name="envelope"
43
+
44
+ {"to":["inbound@inbound.inbound.com"],"from":"test@example.com"}
45
+ --xYzZY
46
+ Content-Disposition: form-data; name="subject"
47
+
48
+ Testing with Request.bin
49
+ --xYzZY
50
+ Content-Disposition: form-data; name="charsets"
51
+
52
+ {"to":"UTF-8","subject":"UTF-8","from":"UTF-8"}
53
+ --xYzZY
54
+ Content-Disposition: form-data; name="SPF"
55
+
56
+ pass
57
+ --xYzZY--