sendgrid4r 1.6.0 → 1.7.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.
- checksums.yaml +4 -4
- data/lib/sendgrid4r/rest/api.rb +7 -4
- data/lib/sendgrid4r/rest/blocks.rb +80 -0
- data/lib/sendgrid4r/rest/invalid_emails.rb +81 -0
- data/lib/sendgrid4r/rest/sm/global_unsubscribes.rb +75 -0
- data/lib/sendgrid4r/rest/{asm → sm}/groups.rb +12 -12
- data/lib/sendgrid4r/rest/{asm/asm.rb → sm/sm.rb} +2 -2
- data/lib/sendgrid4r/rest/{asm → sm}/suppressions.rb +9 -9
- data/lib/sendgrid4r/rest/spam_reports.rb +81 -0
- data/lib/sendgrid4r/version.rb +1 -1
- data/lib/sendgrid4r.rb +7 -4
- data/spec/client_spec.rb +26 -3
- data/spec/rest/blocks_spec.rb +162 -0
- data/spec/rest/invalid_emails_spec.rb +173 -0
- data/spec/rest/{asm/global_suppressions_spec.rb → sm/global_unsubscribes_spec.rb} +18 -3
- data/spec/rest/{asm → sm}/groups_spec.rb +10 -10
- data/spec/rest/{asm/asm_spec.rb → sm/sm_spec.rb} +5 -5
- data/spec/rest/{asm → sm}/suppressions_spec.rb +8 -8
- data/spec/rest/spam_reports_spec.rb +163 -0
- metadata +23 -14
- data/lib/sendgrid4r/rest/asm/global_suppressions.rb +0 -40
@@ -0,0 +1,163 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
3
|
+
|
4
|
+
describe SendGrid4r::REST::SpamReports do
|
5
|
+
describe 'integration test', :it do
|
6
|
+
before do
|
7
|
+
begin
|
8
|
+
Dotenv.load
|
9
|
+
@client = SendGrid4r::Client.new(api_key: ENV['SILVER_API_KEY'])
|
10
|
+
@emails = [
|
11
|
+
'a1@spam_report.com', 'a2@spam_report.com', 'a3@spam_report.com'
|
12
|
+
]
|
13
|
+
rescue RestClient::ExceptionWithResponse => e
|
14
|
+
puts e.inspect
|
15
|
+
raise e
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'without block call' do
|
20
|
+
it '#get_spam_reports' do
|
21
|
+
begin
|
22
|
+
start_time = Time.now - 60 * 60 * 24 * 365
|
23
|
+
end_time = Time.now
|
24
|
+
spam_reports = @client.get_spam_reports(
|
25
|
+
start_time: start_time, end_time: end_time
|
26
|
+
)
|
27
|
+
expect(spam_reports).to be_a(Array)
|
28
|
+
spam_reports.each do |spam_report|
|
29
|
+
expect(spam_report).to be_a(
|
30
|
+
SendGrid4r::REST::SpamReports::SpamReport
|
31
|
+
)
|
32
|
+
end
|
33
|
+
rescue RestClient::ExceptionWithResponse => e
|
34
|
+
puts e.inspect
|
35
|
+
raise e
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it '#delete_spam_reports(delete_all: true)' do
|
40
|
+
begin
|
41
|
+
@client.delete_spam_reports(delete_all: true)
|
42
|
+
rescue RestClient::ExceptionWithResponse => e
|
43
|
+
puts e.inspect
|
44
|
+
raise e
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it '#delete_spam_reports(emails: [])' do
|
49
|
+
begin
|
50
|
+
@client.delete_spam_reports(emails: @emails)
|
51
|
+
rescue RestClient::ExceptionWithResponse => e
|
52
|
+
puts e.inspect
|
53
|
+
raise e
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it '#get_spam_report' do
|
58
|
+
begin
|
59
|
+
spam_report = @client.get_spam_report(email: @email)
|
60
|
+
expect(spam_report).to be_a(Array)
|
61
|
+
rescue RestClient::ExceptionWithResponse => e
|
62
|
+
puts e.inspect
|
63
|
+
raise e
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it '#delete_spam_report' do
|
68
|
+
begin
|
69
|
+
expect do
|
70
|
+
@client.delete_spam_report(email: 'a1@spam_report.com')
|
71
|
+
end.to raise_error(RestClient::ResourceNotFound)
|
72
|
+
rescue RestClient::ExceptionWithResponse => e
|
73
|
+
puts e.inspect
|
74
|
+
raise e
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'unit test', :ut do
|
81
|
+
let(:client) do
|
82
|
+
SendGrid4r::Client.new(api_key: '')
|
83
|
+
end
|
84
|
+
|
85
|
+
let(:spam_reports) do
|
86
|
+
JSON.parse(
|
87
|
+
'['\
|
88
|
+
'{'\
|
89
|
+
'"created": 1443651141,'\
|
90
|
+
'"email": "user1@example.com",'\
|
91
|
+
'"ip": "10.63.202.100"'\
|
92
|
+
'},'\
|
93
|
+
'{'\
|
94
|
+
'"created": 1443651154,'\
|
95
|
+
'"email": "user2@example.com",'\
|
96
|
+
'"ip": "10.63.202.100"'\
|
97
|
+
'}'\
|
98
|
+
']'
|
99
|
+
)
|
100
|
+
end
|
101
|
+
|
102
|
+
let(:spam_report) do
|
103
|
+
JSON.parse(
|
104
|
+
'{'\
|
105
|
+
'"created": 1454433146,'\
|
106
|
+
'"email": "test1@example.com",'\
|
107
|
+
'"ip": "10.89.32.5"'\
|
108
|
+
'}'
|
109
|
+
)
|
110
|
+
end
|
111
|
+
|
112
|
+
it '#get_spam_reports' do
|
113
|
+
allow(client).to receive(:execute).and_return(spam_reports)
|
114
|
+
actual = client.get_spam_reports
|
115
|
+
expect(actual).to be_a(Array)
|
116
|
+
actual.each do |spam_report|
|
117
|
+
expect(spam_report).to be_a(SendGrid4r::REST::SpamReports::SpamReport)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
it '#delete_spam_reports(delete_all: true)' do
|
122
|
+
allow(client).to receive(:execute).and_return('')
|
123
|
+
client.delete_spam_reports(delete_all: true)
|
124
|
+
end
|
125
|
+
|
126
|
+
it '#delete_spam_reports(emails: [])' do
|
127
|
+
allow(client).to receive(:execute).and_return('')
|
128
|
+
actual = client.delete_spam_reports(emails: [])
|
129
|
+
expect(actual).to eq('')
|
130
|
+
end
|
131
|
+
|
132
|
+
it '#get_spam_report' do
|
133
|
+
allow(client).to receive(:execute).and_return(spam_reports)
|
134
|
+
actual = client.get_spam_report(email: '')
|
135
|
+
expect(actual).to be_a(Array)
|
136
|
+
actual.each do |spam_report|
|
137
|
+
expect(spam_report).to be_a(SendGrid4r::REST::SpamReports::SpamReport)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
it '#delete_spam_report' do
|
142
|
+
allow(client).to receive(:execute).and_return('')
|
143
|
+
actual = client.delete_spam_report(email: '')
|
144
|
+
expect(actual).to eq('')
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'creates spam_reports instance' do
|
148
|
+
actual = SendGrid4r::REST::SpamReports.create_spam_reports(spam_reports)
|
149
|
+
expect(actual).to be_a(Array)
|
150
|
+
actual.each do |subuser|
|
151
|
+
expect(subuser).to be_a(SendGrid4r::REST::SpamReports::SpamReport)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'creates spam_report instance' do
|
156
|
+
actual = SendGrid4r::REST::SpamReports.create_spam_report(spam_report)
|
157
|
+
expect(actual).to be_a(SendGrid4r::REST::SpamReports::SpamReport)
|
158
|
+
expect(actual.created).to eq(Time.at(1454433146))
|
159
|
+
expect(actual.email).to eq('test1@example.com')
|
160
|
+
expect(actual.ip).to eq('10.89.32.5')
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendgrid4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- awwa500@gmail.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -129,10 +129,7 @@ files:
|
|
129
129
|
- lib/sendgrid4r/rest/api.rb
|
130
130
|
- lib/sendgrid4r/rest/api_keys/api_keys.rb
|
131
131
|
- lib/sendgrid4r/rest/api_keys/permissions.rb
|
132
|
-
- lib/sendgrid4r/rest/
|
133
|
-
- lib/sendgrid4r/rest/asm/global_suppressions.rb
|
134
|
-
- lib/sendgrid4r/rest/asm/groups.rb
|
135
|
-
- lib/sendgrid4r/rest/asm/suppressions.rb
|
132
|
+
- lib/sendgrid4r/rest/blocks.rb
|
136
133
|
- lib/sendgrid4r/rest/bounces.rb
|
137
134
|
- lib/sendgrid4r/rest/campaigns/campaigns.rb
|
138
135
|
- lib/sendgrid4r/rest/cancel_scheduled_sends.rb
|
@@ -143,6 +140,7 @@ files:
|
|
143
140
|
- lib/sendgrid4r/rest/contacts/reserved_fields.rb
|
144
141
|
- lib/sendgrid4r/rest/contacts/segments.rb
|
145
142
|
- lib/sendgrid4r/rest/email_activity/email_activity.rb
|
143
|
+
- lib/sendgrid4r/rest/invalid_emails.rb
|
146
144
|
- lib/sendgrid4r/rest/ip_access_management.rb
|
147
145
|
- lib/sendgrid4r/rest/ips/addresses.rb
|
148
146
|
- lib/sendgrid4r/rest/ips/pools.rb
|
@@ -153,6 +151,11 @@ files:
|
|
153
151
|
- lib/sendgrid4r/rest/settings/partner.rb
|
154
152
|
- lib/sendgrid4r/rest/settings/settings.rb
|
155
153
|
- lib/sendgrid4r/rest/settings/tracking.rb
|
154
|
+
- lib/sendgrid4r/rest/sm/global_unsubscribes.rb
|
155
|
+
- lib/sendgrid4r/rest/sm/groups.rb
|
156
|
+
- lib/sendgrid4r/rest/sm/sm.rb
|
157
|
+
- lib/sendgrid4r/rest/sm/suppressions.rb
|
158
|
+
- lib/sendgrid4r/rest/spam_reports.rb
|
156
159
|
- lib/sendgrid4r/rest/stats/advanced.rb
|
157
160
|
- lib/sendgrid4r/rest/stats/category.rb
|
158
161
|
- lib/sendgrid4r/rest/stats/global.rb
|
@@ -177,10 +180,7 @@ files:
|
|
177
180
|
- spec/factory/version_factory_spec.rb
|
178
181
|
- spec/rest/api_keys/api_keys_spec.rb
|
179
182
|
- spec/rest/api_keys/permissions_spec.rb
|
180
|
-
- spec/rest/
|
181
|
-
- spec/rest/asm/global_suppressions_spec.rb
|
182
|
-
- spec/rest/asm/groups_spec.rb
|
183
|
-
- spec/rest/asm/suppressions_spec.rb
|
183
|
+
- spec/rest/blocks_spec.rb
|
184
184
|
- spec/rest/bounces_spec.rb
|
185
185
|
- spec/rest/campaigns/campaigns_spec.rb
|
186
186
|
- spec/rest/cancel_scheduled_sends_spec.rb
|
@@ -191,6 +191,7 @@ files:
|
|
191
191
|
- spec/rest/contacts/reserved_fields_spec.rb
|
192
192
|
- spec/rest/contacts/segments_spec.rb
|
193
193
|
- spec/rest/email_activity/email_activity_spec.rb
|
194
|
+
- spec/rest/invalid_emails_spec.rb
|
194
195
|
- spec/rest/ip_access_management_spec.rb
|
195
196
|
- spec/rest/ips/addresses_spec.rb
|
196
197
|
- spec/rest/ips/pools_spec.rb
|
@@ -200,6 +201,11 @@ files:
|
|
200
201
|
- spec/rest/settings/partner_spec.rb
|
201
202
|
- spec/rest/settings/settings_spec.rb
|
202
203
|
- spec/rest/settings/tracking_spec.rb
|
204
|
+
- spec/rest/sm/global_unsubscribes_spec.rb
|
205
|
+
- spec/rest/sm/groups_spec.rb
|
206
|
+
- spec/rest/sm/sm_spec.rb
|
207
|
+
- spec/rest/sm/suppressions_spec.rb
|
208
|
+
- spec/rest/spam_reports_spec.rb
|
203
209
|
- spec/rest/stats/advanced_spec.rb
|
204
210
|
- spec/rest/stats/category_spec.rb
|
205
211
|
- spec/rest/stats/global_spec.rb
|
@@ -248,10 +254,7 @@ test_files:
|
|
248
254
|
- spec/factory/version_factory_spec.rb
|
249
255
|
- spec/rest/api_keys/api_keys_spec.rb
|
250
256
|
- spec/rest/api_keys/permissions_spec.rb
|
251
|
-
- spec/rest/
|
252
|
-
- spec/rest/asm/global_suppressions_spec.rb
|
253
|
-
- spec/rest/asm/groups_spec.rb
|
254
|
-
- spec/rest/asm/suppressions_spec.rb
|
257
|
+
- spec/rest/blocks_spec.rb
|
255
258
|
- spec/rest/bounces_spec.rb
|
256
259
|
- spec/rest/campaigns/campaigns_spec.rb
|
257
260
|
- spec/rest/cancel_scheduled_sends_spec.rb
|
@@ -262,6 +265,7 @@ test_files:
|
|
262
265
|
- spec/rest/contacts/reserved_fields_spec.rb
|
263
266
|
- spec/rest/contacts/segments_spec.rb
|
264
267
|
- spec/rest/email_activity/email_activity_spec.rb
|
268
|
+
- spec/rest/invalid_emails_spec.rb
|
265
269
|
- spec/rest/ip_access_management_spec.rb
|
266
270
|
- spec/rest/ips/addresses_spec.rb
|
267
271
|
- spec/rest/ips/pools_spec.rb
|
@@ -271,6 +275,11 @@ test_files:
|
|
271
275
|
- spec/rest/settings/partner_spec.rb
|
272
276
|
- spec/rest/settings/settings_spec.rb
|
273
277
|
- spec/rest/settings/tracking_spec.rb
|
278
|
+
- spec/rest/sm/global_unsubscribes_spec.rb
|
279
|
+
- spec/rest/sm/groups_spec.rb
|
280
|
+
- spec/rest/sm/sm_spec.rb
|
281
|
+
- spec/rest/sm/suppressions_spec.rb
|
282
|
+
- spec/rest/spam_reports_spec.rb
|
274
283
|
- spec/rest/stats/advanced_spec.rb
|
275
284
|
- spec/rest/stats/category_spec.rb
|
276
285
|
- spec/rest/stats/global_spec.rb
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
module SendGrid4r
|
4
|
-
module REST
|
5
|
-
module Asm
|
6
|
-
#
|
7
|
-
# SendGrid Web API v3 Advanced Suppression Manager - Global Suppressions
|
8
|
-
#
|
9
|
-
module GlobalSuppressions
|
10
|
-
include SendGrid4r::REST::Request
|
11
|
-
|
12
|
-
def self.url(email_address = nil)
|
13
|
-
url = "#{BASE_URL}/asm/suppressions/global"
|
14
|
-
url = "#{url}/#{email_address}" unless email_address.nil?
|
15
|
-
url
|
16
|
-
end
|
17
|
-
|
18
|
-
def post_global_suppressed_emails(recipient_emails:, &block)
|
19
|
-
params = { recipient_emails: recipient_emails }
|
20
|
-
endpoint = SendGrid4r::REST::Asm::GlobalSuppressions.url
|
21
|
-
resp = post(@auth, endpoint, params, &block)
|
22
|
-
SendGrid4r::REST::Asm.create_recipient_emails(resp)
|
23
|
-
end
|
24
|
-
|
25
|
-
def get_global_suppressed_email(email_address:, &block)
|
26
|
-
endpoint =
|
27
|
-
SendGrid4r::REST::Asm::GlobalSuppressions.url(email_address)
|
28
|
-
resp = get(@auth, endpoint, &block)
|
29
|
-
SendGrid4r::REST::Asm.create_recipient_email(resp)
|
30
|
-
end
|
31
|
-
|
32
|
-
def delete_global_suppressed_email(email_address:, &block)
|
33
|
-
endpoint =
|
34
|
-
SendGrid4r::REST::Asm::GlobalSuppressions.url(email_address)
|
35
|
-
delete(@auth, endpoint, &block)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|