sendgrid4r 0.0.5 → 0.1.0

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.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +21 -0
  3. data/.travis.yml +2 -3
  4. data/README.md +3 -373
  5. data/Rakefile +1 -1
  6. data/lib/auth.rb +7 -9
  7. data/lib/client.rb +8 -9
  8. data/lib/sendgrid4r/factory/version_factory.rb +20 -10
  9. data/lib/sendgrid4r/rest/api.rb +28 -9
  10. data/lib/sendgrid4r/rest/asm/global_suppressions.rb +46 -0
  11. data/lib/sendgrid4r/rest/asm/groups.rb +69 -0
  12. data/lib/sendgrid4r/rest/asm/suppressions.rb +68 -0
  13. data/lib/sendgrid4r/rest/categories/categories.rb +38 -0
  14. data/lib/sendgrid4r/rest/ips/addresses.rb +74 -0
  15. data/lib/sendgrid4r/rest/ips/pools.rb +63 -0
  16. data/lib/sendgrid4r/rest/ips/warmup.rb +55 -0
  17. data/lib/sendgrid4r/rest/request.rb +34 -19
  18. data/lib/sendgrid4r/rest/settings/enforced_tls.rb +39 -0
  19. data/lib/sendgrid4r/rest/stats/advanced.rb +91 -0
  20. data/lib/sendgrid4r/rest/stats/category.rb +47 -0
  21. data/lib/sendgrid4r/rest/stats/global.rb +26 -0
  22. data/lib/sendgrid4r/rest/stats/parse.rb +26 -0
  23. data/lib/sendgrid4r/rest/stats/stats.rb +89 -0
  24. data/lib/sendgrid4r/rest/stats/subuser.rb +47 -0
  25. data/lib/sendgrid4r/rest/templates/templates.rb +61 -0
  26. data/lib/sendgrid4r/rest/templates/versions.rb +92 -0
  27. data/lib/sendgrid4r/version.rb +4 -1
  28. data/lib/sendgrid4r.rb +5 -2
  29. data/sendgrid4r.gemspec +13 -12
  30. data/spec/{global_suppressions_spec.rb → asm/global_suppressions_spec.rb} +25 -17
  31. data/spec/asm/groups_spec.rb +58 -0
  32. data/spec/{suppressions_spec.rb → asm/suppressions_spec.rb} +24 -22
  33. data/spec/categories/categories_spec.rb +39 -0
  34. data/spec/client_spec.rb +65 -50
  35. data/spec/ips/addresses_spec.rb +116 -0
  36. data/spec/ips/pools_spec.rb +43 -0
  37. data/spec/ips/warmup_spec.rb +52 -0
  38. data/spec/{enforced_tls_spec.rb → settings/enforced_tls_spec.rb} +12 -11
  39. data/spec/stats/advanced_spec.rb +243 -0
  40. data/spec/stats/category_spec.rb +112 -0
  41. data/spec/stats/global_spec.rb +64 -0
  42. data/spec/stats/parse_spec.rb +49 -0
  43. data/spec/stats/subuser_spec.rb +105 -0
  44. data/spec/templates/templates_spec.rb +66 -0
  45. data/spec/templates/versions_spec.rb +89 -0
  46. data/spec/version_factory_spec.rb +20 -15
  47. metadata +94 -42
  48. data/lib/sendgrid4r/rest/addresses.rb +0 -62
  49. data/lib/sendgrid4r/rest/enforced_tls.rb +0 -46
  50. data/lib/sendgrid4r/rest/global_suppressions.rb +0 -35
  51. data/lib/sendgrid4r/rest/groups.rb +0 -68
  52. data/lib/sendgrid4r/rest/pools.rb +0 -53
  53. data/lib/sendgrid4r/rest/suppressions.rb +0 -57
  54. data/lib/sendgrid4r/rest/templates.rb +0 -64
  55. data/lib/sendgrid4r/rest/versions.rb +0 -65
  56. data/lib/sendgrid4r/rest/warmup.rb +0 -53
  57. data/spec/addresses_spec.rb +0 -80
  58. data/spec/groups_spec.rb +0 -54
  59. data/spec/pools_spec.rb +0 -62
  60. data/spec/templates_spec.rb +0 -38
  61. data/spec/versions_spec.rb +0 -75
  62. data/spec/warmup_spec.rb +0 -52
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f0dc04ae5fecf0e518c08377aa8e12b3073eaa9
4
- data.tar.gz: 522e99261f8f6f33632f5fe92864f2118631b8af
3
+ metadata.gz: fb22cf3a6851051dc9aff2ccd01bb58f44f05d6b
4
+ data.tar.gz: 78395e30015b6182fdf8bdc61bf773d1a0b2c0f3
5
5
  SHA512:
6
- metadata.gz: 28a8693931daa73ec378ee71da02bedb7b125db5fa6d200822de0e4b3a889ea913f02264fd2024ea4088e10297df90ad24765e735176997efcb53d2d74a23f05
7
- data.tar.gz: ed1ca6766cb1af59c82b020d79513fa24b8a460012e313d02bf0a077c1a6c582943cc416836e54e89c81575209776085b646f66ebd5431dbc0e44547ac37c945
6
+ metadata.gz: 4e38ab32b44f3bf59f2c5feb724af2ad0b3d1c128e99f8f490a41a4fecd2d2b44e42c2dd690c65654c2e68d706b465ed6e2fc57c028fbb893f8ecffb1ed1f45e
7
+ data.tar.gz: d34d0ed4873dc08367e41c88101095b967b10c292807f39132fc994ab415e3a5551c843ba8ba5b4ee6aaeaebfb404865fee394bd3d22c5999da3bf3a06182fe1
data/.rubocop.yml ADDED
@@ -0,0 +1,21 @@
1
+ # メソッド名のprefixに「set_」「get_」を許可
2
+ AccessorMethodName:
3
+ Enabled: false
4
+
5
+ # メソッドの行数上限を変更
6
+ MethodLength:
7
+ CountComments: true # count full line comments?
8
+ Max: 20
9
+
10
+ # 引数上限を変更
11
+ ParameterLists:
12
+ Max: 6
13
+ CountKeywordArgs: true
14
+
15
+ # AbcSizeの上限を変更
16
+ AbcSize:
17
+ Max: 20
18
+
19
+ # %r 内で利用できるスラッシュの数の制限変更
20
+ RegexpLiteral:
21
+ MaxSlashes: 0
data/.travis.yml CHANGED
@@ -1,9 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- # - "1.9.3"
4
- # - "2.0.0"
5
- - "2.1.0"
3
+ - "2.1"
6
4
  before_script:
7
5
  - bundle install
8
6
  script:
7
+ - rubocop --fail-level=W
9
8
  - rspec
data/README.md CHANGED
@@ -3,381 +3,11 @@
3
3
  This gem allows you to quickly and easily access to SendGrid Web API v3 for Ruby.
4
4
  See [api reference](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) for more detail
5
5
 
6
- [![Build Status](https://travis-ci.org/awwa/sendgrid_template_engine_ruby.svg?branch=master)](https://travis-ci.org/awwa/sendgrid_template_engine_ruby.svg?branch=master)
6
+ [![Build Status](https://travis-ci.org/awwa/sendgrid4r.svg?branch=master)](https://travis-ci.org/awwa/sendgrid4r)
7
7
 
8
- ## Installation
8
+ # [Documentation](https://github.com/awwa/sendgrid4r/wiki)
9
9
 
10
- Add this line to your application's Gemfile:
11
-
12
- gem 'sendgrid4r'
13
-
14
- And then execute:
15
-
16
- $ bundle
17
-
18
- Or install it yourself as:
19
-
20
- $ gem install sendgrid4r
21
-
22
- ## Usage
23
-
24
- ### Create a client instance
25
-
26
- Create a SendGrid::Client instance for API call.
27
-
28
- ```Ruby
29
- require "sendgrid4r"
30
- client = Sendgrid4r::Client.new("user", "pass")
31
- ```
32
-
33
- ----
34
- ### Advanced Suppression Manager
35
-
36
- #### Groups
37
-
38
- ##### GET
39
- Retrieve all suppression groups associated with your account.
40
- ```Ruby
41
- groups = client.get_groups
42
- groups.each{|group|
43
- puts group.id # => 100
44
- puts group.name # => "Newsletters"
45
- puts group.description # => "Our monthly newsletter."
46
- puts group.last_email_sent_at # => "2014-09-04 01:34:43"
47
- puts group.unsubscribes # => 400
48
- }
49
- ```
50
-
51
- ##### GET
52
- Get information on a single suppression group.
53
- ```Ruby
54
- group = client.get_group(100)
55
- puts group.id # => 100
56
- puts group.name # => "Newsletters"
57
- puts group.description # => "Our monthly newsletter."
58
- puts group.last_email_sent_at # => "2014-09-04 01:34:43"
59
- puts group.unsubscribes # => 400
60
- ```
61
-
62
- ##### POST
63
- Create a new suppression group.
64
- ```Ruby
65
- new_group = client.post_group("group_name", "group_desc")
66
- ```
67
-
68
- ##### PATCH
69
- Update a suppression group.
70
- ```Ruby
71
- new_group.name = "group_edit"
72
- new_group.description = "group_desc_edit"
73
- client.patch_group(new_group.id, new_group)
74
- ```
75
-
76
- ##### DELETE
77
- Delete a suppression group.
78
- ```Ruby
79
- client.delete_group(100)
80
- ```
81
-
82
- #### Suppressions
83
-
84
- ##### POST
85
- Add recipient emails to the suppressions list for a given group.
86
- ```Ruby
87
- emails = client.post_suppressed_emails(group.id, ["email1@address.com", "email2@address.com", "email3@address.com"])
88
- ```
89
-
90
- ##### GET
91
- Get suppressions associated with a recipient email.
92
- ```Ruby
93
- suppressions = client.get_suppressions("email@address.com")
94
- suppressions.each{|suppression|
95
- puts suppression.id # => 1
96
- puts suppression.name # => "Weekly Newsletter"
97
- puts suppression.description # => "The weekly newsletter"
98
- puts suppression.suppressed # => true/false
99
- }
100
- ```
101
-
102
- ##### GET
103
- Retrieve suppressed emails for a group.
104
- ```Ruby
105
- emails = client.get_suppressed_emails(100)
106
- emails.each{|email|
107
- puts email
108
- }
109
- ```
110
-
111
- ##### DELETE
112
- Delete a recipient email from the suppressions list for a given group.
113
- ```Ruby
114
- client.delete_suppressed_email(100, "email1@address.com")
115
- ```
116
-
117
- #### Global Suppressions
118
-
119
- ##### POST
120
- Add recipient emails to the global suppression group.
121
- ```Ruby
122
- emails = client.post_global_suppressed_emails(["email1@address.com", "email2@address.com", "email3@address.com"])
123
- ```
124
-
125
- ##### GET
126
- Check if an address is in the global suppressions group.
127
- ```Ruby
128
- email1 = client.get_global_suppressed_email("email1@address.com")
129
- ```
130
-
131
- ##### DELETE
132
- Delete a recipient email from the global suppressions group.
133
- ```Ruby
134
- client.delete_global_suppressed_email("email1@address.com")
135
- ```
136
-
137
- ----
138
- ### IP Management
139
-
140
- #### IP Addresses
141
-
142
- ##### GET
143
- See a list of all IPs and the IPs, including warm up status and pools.
144
- ```Ruby
145
- ips = client.get_ips
146
- ips.each{|ip|
147
- puts ip.ip # => "xxx.xxx.xxx.xxx"
148
- puts ip.pools # => ["new_test5"]
149
- puts ip.warmup # => true/false
150
- puts ip.start_date # => 1409616000
151
- }
152
- ```
153
-
154
- ##### GET
155
- See which pools an IP address belongs to.
156
- ```Ruby
157
- ip = client.get_ip("xxx.xxx.xxx.xxx")
158
- puts ip.ip # => "xxx.xxx.xxx.xxx"
159
- puts ip.pools # => ["new_test5"]
160
- puts ip.warmup # => true/false
161
- ```
162
-
163
- ##### POST
164
- Add an IP to a pool.
165
- ```Ruby
166
- ip = client.post_ip_to_pool("pool_name", "xxx.xxx.xxx.xxx")
167
- puts ip.ip # => "xxx.xxx.xxx.xxx"
168
- puts ip.pool_name # => "new_test5"
169
- ```
170
-
171
- ##### DELETE
172
- Remove an IP address from a pool.
173
- ```Ruby
174
- client.delete_ip_from_pool("pool_name", "xxx.xxx.xxx.xxx")
175
- ```
176
-
177
- #### IP Pools
178
-
179
- ##### GET
180
- List all IP pools.
181
- ```Ruby
182
- pools = client.get_pools
183
- puts pools.inspect # => ["marketing","transactional"]
184
- ```
185
-
186
- ##### POST
187
- Create an IP pool.
188
- ```Ruby
189
- pool = client.post_pool("name")
190
- puts pool.name # => "name"
191
- ```
192
-
193
- ##### GET
194
- List the IPs in a specified pool.
195
- ```Ruby
196
- pool = client.get_pool("name")
197
- puts pool.name # => "name"
198
- puts pool.ips.inspect # => ["167.89.21.3"]
199
- ```
200
-
201
- ##### PUT
202
- Update an IP pool’s name
203
- ```Ruby
204
- client.put_pool("name", "new_name")
205
- puts pool.name # => "name"
206
- puts pool.ips.inspect # => ["167.89.21.3"]
207
- ```
208
-
209
- ##### DELETE
210
- Delete an IP pool.
211
- ```Ruby
212
- client.delete_pool("name")
213
- ```
214
-
215
- #### IP Warmup
216
-
217
- ##### GET
218
- Get all IPs that are currently warming up.
219
- ```Ruby
220
- warmup_ips = client.get_warmup_ips
221
- warmup_ips.each{|warmup_ip|
222
- puts warmup_ip.ip # => "xxx.xxx.xxx.xxx"
223
- puts warmup_ip.start_date # => 1409616000
224
- }
225
- ```
226
-
227
- ##### GET
228
- Get warmup status for a particular IP.
229
- ```Ruby
230
- warmup_ip = client.get_warmup_ip("xxx.xxx.xxx.xxx")
231
- puts warmup_ip.ip # => "xxx.xxx.xxx.xxx"
232
- puts warmup_ip.start_date # => 1409616000
233
- ```
234
-
235
- ##### POST
236
- Add an IP to warmup.
237
- ```Ruby
238
- client.post_warmup_ip("xxx.xxx.xxx.xxx")
239
- ```
240
-
241
- ##### DELETE
242
- Remove an IP from warmup.
243
- ```Ruby
244
- client.delete_warmup_ip("xxx.xxx.xxx.xxx")
245
- ```
246
-
247
- ----
248
- ### Settings
249
-
250
- #### Enforced TLS
251
-
252
- ##### GET
253
- Get the current Enforced TLS settings.
254
- ```Ruby
255
- enforced_tls = client.get_enforced_tls
256
- puts enforced_tls.require_tls # => true/false
257
- puts enforced_tls.require_valid_cert # => true/false
258
- ```
259
-
260
- ##### PATCH
261
- Change the Enforced TLS settings.
262
- ```Ruby
263
- enforced_tls = client.get_enforced_tls
264
- enforced_tls.require_tls = true
265
- enforced_tls.require_valid_cert = true
266
- client.patch_enforced_tls(enforced_tls)
267
- ```
268
-
269
- ----
270
- ### Template Engine
271
-
272
- #### Templates
273
-
274
- ##### GET
275
- Retrieve all templates.
276
- ```Ruby
277
- templates = client.get_templates
278
- templates.each {|template|
279
- puts template.id
280
- puts template.name
281
- template.versions.each {|ver|
282
- puts ver.id
283
- puts ver.template_id
284
- puts ver.active
285
- puts ver.name
286
- puts ver.updated_at
287
- }
288
- }
289
- ```
290
-
291
- ##### GET
292
- Retrieve a single template
293
- ```Ruby
294
- template = client.get_template(template_id)
295
- puts template.id
296
- puts template.name
297
- template.versions.each {|ver|
298
- puts ver.id
299
- puts ver.template_id
300
- puts ver.active
301
- puts ver.name
302
- puts ver.updated_at
303
- }
304
- ```
305
-
306
- ##### POST
307
- Create a template
308
- ```Ruby
309
- client.post_template("new_template_name")
310
- ```
311
-
312
- ##### PATCH
313
- Edit a template.
314
- ```Ruby
315
- client.patch_template(template_id, "edit_template_name")
316
- ```
317
-
318
- ##### DELETE
319
- Delete a template.
320
- ```Ruby
321
- client.delete_template(template_id)
322
- ```
323
-
324
- #### Versions
325
-
326
- ##### GET
327
- Retrieve a specific version of template.
328
- ```Ruby
329
- ver = client.get_version(template_id, version_id)
330
- puts ver.id
331
- puts ver.template_id
332
- puts ver.active
333
- puts ver.name
334
- puts ver.html_content
335
- puts ver.plain_content
336
- puts ver.subject
337
- puts ver.update_at
338
- ```
339
-
340
- ##### POST
341
- Create a new version
342
- ```Ruby
343
- factory = SendGrid4r::VersionFactory.new
344
- ver1 = factory.create("version1_name")
345
- ver1 = client.post_version(template_id, ver1)
346
- puts ver1.name # => "version1_name"
347
- puts ver1.subject # => "<%subject%>"
348
- puts ver1.html_content # => "<%body%>"
349
- puts ver1.plain_content # => "<%body%>"
350
- puts ver1.active # => 1
351
-
352
- ver2 = factory.create("version2_name", "<%subject%> ver2", "<%body%> ver2", "<%body%> ver2", 1)
353
- ver2 = client.post_version(template_id, ver2)
354
- ```
355
-
356
- ##### POST
357
- Activate a version.
358
- ```Ruby
359
- client.activate_version(template_id, version_id)
360
- ```
361
-
362
- ##### PATCH
363
- Edit a version.
364
- ```Ruby
365
- edit_ver = client.get_version(template_id, version_id)
366
- edit_ver.name = "edit_version"
367
- edit_ver.subject = "edit<%subject%>edit"
368
- edit_ver.html_content = "edit<%body%>edit"
369
- edit_ver.plain_content = "edit<%body%>edit"
370
- edit_ver.active = 0
371
- client.patch_version(template_id, version_id, edit_ver)
372
- ```
373
-
374
- ##### DELETE
375
- Delete a version.
376
- ```Ruby
377
- client.delete_version(template_id, version_id)
378
- ```
379
-
380
- ## Contributing
10
+ # Contributing
381
11
 
382
12
  1. Fork it ( https://github.com/[my-github-username]/sendgrid4r/fork )
383
13
  2. Create your feature branch (`git checkout -b my-new-feature`)
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
data/lib/auth.rb CHANGED
@@ -1,18 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
1
4
  module SendGrid4r
5
+ #
6
+ # SendGrid Web API v3 data container for authentication
7
+ #
2
8
  class Auth
9
+ attr_reader :username, :password
3
10
 
4
11
  def initialize(username, password)
5
12
  @username = username
6
13
  @password = password
7
14
  end
8
-
9
- def get_username
10
- @username
11
- end
12
-
13
- def get_password
14
- @password
15
- end
16
-
17
15
  end
18
16
  end
data/lib/client.rb CHANGED
@@ -1,22 +1,21 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.unshift File.dirname(__FILE__)
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
3
 
4
- require "auth"
5
- require "sendgrid4r/rest/api"
6
- require "sendgrid4r/factory/version_factory"
4
+ require 'auth'
5
+ require 'sendgrid4r/rest/api'
6
+ require 'sendgrid4r/factory/version_factory'
7
7
 
8
8
  module SendGrid4r
9
-
9
+ #
10
+ # SendGrid Web API v3 Client implementation
11
+ #
10
12
  class Client
11
-
12
13
  include SendGrid4r::REST::API
13
14
 
14
- BASE_URL = "https://api.sendgrid.com/v3"
15
+ BASE_URL = 'https://api.sendgrid.com/v3'
15
16
 
16
17
  def initialize(username, password)
17
18
  @auth = Auth.new(username, password)
18
19
  end
19
-
20
20
  end
21
-
22
21
  end
@@ -1,15 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
1
4
  module SendGrid4r
5
+ #
6
+ # SendGrid Web API v3 Factory Class implementation
7
+ #
2
8
  class VersionFactory
3
-
4
- def create(name, subject = "<%subject%>", html_content = "<%body%>", plain_content = "<%body%>", active = 1)
5
- ver = SendGrid4r::REST::Templates::Version.new()
6
- ver.name = name
7
- ver.subject = subject
8
- ver.html_content = html_content
9
- ver.plain_content = plain_content
10
- ver.active = active
11
- ver
9
+ def create(
10
+ name:, subject: '<%subject%>',
11
+ html_content: '<%body%>', plain_content: '<%body%>', active: 1)
12
+ SendGrid4r::REST::Templates::Version.new(
13
+ nil,
14
+ nil,
15
+ nil,
16
+ active,
17
+ name,
18
+ html_content,
19
+ plain_content,
20
+ subject,
21
+ nil
22
+ )
12
23
  end
13
-
14
24
  end
15
25
  end
@@ -1,15 +1,28 @@
1
- require "sendgrid4r/rest/templates"
2
- require "sendgrid4r/rest/versions"
3
- require "sendgrid4r/rest/groups"
4
- require "sendgrid4r/rest/suppressions"
5
- require "sendgrid4r/rest/global_suppressions"
6
- require "sendgrid4r/rest/enforced_tls"
7
- require "sendgrid4r/rest/addresses"
8
- require "sendgrid4r/rest/pools"
9
- require "sendgrid4r/rest/warmup"
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ require 'sendgrid4r/rest/templates/templates'
5
+ require 'sendgrid4r/rest/templates/versions'
6
+ require 'sendgrid4r/rest/asm/groups'
7
+ require 'sendgrid4r/rest/asm/suppressions'
8
+ require 'sendgrid4r/rest/asm/global_suppressions'
9
+ require 'sendgrid4r/rest/settings/enforced_tls'
10
+ require 'sendgrid4r/rest/ips/addresses'
11
+ require 'sendgrid4r/rest/ips/pools'
12
+ require 'sendgrid4r/rest/ips/warmup'
13
+ require 'sendgrid4r/rest/categories/categories'
14
+ require 'sendgrid4r/rest/stats/stats'
15
+ require 'sendgrid4r/rest/stats/global'
16
+ require 'sendgrid4r/rest/stats/category'
17
+ require 'sendgrid4r/rest/stats/subuser'
18
+ require 'sendgrid4r/rest/stats/advanced'
19
+ require 'sendgrid4r/rest/stats/parse'
10
20
 
11
21
  module SendGrid4r
12
22
  module REST
23
+ #
24
+ # SendGrid Web API v3
25
+ #
13
26
  module API
14
27
  include SendGrid4r::REST::Templates
15
28
  include SendGrid4r::REST::Templates::Versions
@@ -20,6 +33,12 @@ module SendGrid4r
20
33
  include SendGrid4r::REST::Ips::Addresses
21
34
  include SendGrid4r::REST::Ips::Warmup
22
35
  include SendGrid4r::REST::Ips::Pools
36
+ include SendGrid4r::REST::Categories::Categories
37
+ include SendGrid4r::REST::Stats::Global
38
+ include SendGrid4r::REST::Stats::Category
39
+ include SendGrid4r::REST::Stats::Subuser
40
+ include SendGrid4r::REST::Stats::Advanced
41
+ include SendGrid4r::REST::Stats::Parse
23
42
  end
24
43
  end
25
44
  end
@@ -0,0 +1,46 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ require 'sendgrid4r/rest/request'
5
+
6
+ module SendGrid4r
7
+ module REST
8
+ module Asm
9
+ #
10
+ # SendGrid Web API v3 Advanced Suppression Manager - Global Suppressions
11
+ #
12
+ module GlobalSuppressions
13
+ include SendGrid4r::REST::Request
14
+
15
+ def self.url(email_address = nil)
16
+ url = "#{SendGrid4r::Client::BASE_URL}/asm/suppressions/global"
17
+ url = "#{url}/#{email_address}" unless email_address.nil?
18
+ url
19
+ end
20
+
21
+ def post_global_suppressed_emails(recipient_emails)
22
+ params = { recipient_emails: recipient_emails }
23
+ resp = post(
24
+ @auth,
25
+ SendGrid4r::REST::Asm::GlobalSuppressions.url,
26
+ params
27
+ )
28
+ resp['recipient_emails']
29
+ end
30
+
31
+ def get_global_suppressed_email(email_address)
32
+ resp = get(
33
+ @auth,
34
+ SendGrid4r::REST::Asm::GlobalSuppressions.url(email_address)
35
+ )
36
+ resp['recipient_email']
37
+ end
38
+
39
+ def delete_global_suppressed_email(email_address)
40
+ delete(
41
+ @auth, SendGrid4r::REST::Asm::GlobalSuppressions.url(email_address))
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,69 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ require 'sendgrid4r/rest/request'
5
+
6
+ module SendGrid4r
7
+ module REST
8
+ module Asm
9
+ #
10
+ # SendGrid Web API v3 Advanced Suppression Manager - Groups
11
+ #
12
+ module Groups
13
+ include SendGrid4r::REST::Request
14
+
15
+ Group = Struct.new(
16
+ :id, :name, :description, :last_email_sent_at, :unsubscribes)
17
+
18
+ def self.create_group(resp)
19
+ Group.new(
20
+ resp['id'],
21
+ resp['name'],
22
+ resp['description'],
23
+ resp['last_email_sent_at'],
24
+ resp['unsubscribes']
25
+ )
26
+ end
27
+
28
+ def post_group(name, description)
29
+ params = { name: name, description: description }
30
+ resp = post(
31
+ @auth, "#{SendGrid4r::Client::BASE_URL}/asm/groups", params
32
+ )
33
+ SendGrid4r::REST::Asm::Groups.create_group(resp)
34
+ end
35
+
36
+ def get_groups
37
+ resp_a = get(@auth, "#{SendGrid4r::Client::BASE_URL}/asm/groups")
38
+ groups = []
39
+ resp_a.each do |resp|
40
+ groups.push(SendGrid4r::REST::Asm::Groups.create_group(resp))
41
+ end
42
+ groups
43
+ end
44
+
45
+ def get_group(group_id)
46
+ resp = get(
47
+ @auth, "#{SendGrid4r::Client::BASE_URL}/asm/groups/#{group_id}"
48
+ )
49
+ SendGrid4r::REST::Asm::Groups.create_group(resp)
50
+ end
51
+
52
+ def patch_group(group_id, group)
53
+ resp = patch(
54
+ @auth,
55
+ "#{SendGrid4r::Client::BASE_URL}/asm/groups/#{group_id}",
56
+ group.to_h
57
+ )
58
+ SendGrid4r::REST::Asm::Groups.create_group(resp)
59
+ end
60
+
61
+ def delete_group(group_id)
62
+ delete(
63
+ @auth, "#{SendGrid4r::Client::BASE_URL}/asm/groups/#{group_id}"
64
+ )
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end