sendgrid4r 1.12.0 → 1.13.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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/README.md +2 -1
  4. data/lib/sendgrid4r/cli/alert.rb +51 -0
  5. data/lib/sendgrid4r/cli/campaign/campaign.rb +2 -2
  6. data/lib/sendgrid4r/cli/campaign/contact/custom_field.rb +1 -1
  7. data/lib/sendgrid4r/cli/campaign/contact/list.rb +1 -1
  8. data/lib/sendgrid4r/cli/campaign/contact/recipient.rb +2 -2
  9. data/lib/sendgrid4r/cli/campaign/contact/segment.rb +12 -3
  10. data/lib/sendgrid4r/cli/ipam/whitelist.rb +1 -1
  11. data/lib/sendgrid4r/cli/settings/enforced_tls.rb +2 -2
  12. data/lib/sendgrid4r/cli/settings/mail.rb +33 -9
  13. data/lib/sendgrid4r/cli/settings/partner.rb +4 -1
  14. data/lib/sendgrid4r/cli/settings/tracking.rb +13 -4
  15. data/lib/sendgrid4r/cli/sg.rb +16 -10
  16. data/lib/sendgrid4r/cli/sg_thor.rb +27 -11
  17. data/lib/sendgrid4r/cli/stats/advanced.rb +22 -20
  18. data/lib/sendgrid4r/cli/stats/category.rb +8 -8
  19. data/lib/sendgrid4r/cli/stats/global.rb +3 -3
  20. data/lib/sendgrid4r/cli/stats/parse.rb +3 -3
  21. data/lib/sendgrid4r/cli/stats/subuser.rb +10 -10
  22. data/lib/sendgrid4r/cli/suppressions/block.rb +2 -2
  23. data/lib/sendgrid4r/cli/suppressions/bounce.rb +2 -2
  24. data/lib/sendgrid4r/cli/suppressions/global_unsubscribe.rb +2 -2
  25. data/lib/sendgrid4r/cli/suppressions/group.rb +6 -1
  26. data/lib/sendgrid4r/cli/suppressions/group_unsubscribe.rb +9 -0
  27. data/lib/sendgrid4r/cli/suppressions/invalid_email.rb +2 -2
  28. data/lib/sendgrid4r/cli/suppressions/spam_report.rb +2 -2
  29. data/lib/sendgrid4r/cli/templates/version.rb +2 -2
  30. data/lib/sendgrid4r/cli/user.rb +5 -5
  31. data/lib/sendgrid4r/cli/webhooks/parse.rb +42 -2
  32. data/lib/sendgrid4r/cli/whitelabel/domain.rb +3 -3
  33. data/lib/sendgrid4r/cli/whitelabel/link.rb +2 -2
  34. data/lib/sendgrid4r/rest/alerts.rb +81 -0
  35. data/lib/sendgrid4r/rest/api.rb +1 -0
  36. data/lib/sendgrid4r/rest/blocks.rb +2 -4
  37. data/lib/sendgrid4r/rest/bounces.rb +2 -4
  38. data/lib/sendgrid4r/rest/invalid_emails.rb +2 -4
  39. data/lib/sendgrid4r/rest/request.rb +10 -6
  40. data/lib/sendgrid4r/rest/sm/groups.rb +3 -2
  41. data/lib/sendgrid4r/rest/sm/suppressions.rb +61 -14
  42. data/lib/sendgrid4r/rest/spam_reports.rb +2 -4
  43. data/lib/sendgrid4r/rest/webhooks/parse.rb +47 -6
  44. data/lib/sendgrid4r/version.rb +1 -1
  45. data/lib/sendgrid4r.rb +3 -0
  46. data/spec/cli/alert_spec.rb +71 -0
  47. data/spec/cli/sg_spec.rb +5 -0
  48. data/spec/cli/suppressions/group_spec.rb +11 -2
  49. data/spec/cli/suppressions/group_unsubscribe_spec.rb +12 -2
  50. data/spec/cli/webhooks/parse_spec.rb +53 -1
  51. data/spec/client_spec.rb +17 -1
  52. data/spec/rest/alerts_spec.rb +188 -0
  53. data/spec/rest/mail/mail_spec.rb +10 -10
  54. data/spec/rest/request_spec.rb +41 -0
  55. data/spec/rest/sm/groups_spec.rb +9 -0
  56. data/spec/rest/sm/suppressions_spec.rb +122 -35
  57. data/spec/rest/webhooks/parse_spec.rb +94 -7
  58. metadata +10 -2
@@ -43,20 +43,38 @@ module SendGrid4r::REST::Sm
43
43
  expect(emails.recipient_emails[1]).to eq(@email3)
44
44
  end
45
45
 
46
+ it '#search_suppressed_emails' do
47
+ emails = @client.search_suppressed_emails(
48
+ group_id: @group.id, recipient_emails: [@email1]
49
+ )
50
+ expect(emails.length).to eq(1)
51
+ expect(emails[0]).to eq(@email1)
52
+ end
53
+
46
54
  it '#get_suppressed_emails' do
47
55
  emails = @client.get_suppressed_emails(group_id: @group.id)
48
56
  expect(emails.length).to eq(1)
49
57
  expect(emails[0]).to eq(@email1)
50
58
  end
51
59
 
60
+ it '#get_groups_by_email' do
61
+ groups = @client.get_groups_by_email(email_address: @email1)
62
+ expect(groups.suppressions).to be_a(Array)
63
+ groups.suppressions.each do |group|
64
+ next unless group.name == @group_name
65
+ expect(group.id).to eq(@group.id)
66
+ expect(group.name).to eq(@group_name)
67
+ expect(group.description).to eq(@group_desc)
68
+ expect(group.suppressed).to eq(true)
69
+ expect(group.is_default).to eq(false)
70
+ end
71
+ end
72
+
52
73
  it '#get_suppressions' do
53
- suppressions = @client.get_suppressions(email_address: @email1)
54
- expect(suppressions.suppressions).to be_a(Array)
55
- suppressions.suppressions.each do |suppression|
56
- next unless suppression.name == @group_name
57
- expect(suppression.name).to eq(@group_name)
58
- expect(suppression.description).to eq(@group_desc)
59
- expect(suppression.suppressed).to eq(true)
74
+ suppressions = @client.get_suppressions
75
+ expect(suppressions).to be_a(Array)
76
+ suppressions.each do |suppression|
77
+ expect(suppression).to be_a(Suppressions::Suppression)
60
78
  end
61
79
  end
62
80
 
@@ -98,34 +116,76 @@ module SendGrid4r::REST::Sm
98
116
  '["test1@example.com","test2@example.com"]'
99
117
  end
100
118
 
101
- let(:suppression) do
119
+ let(:group) do
102
120
  '{'\
103
- '"id": 4,'\
104
- '"name": "Special Offers",'\
105
- '"description": "Special offers and coupons",'\
106
- '"suppressed": false'\
121
+ '"description": "Optional description.",'\
122
+ '"id": 1,'\
123
+ '"is_default": true,'\
124
+ '"name": "Weekly News",'\
125
+ '"suppressed": true'\
107
126
  '}'
108
127
  end
109
128
 
110
- let(:suppressions) do
129
+ let(:groups) do
111
130
  '{'\
112
131
  '"suppressions": ['\
113
132
  '{'\
133
+ '"description": "Optional description.",'\
114
134
  '"id": 1,'\
115
- '"name": "Weekly Newsletter",'\
116
- '"description": "The weekly newsletter",'\
117
- '"suppressed": false'\
135
+ '"is_default": true,'\
136
+ '"name": "Weekly News",'\
137
+ '"suppressed": true'\
138
+ '},'\
139
+ '{'\
140
+ '"description": "Some daily news.",'\
141
+ '"id": 2,'\
142
+ '"is_default": true,'\
143
+ '"name": "Daily News",'\
144
+ '"suppressed": true'\
118
145
  '},'\
119
146
  '{'\
120
- '"id": 4,'\
121
- '"name": "Special Offers",'\
122
- '"description": "Special offers and coupons",'\
147
+ '"description": "An old group.",'\
148
+ '"id": 2,'\
149
+ '"is_default": false,'\
150
+ '"name": "Old News",'\
123
151
  '"suppressed": false'\
124
152
  '}'\
125
153
  ']'\
126
154
  '}'
127
155
  end
128
156
 
157
+ let(:suppressions) do
158
+ '['\
159
+ '{'\
160
+ '"email":"test@example.com",'\
161
+ '"group_id": 1,'\
162
+ '"group_name": "Weekly News",'\
163
+ '"created_at": 1410986704'\
164
+ '},'\
165
+ '{'\
166
+ '"email":"test1@example.com",'\
167
+ '"group_id": 2,'\
168
+ '"group_name": "Daily News",'\
169
+ '"created_at": 1411493671'\
170
+ '},'\
171
+ '{'\
172
+ '"email":"test2@example.com",'\
173
+ '"group_id": 2,'\
174
+ '"group_name": "Daily News",'\
175
+ '"created_at": 1411493671'\
176
+ '}'\
177
+ ']'
178
+ end
179
+
180
+ let(:suppression) do
181
+ '{'\
182
+ '"email":"test@example.com",'\
183
+ '"group_id": 1,'\
184
+ '"group_name": "Weekly News",'\
185
+ '"created_at": 1410986704'\
186
+ '}'
187
+ end
188
+
129
189
  it '#post_suppressed_emails' do
130
190
  allow(client).to receive(:execute).and_return(recipient_emails)
131
191
  actual = client.post_suppressed_emails(
@@ -134,18 +194,35 @@ module SendGrid4r::REST::Sm
134
194
  expect(actual).to be_a(RecipientEmails)
135
195
  end
136
196
 
197
+ it '#search_suppressed_emails' do
198
+ allow(client).to receive(:execute).and_return(emails)
199
+ actual = client.search_suppressed_emails(
200
+ group_id: 0, recipient_emails: ['', '']
201
+ )
202
+ expect(actual).to be_a(Array)
203
+ end
204
+
137
205
  it '#get_suppressed_emails' do
138
206
  allow(client).to receive(:execute).and_return(emails)
139
207
  actual = client.get_suppressed_emails(group_id: 0)
140
208
  expect(actual).to be_a(Array)
141
209
  end
142
210
 
211
+ it '#get_groups_by_email' do
212
+ allow(client).to receive(:execute).and_return(groups)
213
+ actual = client.get_groups_by_email(email_address: '')
214
+ expect(actual.suppressions).to be_a(Array)
215
+ actual.suppressions.each do |group|
216
+ expect(group).to be_a(Suppressions::Group)
217
+ end
218
+ end
219
+
143
220
  it '#get_suppressions' do
144
221
  allow(client).to receive(:execute).and_return(suppressions)
145
- actual = client.get_suppressions(email_address: '')
146
- expect(actual.suppressions).to be_a(Array)
147
- actual.suppressions.each do |suppression|
148
- expect(suppression).to be_a(Suppressions::Suppression)
222
+ actual = client.get_suppressions
223
+ expect(actual).to be_a(Array)
224
+ actual.each do |group|
225
+ expect(group).to be_a(Suppressions::Suppression)
149
226
  end
150
227
  end
151
228
 
@@ -155,23 +232,33 @@ module SendGrid4r::REST::Sm
155
232
  expect(actual).to eq('')
156
233
  end
157
234
 
158
- it 'creates suppression instance' do
159
- actual = Suppressions.create_suppression(JSON.parse(suppression))
160
- expect(actual).to be_a(Suppressions::Suppression)
161
- expect(actual.id).to eq(4)
162
- expect(actual.name).to eq('Special Offers')
163
- expect(actual.description).to eq('Special offers and coupons')
164
- expect(actual.suppressed).to eq(false)
235
+ it 'creates group instance' do
236
+ actual = Suppressions.create_group(JSON.parse(group))
237
+ expect(actual).to be_a(Suppressions::Group)
238
+ expect(actual.id).to eq(1)
239
+ expect(actual.name).to eq('Weekly News')
240
+ expect(actual.description).to eq('Optional description.')
241
+ expect(actual.suppressed).to eq(true)
242
+ expect(actual.is_default).to eq(true)
165
243
  end
166
244
 
167
- it 'creates suppressions instance' do
168
- actual = Suppressions.create_suppressions(JSON.parse(suppressions))
169
- expect(actual).to be_a(Suppressions::Suppressions)
245
+ it 'creates groups instance' do
246
+ actual = Suppressions.create_groups(JSON.parse(groups))
247
+ expect(actual).to be_a(Suppressions::Groups)
170
248
  expect(actual.suppressions).to be_a(Array)
171
- actual.suppressions.each do |suppression|
172
- expect(suppression).to be_a(Suppressions::Suppression)
249
+ actual.suppressions.each do |group|
250
+ expect(group).to be_a(Suppressions::Group)
173
251
  end
174
252
  end
253
+
254
+ it 'create suppression instance' do
255
+ actual = Suppressions.create_suppression(JSON.parse(suppression))
256
+ expect(actual).to be_a(Suppressions::Suppression)
257
+ expect(actual.email).to eq('test@example.com')
258
+ expect(actual.group_id).to eq(1)
259
+ expect(actual.group_name).to eq('Weekly News')
260
+ expect(actual.created_at).to eq(Time.at(1410986704))
261
+ end
175
262
  end
176
263
  end
177
264
  end
@@ -7,13 +7,69 @@ module SendGrid4r::REST::Webhooks
7
7
  before do
8
8
  Dotenv.load
9
9
  @client = SendGrid4r::Client.new(api_key: ENV['SILVER_API_KEY'])
10
+ @hostname1 = 'host1.abc.abc'
11
+ @hostname2 = 'host2.abc.abc'
12
+ # clean up test env
13
+ settings = @client.get_parse_settings
14
+ settings.result.each do |setting|
15
+ if setting.hostname == @hostname1
16
+ @client.delete_parse_setting(hostname: @hostname1)
17
+ end
18
+ if setting.hostname == @hostname2
19
+ @client.delete_parse_setting(hostname: @hostname2)
20
+ end
21
+ end
22
+ # post parse setting
23
+ @parse_setting1 = @client.post_parse_setting(
24
+ hostname: @hostname1,
25
+ url: 'http://host1.abc.abc',
26
+ spam_check: false,
27
+ send_raw: false
28
+ )
10
29
  end
11
30
 
12
31
  context 'without block call' do
13
- it '#get_parse_settings' do
14
- parse_settings = @client.get_parse_settings
15
- expect(parse_settings).to be_a(Parse::ParseSettings)
16
- expect(parse_settings.result).to be_a(Array)
32
+ it '#get_parse_settings without params' do
33
+ settings = @client.get_parse_settings
34
+ expect(settings).to be_a(Parse::ParseSettings)
35
+ expect(settings.result).to be_a(Array)
36
+ end
37
+
38
+ it '#get_parse_settings with full params' do
39
+ settings = @client.get_parse_settings(limit: 1, offset: 0)
40
+ expect(settings).to be_a(Parse::ParseSettings)
41
+ expect(settings.result).to be_a(Array)
42
+ end
43
+
44
+ it '#post_parse_setting' do
45
+ setting = @client.post_parse_setting(
46
+ hostname: @hostname2,
47
+ url: 'https://host2.abc.abc',
48
+ spam_check: true,
49
+ send_raw: true
50
+ )
51
+ expect(setting).to be_a(Parse::ParseSetting)
52
+ end
53
+
54
+ it '#get_parse_setting' do
55
+ setting = @client.get_parse_setting(
56
+ hostname: @hostname1
57
+ )
58
+ expect(setting).to be_a(Parse::ParseSetting)
59
+ end
60
+
61
+ it '#patch_parse_setting' do
62
+ setting = @client.patch_parse_setting(
63
+ hostname: @hostname1,
64
+ url: 'http://host1.ccc.ccc',
65
+ spam_check: true,
66
+ send_raw: true
67
+ )
68
+ expect(setting).to be_a(Parse::ParseSetting)
69
+ end
70
+
71
+ it '#delete_parse_setting' do
72
+ @client.delete_parse_setting(hostname: @hostname1)
17
73
  end
18
74
  end
19
75
  end
@@ -29,7 +85,8 @@ module SendGrid4r::REST::Webhooks
29
85
  '{'\
30
86
  '"url": "http://mydomain.com/parse",'\
31
87
  '"hostname": "mail.mydomain.com",'\
32
- '"spam_check_outgoing": true'\
88
+ '"spam_check": true,'\
89
+ '"send_raw": true'\
33
90
  '}'\
34
91
  ']'\
35
92
  '}'
@@ -39,7 +96,8 @@ module SendGrid4r::REST::Webhooks
39
96
  '{'\
40
97
  '"url": "http://mydomain.com/parse",'\
41
98
  '"hostname": "mail.mydomain.com",'\
42
- '"spam_check_outgoing": true'\
99
+ '"spam_check": true,'\
100
+ '"send_raw": true'\
43
101
  '}'\
44
102
  end
45
103
 
@@ -49,12 +107,41 @@ module SendGrid4r::REST::Webhooks
49
107
  expect(actual).to be_a(Parse::ParseSettings)
50
108
  end
51
109
 
110
+ it '#post_parse_setting' do
111
+ allow(client).to receive(:execute).and_return(parse_setting)
112
+ actual = client.post_parse_setting(
113
+ hostname: '', url: '', spam_check: true, send_raw: true
114
+ )
115
+ expect(actual).to be_a(Parse::ParseSetting)
116
+ end
117
+
118
+ it '#get_parse_setting' do
119
+ allow(client).to receive(:execute).and_return(parse_setting)
120
+ actual = client.get_parse_setting(hostname: '')
121
+ expect(actual).to be_a(Parse::ParseSetting)
122
+ end
123
+
124
+ it '#patch_parse_setting' do
125
+ allow(client).to receive(:execute).and_return(parse_setting)
126
+ actual = client.patch_parse_setting(
127
+ hostname: '', url: '', spam_check: true, send_raw: true
128
+ )
129
+ expect(actual).to be_a(Parse::ParseSetting)
130
+ end
131
+
132
+ it '#delete_parse_setting' do
133
+ allow(client).to receive(:execute).and_return('')
134
+ actual = client.delete_parse_setting(hostname: '')
135
+ expect(actual).to eq('')
136
+ end
137
+
52
138
  it 'creates parse_setting instance' do
53
139
  actual = Parse.create_parse_setting(JSON.parse(parse_setting))
54
140
  expect(actual).to be_a(Parse::ParseSetting)
55
141
  expect(actual.url).to eq('http://mydomain.com/parse')
56
142
  expect(actual.hostname).to eq('mail.mydomain.com')
57
- expect(actual.spam_check_outgoing).to eq(true)
143
+ expect(actual.spam_check).to eq(true)
144
+ expect(actual.send_raw).to eq(true)
58
145
  end
59
146
 
60
147
  it 'creates parse_settings instance' do
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.12.0
4
+ version: 1.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - awwa500@gmail.com
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-23 00:00:00.000000000 Z
11
+ date: 2016-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -137,6 +137,7 @@ files:
137
137
  - exe/sg
138
138
  - lib/sendgrid4r.rb
139
139
  - lib/sendgrid4r/auth.rb
140
+ - lib/sendgrid4r/cli/alert.rb
140
141
  - lib/sendgrid4r/cli/api_keys/api_key.rb
141
142
  - lib/sendgrid4r/cli/api_keys/permission.rb
142
143
  - lib/sendgrid4r/cli/campaign/campaign.rb
@@ -198,6 +199,7 @@ files:
198
199
  - lib/sendgrid4r/factory/mail_factory.rb
199
200
  - lib/sendgrid4r/factory/segment_factory.rb
200
201
  - lib/sendgrid4r/factory/version_factory.rb
202
+ - lib/sendgrid4r/rest/alerts.rb
201
203
  - lib/sendgrid4r/rest/api.rb
202
204
  - lib/sendgrid4r/rest/api_keys_management/api_keys.rb
203
205
  - lib/sendgrid4r/rest/api_keys_management/permissions.rb
@@ -254,6 +256,7 @@ files:
254
256
  - lib/sendgrid4r/rest/whitelabel/links.rb
255
257
  - lib/sendgrid4r/version.rb
256
258
  - sendgrid4r.gemspec
259
+ - spec/cli/alert_spec.rb
257
260
  - spec/cli/api_keys/api_key_spec.rb
258
261
  - spec/cli/api_keys/permission_spec.rb
259
262
  - spec/cli/campaign/campaign_spec.rb
@@ -313,6 +316,7 @@ files:
313
316
  - spec/factory/segment_factory_spec.rb
314
317
  - spec/factory/version_factory_spec.rb
315
318
  - spec/photo.jpg
319
+ - spec/rest/alerts_spec.rb
316
320
  - spec/rest/api_keys_management/api_keys_spec.rb
317
321
  - spec/rest/api_keys_management/permissions_spec.rb
318
322
  - spec/rest/blocks_spec.rb
@@ -340,6 +344,7 @@ files:
340
344
  - spec/rest/marketing_campaigns/contacts/segments_spec.rb
341
345
  - spec/rest/marketing_campaigns/marketing_campaigns_spec.rb
342
346
  - spec/rest/marketing_campaigns/senders_spec.rb
347
+ - spec/rest/request_spec.rb
343
348
  - spec/rest/settings/enforced_tls_spec.rb
344
349
  - spec/rest/settings/mail_spec.rb
345
350
  - spec/rest/settings/partner_spec.rb
@@ -391,6 +396,7 @@ signing_key:
391
396
  specification_version: 4
392
397
  summary: SendGrid Web API v3 module
393
398
  test_files:
399
+ - spec/cli/alert_spec.rb
394
400
  - spec/cli/api_keys/api_key_spec.rb
395
401
  - spec/cli/api_keys/permission_spec.rb
396
402
  - spec/cli/campaign/campaign_spec.rb
@@ -450,6 +456,7 @@ test_files:
450
456
  - spec/factory/segment_factory_spec.rb
451
457
  - spec/factory/version_factory_spec.rb
452
458
  - spec/photo.jpg
459
+ - spec/rest/alerts_spec.rb
453
460
  - spec/rest/api_keys_management/api_keys_spec.rb
454
461
  - spec/rest/api_keys_management/permissions_spec.rb
455
462
  - spec/rest/blocks_spec.rb
@@ -477,6 +484,7 @@ test_files:
477
484
  - spec/rest/marketing_campaigns/contacts/segments_spec.rb
478
485
  - spec/rest/marketing_campaigns/marketing_campaigns_spec.rb
479
486
  - spec/rest/marketing_campaigns/senders_spec.rb
487
+ - spec/rest/request_spec.rb
480
488
  - spec/rest/settings/enforced_tls_spec.rb
481
489
  - spec/rest/settings/mail_spec.rb
482
490
  - spec/rest/settings/partner_spec.rb