sendgrid4r 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.env.example +2 -0
- data/.gitignore +23 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +324 -0
- data/Rakefile +1 -0
- data/lib/auth.rb +18 -0
- data/lib/client.rb +22 -0
- data/lib/sendgrid4r/factory/version_factory.rb +15 -0
- data/lib/sendgrid4r/rest/api.rb +23 -0
- data/lib/sendgrid4r/rest/enforced_tls.rb +47 -0
- data/lib/sendgrid4r/rest/global_suppressions.rb +35 -0
- data/lib/sendgrid4r/rest/groups.rb +69 -0
- data/lib/sendgrid4r/rest/ip_addresses.rb +46 -0
- data/lib/sendgrid4r/rest/request.rb +42 -0
- data/lib/sendgrid4r/rest/suppressions.rb +58 -0
- data/lib/sendgrid4r/rest/templates.rb +64 -0
- data/lib/sendgrid4r/rest/versions.rb +66 -0
- data/lib/sendgrid4r/rest/warmup.rb +53 -0
- data/lib/sendgrid4r/version.rb +3 -0
- data/lib/sendgrid4r.rb +2 -0
- data/sendgrid4r.gemspec +25 -0
- data/spec/client_spec.rb +68 -0
- data/spec/enforced_tls_spec.rb +38 -0
- data/spec/global_suppressions_spec.rb +49 -0
- data/spec/groups_spec.rb +63 -0
- data/spec/ip_addresses_spec.rb +25 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/suppressions_spec.rb +75 -0
- data/spec/templates_spec.rb +53 -0
- data/spec/version_factory_spec.rb +37 -0
- data/spec/versions_spec.rb +90 -0
- data/spec/warmup_spec.rb +52 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 568b1050de08f8eca17e627d9a39b1b8e23225a9
|
4
|
+
data.tar.gz: b38ba6b0a6745268940558d8416ac29be5365d00
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29e018b98d2356945f6a003fbdf768a04886a65cee01402c0ba14e6023d414ca05af0c3acec11ed7947607ac1a3533d764b8999fe14fce0e186e4284e5e70df2
|
7
|
+
data.tar.gz: 9c841443a41546dfa7f77bfd1c3b82f37c93170672467958fe2cfbb0b6c96e62695cad154d38c7423baebc3ae0076680c4243cc3693d20dc3d5958121738e820
|
data/.env.example
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
.env
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 awwa500@gmail.com
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,324 @@
|
|
1
|
+
# Sendgrid4r
|
2
|
+
|
3
|
+
This gem allows you to quickly and easily access to SendGrid Web API v3 for Ruby.
|
4
|
+
See [api reference](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) for more detail
|
5
|
+
|
6
|
+
[](https://travis-ci.org/awwa/sendgrid_template_engine_ruby.svg?branch=master)
|
7
|
+
|
8
|
+
## Installation
|
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
|
+
Get all groups.
|
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 the 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 suppression group.
|
64
|
+
```Ruby
|
65
|
+
new_group = client.post_group("group_name", "group_desc")
|
66
|
+
```
|
67
|
+
|
68
|
+
##### PATCH
|
69
|
+
Edit the 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 the 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(group.id)
|
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_group(group.id)
|
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 warm up status.
|
144
|
+
```Ruby
|
145
|
+
ips = client.get_ips
|
146
|
+
ips.each{|ip|
|
147
|
+
puts ip.ip # => "xxx.xxx.xxx.xxx"
|
148
|
+
puts ip.warmup # => true/false
|
149
|
+
puts ip.start_date # => 1409616000
|
150
|
+
}
|
151
|
+
```
|
152
|
+
|
153
|
+
#### IP Warmup
|
154
|
+
|
155
|
+
##### GET
|
156
|
+
Get all IPs that are currently warming up.
|
157
|
+
```Ruby
|
158
|
+
warmup_ips = client.get_warmup_ips
|
159
|
+
warmup_ips.each{|warmup_ip|
|
160
|
+
puts warmup_ip.ip # => "xxx.xxx.xxx.xxx"
|
161
|
+
puts warmup_ip.start_date # => 1409616000
|
162
|
+
}
|
163
|
+
```
|
164
|
+
|
165
|
+
##### GET
|
166
|
+
Get warmup status for a particular IP.
|
167
|
+
```Ruby
|
168
|
+
warmup_ip = client.get_warmup_ip("xxx.xxx.xxx.xxx")
|
169
|
+
puts warmup_ip.ip # => "xxx.xxx.xxx.xxx"
|
170
|
+
puts warmup_ip.start_date # => 1409616000
|
171
|
+
```
|
172
|
+
|
173
|
+
##### POST
|
174
|
+
Add an IP to warmup.
|
175
|
+
```Ruby
|
176
|
+
client.post_warmup_ip("xxx.xxx.xxx.xxx")
|
177
|
+
```
|
178
|
+
|
179
|
+
##### DELETE
|
180
|
+
Remove an IP from warmup.
|
181
|
+
```Ruby
|
182
|
+
client.delete_warmup_ip("xxx.xxx.xxx.xxx")
|
183
|
+
```
|
184
|
+
|
185
|
+
----
|
186
|
+
### Settings
|
187
|
+
|
188
|
+
#### Enforced TLS
|
189
|
+
|
190
|
+
##### GET
|
191
|
+
Get the current Enforced TLS settings.
|
192
|
+
```Ruby
|
193
|
+
enforced_tls = client.get_enforced_tls
|
194
|
+
puts enforced_tls.require_tls # => true/false
|
195
|
+
puts enforced_tls.require_valid_cert # => true/false
|
196
|
+
```
|
197
|
+
|
198
|
+
##### PATCH
|
199
|
+
Change the Enforced TLS settings.
|
200
|
+
```Ruby
|
201
|
+
enforced_tls = client.get_enforced_tls
|
202
|
+
enforced_tls.require_tls = true
|
203
|
+
enforced_tls.require_valid_cert = true
|
204
|
+
client.patch_enforced_tls(enforced_tls)
|
205
|
+
```
|
206
|
+
|
207
|
+
----
|
208
|
+
### Template Engine
|
209
|
+
|
210
|
+
#### Templates
|
211
|
+
|
212
|
+
##### GET
|
213
|
+
Retrieve all templates.
|
214
|
+
```Ruby
|
215
|
+
templates = client.get_templates
|
216
|
+
templates.each {|template|
|
217
|
+
puts template.id
|
218
|
+
puts template.name
|
219
|
+
template.versions.each {|ver|
|
220
|
+
puts ver.id
|
221
|
+
puts ver.template_id
|
222
|
+
puts ver.active
|
223
|
+
puts ver.name
|
224
|
+
puts ver.updated_at
|
225
|
+
}
|
226
|
+
}
|
227
|
+
```
|
228
|
+
|
229
|
+
##### GET
|
230
|
+
Retrieve a single template
|
231
|
+
```Ruby
|
232
|
+
template = client.get_template(template_id)
|
233
|
+
puts template.id
|
234
|
+
puts template.name
|
235
|
+
template.versions.each {|ver|
|
236
|
+
puts ver.id
|
237
|
+
puts ver.template_id
|
238
|
+
puts ver.active
|
239
|
+
puts ver.name
|
240
|
+
puts ver.updated_at
|
241
|
+
}
|
242
|
+
```
|
243
|
+
|
244
|
+
##### POST
|
245
|
+
Create a template
|
246
|
+
```Ruby
|
247
|
+
client.post_template("new_template_name")
|
248
|
+
```
|
249
|
+
|
250
|
+
##### PATCH
|
251
|
+
Edit a template.
|
252
|
+
```Ruby
|
253
|
+
client.patch_template(template_id, "edit_template_name")
|
254
|
+
```
|
255
|
+
|
256
|
+
##### DELETE
|
257
|
+
Delete a template.
|
258
|
+
```Ruby
|
259
|
+
client.delete_template(template_id)
|
260
|
+
```
|
261
|
+
|
262
|
+
#### Versions
|
263
|
+
|
264
|
+
##### GET
|
265
|
+
Retrieve a specific version of template.
|
266
|
+
```Ruby
|
267
|
+
ver = client.get_version(template_id, version_id)
|
268
|
+
puts ver.id
|
269
|
+
puts ver.template_id
|
270
|
+
puts ver.active
|
271
|
+
puts ver.name
|
272
|
+
puts ver.html_content
|
273
|
+
puts ver.plain_content
|
274
|
+
puts ver.subject
|
275
|
+
puts ver.update_at
|
276
|
+
```
|
277
|
+
|
278
|
+
##### POST
|
279
|
+
Create a new version
|
280
|
+
```Ruby
|
281
|
+
factory = SendGrid4r::VersionFactory.new
|
282
|
+
ver1 = factory.create("version1_name")
|
283
|
+
ver1 = client.post_version(template_id, ver1)
|
284
|
+
puts ver1.name # => "version1_name"
|
285
|
+
puts ver1.subject # => "<%subject%>"
|
286
|
+
puts ver1.html_content # => "<%body%>"
|
287
|
+
puts ver1.plain_content # => "<%body%>"
|
288
|
+
puts ver1.active # => 1
|
289
|
+
|
290
|
+
ver2 = factory.create("version2_name", "<%subject%> ver2", "<%body%> ver2", "<%body%> ver2", 1)
|
291
|
+
ver2 = client.post_version(template_id, ver2)
|
292
|
+
```
|
293
|
+
|
294
|
+
##### POST
|
295
|
+
Activate a version.
|
296
|
+
```Ruby
|
297
|
+
client.activate_version(template_id, version_id)
|
298
|
+
```
|
299
|
+
|
300
|
+
##### PATCH
|
301
|
+
Edit a version.
|
302
|
+
```Ruby
|
303
|
+
edit_ver = client.get_version(template_id, version_id)
|
304
|
+
edit_ver.name = "edit_version"
|
305
|
+
edit_ver.subject = "edit<%subject%>edit"
|
306
|
+
edit_ver.html_content = "edit<%body%>edit"
|
307
|
+
edit_ver.plain_content = "edit<%body%>edit"
|
308
|
+
edit_ver.active = 0
|
309
|
+
client.patch_version(template_id, version_id, edit_ver)
|
310
|
+
```
|
311
|
+
|
312
|
+
##### DELETE
|
313
|
+
Delete a version.
|
314
|
+
```Ruby
|
315
|
+
client.delete_version(template_id, version_id)
|
316
|
+
```
|
317
|
+
|
318
|
+
## Contributing
|
319
|
+
|
320
|
+
1. Fork it ( https://github.com/[my-github-username]/sendgrid4r/fork )
|
321
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
322
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
323
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
324
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/auth.rb
ADDED
data/lib/client.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.unshift File.dirname(__FILE__)
|
3
|
+
|
4
|
+
require "auth"
|
5
|
+
require "sendgrid4r/rest/api"
|
6
|
+
require "sendgrid4r/factory/version_factory"
|
7
|
+
|
8
|
+
module SendGrid4r
|
9
|
+
|
10
|
+
class Client
|
11
|
+
|
12
|
+
include SendGrid4r::REST::API
|
13
|
+
|
14
|
+
BASE_URL = "https://api.sendgrid.com/v3"
|
15
|
+
|
16
|
+
def initialize(username, password)
|
17
|
+
@auth = Auth.new(username, password)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SendGrid4r
|
2
|
+
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
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
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/ip_addresses"
|
8
|
+
require "sendgrid4r/rest/warmup"
|
9
|
+
|
10
|
+
module SendGrid4r
|
11
|
+
module REST
|
12
|
+
module API
|
13
|
+
include SendGrid4r::REST::Templates
|
14
|
+
include SendGrid4r::REST::Templates::Versions
|
15
|
+
include SendGrid4r::REST::Asm::Groups
|
16
|
+
include SendGrid4r::REST::Asm::Suppressions
|
17
|
+
include SendGrid4r::REST::Asm::GlobalSuppressions
|
18
|
+
include SendGrid4r::REST::Settings::EnforcedTls
|
19
|
+
include SendGrid4r::REST::Ips::IpAddresses
|
20
|
+
include SendGrid4r::REST::Ips::Warmup
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.unshift File.dirname(__FILE__)
|
3
|
+
|
4
|
+
require "sendgrid4r/rest/request"
|
5
|
+
|
6
|
+
module SendGrid4r
|
7
|
+
module REST
|
8
|
+
module Settings
|
9
|
+
module EnforcedTls
|
10
|
+
|
11
|
+
include SendGrid4r::REST::Request
|
12
|
+
|
13
|
+
def get_enforced_tls
|
14
|
+
response = get(@auth, "#{SendGrid4r::Client::BASE_URL}/user/settings/enforced_tls")
|
15
|
+
EnforcedTls.create(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
def patch_enforced_tls(params)
|
19
|
+
response = patch(@auth, "#{SendGrid4r::Client::BASE_URL}/user/settings/enforced_tls", params.to_hash)
|
20
|
+
EnforcedTls.create(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
class EnforcedTls
|
24
|
+
|
25
|
+
attr_accessor :require_tls, :require_valid_cert
|
26
|
+
|
27
|
+
def self.create(value)
|
28
|
+
obj = EnforcedTls.new
|
29
|
+
obj.require_tls = value["require_tls"]
|
30
|
+
obj.require_valid_cert = value["require_valid_cert"]
|
31
|
+
obj
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_hash
|
35
|
+
hash = Hash.new
|
36
|
+
hash["require_tls"] = @require_tls if @require_tls != nil
|
37
|
+
hash["require_valid_cert"] = @require_valid_cert if @require_valid_cert != nil
|
38
|
+
hash
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.unshift File.dirname(__FILE__)
|
3
|
+
|
4
|
+
require "sendgrid4r/rest/request"
|
5
|
+
|
6
|
+
module SendGrid4r
|
7
|
+
module REST
|
8
|
+
module Asm
|
9
|
+
module GlobalSuppressions
|
10
|
+
|
11
|
+
include SendGrid4r::REST::Request
|
12
|
+
|
13
|
+
def post_global_suppressed_emails(recipient_emails)
|
14
|
+
params = Hash.new
|
15
|
+
params["recipient_emails"] = recipient_emails
|
16
|
+
response = post(@auth, "#{SendGrid4r::Client::BASE_URL}/asm/suppressions/global", params.to_hash)
|
17
|
+
recipient_emails = response["recipient_emails"]
|
18
|
+
recipient_emails
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_global_suppressed_email(email_address)
|
22
|
+
response = get(@auth, "#{SendGrid4r::Client::BASE_URL}/asm/suppressions/global/#{email_address}")
|
23
|
+
email_address = response["recipient_email"]
|
24
|
+
email_address
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete_global_suppressed_email(email_address)
|
28
|
+
delete(@auth, "#{SendGrid4r::Client::BASE_URL}/asm/suppressions/global/#{email_address}")
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.unshift File.dirname(__FILE__)
|
3
|
+
|
4
|
+
require "sendgrid4r/rest/request"
|
5
|
+
|
6
|
+
module SendGrid4r
|
7
|
+
module REST
|
8
|
+
module Asm
|
9
|
+
module Groups
|
10
|
+
|
11
|
+
include SendGrid4r::REST::Request
|
12
|
+
|
13
|
+
def get_groups
|
14
|
+
response = get(@auth, "#{SendGrid4r::Client::BASE_URL}/asm/groups")
|
15
|
+
groups = Array.new
|
16
|
+
response.each{|grp|
|
17
|
+
group = Group.create(grp)
|
18
|
+
groups.push(group)
|
19
|
+
} if response.length != 0
|
20
|
+
groups
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_group(group_id)
|
24
|
+
Group.create(get(@auth, "#{SendGrid4r::Client::BASE_URL}/asm/groups/#{group_id}"))
|
25
|
+
end
|
26
|
+
|
27
|
+
def post_group(name, description)
|
28
|
+
params = Hash.new
|
29
|
+
params["name"] = name
|
30
|
+
params["description"] = description
|
31
|
+
Group.create(post(@auth, "#{SendGrid4r::Client::BASE_URL}/asm/groups", params))
|
32
|
+
end
|
33
|
+
|
34
|
+
def patch_group(group_id, group)
|
35
|
+
Group.create(patch(@auth, "#{SendGrid4r::Client::BASE_URL}/asm/groups/#{group_id}", group.to_hash))
|
36
|
+
end
|
37
|
+
|
38
|
+
def delete_group(group_id)
|
39
|
+
delete(@auth, "#{SendGrid4r::Client::BASE_URL}/asm/groups/#{group_id}")
|
40
|
+
end
|
41
|
+
|
42
|
+
class Group
|
43
|
+
|
44
|
+
attr_accessor :id, :name, :description, :last_email_sent_at, :unsubscribes
|
45
|
+
|
46
|
+
def self.create(value)
|
47
|
+
obj = Group.new
|
48
|
+
obj.id = value["id"]
|
49
|
+
obj.name = value["name"]
|
50
|
+
obj.description = value["description"]
|
51
|
+
obj.last_email_sent_at = value["last_email_sent_at"]
|
52
|
+
obj.unsubscribes = value["unsubscribes"]
|
53
|
+
obj
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_hash
|
57
|
+
hash = {
|
58
|
+
"name" => @name,
|
59
|
+
"description" => @description,
|
60
|
+
}
|
61
|
+
hash
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.unshift File.dirname(__FILE__)
|
3
|
+
|
4
|
+
require "sendgrid4r/rest/request"
|
5
|
+
|
6
|
+
module SendGrid4r
|
7
|
+
module REST
|
8
|
+
module Ips
|
9
|
+
module IpAddresses
|
10
|
+
|
11
|
+
include SendGrid4r::REST::Request
|
12
|
+
|
13
|
+
def get_ips
|
14
|
+
response = get(@auth, "#{SendGrid4r::Client::BASE_URL}/ips")
|
15
|
+
ips = Array.new
|
16
|
+
response.each{|ip|
|
17
|
+
ip_address = IpAddress.create(ip)
|
18
|
+
ips.push(ip_address)
|
19
|
+
} if response.length > 0
|
20
|
+
ips
|
21
|
+
end
|
22
|
+
|
23
|
+
class IpAddress
|
24
|
+
|
25
|
+
attr_accessor :ip, :pools, :warmup, :start_date
|
26
|
+
|
27
|
+
def self.create(value)
|
28
|
+
obj = IpAddress.new
|
29
|
+
obj.ip = value["ip"]
|
30
|
+
obj.pools = []
|
31
|
+
# TODO Implements if ip pools GA
|
32
|
+
# value["pools"].each{|pool|
|
33
|
+
# ver = Pool.create(pool)
|
34
|
+
# obj.pools.push(ver)
|
35
|
+
# }
|
36
|
+
obj.warmup = value["warmup"]
|
37
|
+
obj.start_date = value["start_date"]
|
38
|
+
obj
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|