sendgrid4r 1.3.0 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f917e5bad6e118fb4038ed40d03c754cf0c47a29
4
- data.tar.gz: 36b3c7f7bf0a50841a9a6970c017f76d41669c67
3
+ metadata.gz: b3ee86e446ae380f740a78f1e87062d7bb5db054
4
+ data.tar.gz: a8a4dfe52c631a858531cab5de61435f13e11b0e
5
5
  SHA512:
6
- metadata.gz: e58bdc185eee38e7a8e07a9ab6720639e65d20fb4484e8ab98b94223a9b100f210bd5cc47be5adc76c58bcc3fe0c4702e898b3e611aa98102a1706fe39f11bc5
7
- data.tar.gz: fde6e1b9d2abf15276d6f700a2d169c583752c73b946b364aabb3bdd30f1cabbb5f6564cf7d3756383d3bbaffa33ff3078d246115af1ab02e8e1edc6901d3cfe
6
+ metadata.gz: f2a14376adeaf79d4297555e52bf4547759990bdfd4ed69f4ff4ba6270361f0cfc76e33ed59e57930a912dd44d6672b5172c0f8a30f613e036a2ce1e02581821
7
+ data.tar.gz: d33323175ab7e3beee707805ef572f3e5ec461670412ae22760c2f88625102bd4688c01554eb73eada984f51be19904eb4e324b439175e721d8992fc2f321aff
@@ -29,12 +29,14 @@ require 'sendgrid4r/rest/contacts/reserved_fields'
29
29
  require 'sendgrid4r/rest/contacts/segments'
30
30
  require 'sendgrid4r/rest/campaigns/campaigns'
31
31
  require 'sendgrid4r/rest/api_keys/api_keys'
32
- require 'sendgrid4r/rest/subusers/subusers'
32
+ require 'sendgrid4r/rest/subusers'
33
33
  require 'sendgrid4r/rest/email_activity/email_activity'
34
34
  require 'sendgrid4r/rest/whitelabel/domains'
35
35
  require 'sendgrid4r/rest/whitelabel/ips'
36
36
  require 'sendgrid4r/rest/whitelabel/links'
37
- require 'sendgrid4r/rest/users/users'
37
+ require 'sendgrid4r/rest/users'
38
+ require 'sendgrid4r/rest/bounces'
39
+ require 'sendgrid4r/rest/cancel_scheduled_sends'
38
40
 
39
41
  module SendGrid4r
40
42
  module REST
@@ -75,6 +77,8 @@ module SendGrid4r
75
77
  include SendGrid4r::REST::Whitelabel::Ips
76
78
  include SendGrid4r::REST::Whitelabel::Links
77
79
  include SendGrid4r::REST::Users
80
+ include SendGrid4r::REST::Bounces
81
+ include SendGrid4r::REST::CancelScheduledSends
78
82
  end
79
83
  end
80
84
  end
@@ -13,7 +13,7 @@ module SendGrid4r
13
13
  include SendGrid4r::REST::Request
14
14
 
15
15
  Group = Struct.new(
16
- :id, :name, :description, :last_email_sent_at, :unsubscribes)
16
+ :id, :name, :description, :unsubscribes)
17
17
 
18
18
  def self.url(group_id = nil)
19
19
  url = "#{BASE_URL}/asm/groups"
@@ -36,7 +36,6 @@ module SendGrid4r
36
36
  resp['id'],
37
37
  resp['name'],
38
38
  resp['description'],
39
- resp['last_email_sent_at'],
40
39
  resp['unsubscribes']
41
40
  )
42
41
  end
@@ -0,0 +1,79 @@
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
+ #
9
+ # SendGrid Web API v3 Subusers
10
+ #
11
+ module Bounces
12
+ include SendGrid4r::REST::Request
13
+
14
+ Bounce = Struct.new(
15
+ :created, :email, :reason, :status
16
+ )
17
+
18
+ def self.url(email = nil)
19
+ url = "#{BASE_URL}/suppression/bounces"
20
+ url = "#{url}/#{email}" unless email.nil?
21
+ url
22
+ end
23
+
24
+ def self.create_bounces(resp)
25
+ return resp if resp.nil?
26
+ bounces = []
27
+ resp.each do |bounce|
28
+ bounces.push(SendGrid4r::REST::Bounces.create_bounce(bounce))
29
+ end
30
+ bounces
31
+ end
32
+
33
+ def self.create_bounce(resp)
34
+ return resp if resp.nil?
35
+ created = Time.at(resp['created']) unless resp['created'].nil?
36
+ Bounce.new(
37
+ created,
38
+ resp['email'],
39
+ resp['reason'],
40
+ resp['status']
41
+ )
42
+ end
43
+
44
+ def get_bounces(start_time: nil, end_time: nil, &block)
45
+ params = {}
46
+ params['start_time'] = start_time.to_i unless start_time.nil?
47
+ params['end_time'] = end_time.to_i unless end_time.nil?
48
+ resp = get(@auth, SendGrid4r::REST::Bounces.url, params, &block)
49
+ SendGrid4r::REST::Bounces.create_bounces(resp)
50
+ end
51
+
52
+ def delete_bounces(delete_all: nil, emails: nil, &block)
53
+ endpoint = SendGrid4r::REST::Bounces.url
54
+ payload = {}
55
+ if delete_all == true
56
+ payload['delete_all'] = delete_all
57
+ else
58
+ payload['emails'] = emails
59
+ end
60
+ delete(@auth, endpoint, nil, payload, &block)
61
+ end
62
+
63
+ def get_bounce(email:, &block)
64
+ endpoint = SendGrid4r::REST::Bounces.url(email)
65
+ params = {}
66
+ params['email'] = email
67
+ resp = get(@auth, endpoint, params, &block)
68
+ SendGrid4r::REST::Bounces.create_bounces(resp)
69
+ end
70
+
71
+ def delete_bounce(email:, &block)
72
+ endpoint = SendGrid4r::REST::Bounces.url(email)
73
+ params = {}
74
+ params['email'] = email
75
+ delete(@auth, endpoint, params, &block)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,92 @@
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
+ #
9
+ # SendGrid Web API v3 CancelScheduledSends
10
+ #
11
+ module CancelScheduledSends
12
+ include SendGrid4r::REST::Request
13
+
14
+ ScheduledSend = Struct.new(:batch_id, :status)
15
+
16
+ def self.batch_url(batch_id = nil)
17
+ url = "#{BASE_URL}/mail/batch"
18
+ url = "#{url}/#{batch_id}" unless batch_id.nil?
19
+ url
20
+ end
21
+
22
+ def self.scheduled_sends_url(batch_id = nil)
23
+ url = "#{BASE_URL}/user/scheduled_sends"
24
+ url = "#{url}/#{batch_id}" unless batch_id.nil?
25
+ url
26
+ end
27
+
28
+ def self.create_scheduled_sends(resp)
29
+ return resp if resp.nil?
30
+ scheduled_sends = []
31
+ resp.each do |scheduled_send|
32
+ scheduled_sends.push(
33
+ SendGrid4r::REST::CancelScheduledSends.create_scheduled_send(
34
+ scheduled_send
35
+ )
36
+ )
37
+ end
38
+ scheduled_sends
39
+ end
40
+
41
+ def self.create_scheduled_send(resp)
42
+ return resp if resp.nil?
43
+ ScheduledSend.new(resp['batch_id'], resp['status'])
44
+ end
45
+
46
+ def generate_batch_id(&block)
47
+ endpoint = SendGrid4r::REST::CancelScheduledSends.batch_url
48
+ resp = post(@auth, endpoint, nil, &block)
49
+ SendGrid4r::REST::CancelScheduledSends.create_scheduled_send(resp)
50
+ end
51
+
52
+ def validate_batch_id(batch_id:, &block)
53
+ endpoint = SendGrid4r::REST::CancelScheduledSends.batch_url(batch_id)
54
+ resp = get(@auth, endpoint, nil, &block)
55
+ SendGrid4r::REST::CancelScheduledSends.create_scheduled_send(resp)
56
+ end
57
+
58
+ def post_scheduled_send(batch_id:, status:, &block)
59
+ endpoint = SendGrid4r::REST::CancelScheduledSends.scheduled_sends_url
60
+ payload = {}
61
+ payload['batch_id'] = batch_id
62
+ payload['status'] = status
63
+ resp = post(@auth, endpoint, payload, &block)
64
+ SendGrid4r::REST::CancelScheduledSends.create_scheduled_send(resp)
65
+ end
66
+
67
+ def get_scheduled_sends(batch_id: nil, &block)
68
+ endpoint = SendGrid4r::REST::CancelScheduledSends.scheduled_sends_url(
69
+ batch_id
70
+ )
71
+ resp = get(@auth, endpoint, nil, nil, &block)
72
+ SendGrid4r::REST::CancelScheduledSends.create_scheduled_sends(resp)
73
+ end
74
+
75
+ def patch_scheduled_send(batch_id:, status:, &block)
76
+ endpoint = SendGrid4r::REST::CancelScheduledSends.scheduled_sends_url(
77
+ batch_id
78
+ )
79
+ payload = {}
80
+ payload['status'] = status
81
+ patch(@auth, endpoint, payload, &block)
82
+ end
83
+
84
+ def delete_scheduled_send(batch_id:, &block)
85
+ endpoint = SendGrid4r::REST::CancelScheduledSends.scheduled_sends_url(
86
+ batch_id
87
+ )
88
+ delete(@auth, endpoint, nil, &block)
89
+ end
90
+ end
91
+ end
92
+ end
@@ -30,21 +30,18 @@ module SendGrid4r
30
30
  def self.create_recipient(resp)
31
31
  return resp if resp.nil?
32
32
  custom_fields = []
33
- resp['custom_fields'].each do |field|
34
- custom_fields.push(
35
- SendGrid4r::REST::Contacts::CustomFields.create_field(field)
36
- )
33
+ unless resp['custom_fields'].nil?
34
+ resp['custom_fields'].each do |field|
35
+ custom_fields.push(
36
+ SendGrid4r::REST::Contacts::CustomFields.create_field(field)
37
+ )
38
+ end
37
39
  end
38
40
  Recipient.new(
39
- Time.at(resp['created_at']),
40
- custom_fields,
41
- resp['email'],
42
- resp['first_name'],
43
- resp['id'],
44
- resp['last_clicked'],
45
- resp['last_emailed'],
46
- resp['last_name'],
47
- resp['last_opened'],
41
+ Time.at(resp['created_at']), custom_fields,
42
+ resp['email'], resp['first_name'], resp['id'],
43
+ resp['last_clicked'], resp['last_emailed'],
44
+ resp['last_name'], resp['last_opened'],
48
45
  Time.at(resp['updated_at'])
49
46
  )
50
47
  end
File without changes
@@ -93,9 +93,9 @@ module SendGrid4r
93
93
  Result = Struct.new(:id, :valid, :validation_results)
94
94
  ValidationResults = Struct.new(
95
95
  # automatic_security:true
96
- :mail_cname, :spf, :dkim1, :dkim2,
96
+ :mail_cname, :dkim1, :dkim2,
97
97
  # automatic_security:false
98
- :mail_server, :subdomain_spf, :domain_spf, :dkim
98
+ :mail_server, :subdomain_spf, :dkim
99
99
  )
100
100
  ValidationResult = Struct.new(:valid, :reason)
101
101
 
@@ -119,14 +119,10 @@ module SendGrid4r
119
119
  resp['dkim1']),
120
120
  SendGrid4r::REST::Whitelabel::Domains.create_validation_result(
121
121
  resp['dkim2']),
122
- SendGrid4r::REST::Whitelabel::Domains.create_validation_result(
123
- resp['spf']),
124
122
  SendGrid4r::REST::Whitelabel::Domains.create_validation_result(
125
123
  resp['mail_server']),
126
124
  SendGrid4r::REST::Whitelabel::Domains.create_validation_result(
127
125
  resp['subdomain_spf']),
128
- SendGrid4r::REST::Whitelabel::Domains.create_validation_result(
129
- resp['domain_spf']),
130
126
  SendGrid4r::REST::Whitelabel::Domains.create_validation_result(
131
127
  resp['dkim'])
132
128
  )
@@ -2,5 +2,5 @@
2
2
  # SendGrid API v3 wrapper implementation.
3
3
  #
4
4
  module SendGrid4r
5
- VERSION = '1.3.0'
5
+ VERSION = '1.4.0'
6
6
  end
data/spec/client_spec.rb CHANGED
@@ -254,12 +254,26 @@ describe SendGrid4r::Client do
254
254
  expect(@client.respond_to?('get_user_profile')).to eq(true)
255
255
  expect(@client.respond_to?('patch_user_profile')).to eq(true)
256
256
  expect(@client.respond_to?('get_user_account')).to eq(true)
257
+
258
+ # Bounces API
259
+ expect(@client.respond_to?('get_bounces')).to eq(true)
260
+ expect(@client.respond_to?('delete_bounces')).to eq(true)
261
+ expect(@client.respond_to?('get_bounce')).to eq(true)
262
+ expect(@client.respond_to?('delete_bounce')).to eq(true)
263
+
264
+ # Cancel Scheduled Sends Api
265
+ expect(@client.respond_to?('generate_batch_id')).to eq(true)
266
+ expect(@client.respond_to?('validate_batch_id')).to eq(true)
267
+ expect(@client.respond_to?('post_scheduled_send')).to eq(true)
268
+ expect(@client.respond_to?('get_scheduled_sends')).to eq(true)
269
+ expect(@client.respond_to?('patch_scheduled_send')).to eq(true)
270
+ expect(@client.respond_to?('delete_scheduled_send')).to eq(true)
257
271
  end
258
272
  end
259
273
 
260
274
  describe 'VERSION' do
261
275
  it 'returns VERSION value' do
262
- expect(SendGrid4r::VERSION).to eq('1.3.0')
276
+ expect(SendGrid4r::VERSION).to eq('1.4.0')
263
277
  end
264
278
  end
265
279
  end
@@ -60,7 +60,6 @@ describe SendGrid4r::REST::Asm::Groups do
60
60
  expect(group_edit1.id).to be_a(Fixnum)
61
61
  expect(group_edit1.name).to eq(@group_name_edit1)
62
62
  expect(group_edit1.description).to eq(@group_desc_edit)
63
- expect(group_edit1.last_email_sent_at).to eq(nil)
64
63
  expect(group_edit1.unsubscribes).to eq(nil)
65
64
  rescue RestClient::ExceptionWithResponse => e
66
65
  puts e.inspect
@@ -87,7 +86,6 @@ describe SendGrid4r::REST::Asm::Groups do
87
86
  expect(group.id).to be_a(Fixnum)
88
87
  expect(group.name).to eq(@group_name1)
89
88
  expect(group.description).to eq(@group_desc)
90
- expect(group.last_email_sent_at).to eq(nil)
91
89
  expect(group.unsubscribes).to eq(0)
92
90
  rescue RestClient::ExceptionWithResponse => e
93
91
  puts e.inspect
@@ -117,7 +115,6 @@ describe SendGrid4r::REST::Asm::Groups do
117
115
  '"id": 100,'\
118
116
  '"name": "Newsletters",'\
119
117
  '"description": "Our monthly newsletter.",'\
120
- '"last_email_sent_at": "2014-09-04 01:34:43",'\
121
118
  '"unsubscribes": 400'\
122
119
  '}'
123
120
  )
@@ -130,14 +127,12 @@ describe SendGrid4r::REST::Asm::Groups do
130
127
  '"id": 100,'\
131
128
  '"name": "Newsletters",'\
132
129
  '"description": "Our monthly newsletter.",'\
133
- '"last_email_sent_at": "2014-09-04 01:34:43",'\
134
130
  '"unsubscribes": 400'\
135
131
  '},'\
136
132
  '{'\
137
133
  '"id": 101,'\
138
134
  '"name": "Alerts",'\
139
135
  '"description": "Emails triggered by user-defined rules.",'\
140
- '"last_email_sent_at": "2012-11-06 09:37:33",'\
141
136
  '"unsubscribes": 1'\
142
137
  '}'\
143
138
  ']'
@@ -185,7 +180,6 @@ describe SendGrid4r::REST::Asm::Groups do
185
180
  expect(actual.id).to eq(100)
186
181
  expect(actual.name).to eq('Newsletters')
187
182
  expect(actual.description).to eq('Our monthly newsletter.')
188
- expect(actual.last_email_sent_at).to eq('2014-09-04 01:34:43')
189
183
  expect(actual.unsubscribes).to eq(400)
190
184
  end
191
185
 
@@ -0,0 +1,173 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ describe SendGrid4r::REST::Bounces 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 = ['a1@bounce.com', 'a2@bounce.com', 'a3@bounce.com']
11
+ rescue RestClient::ExceptionWithResponse => e
12
+ puts e.inspect
13
+ raise e
14
+ end
15
+ end
16
+
17
+ context 'without block call' do
18
+ it '#get_bounces' do
19
+ begin
20
+ start_time = Time.now - 60 * 60 * 24 * 365
21
+ end_time = Time.now
22
+ bounces = @client.get_bounces(
23
+ start_time: start_time, end_time: end_time
24
+ )
25
+ expect(bounces).to be_a(Array)
26
+ bounces.each do |bounce|
27
+ expect(bounce).to be_a(SendGrid4r::REST::Bounces::Bounce)
28
+ end
29
+ rescue RestClient::ExceptionWithResponse => e
30
+ puts e.inspect
31
+ raise e
32
+ end
33
+ end
34
+
35
+ it '#delete_bounces(delete_all: true)' do
36
+ begin
37
+ @client.delete_bounces(delete_all: true)
38
+ rescue RestClient::ExceptionWithResponse => e
39
+ puts e.inspect
40
+ raise e
41
+ end
42
+ end
43
+
44
+ it '#delete_bounces(emails: [])' do
45
+ begin
46
+ @client.delete_bounces(emails: @emails)
47
+ rescue RestClient::ExceptionWithResponse => e
48
+ puts e.inspect
49
+ raise e
50
+ end
51
+ end
52
+
53
+ it '#get_bounce' do
54
+ begin
55
+ bounce = @client.get_bounce(email: @email)
56
+ expect(bounce).to be_a(Array)
57
+ rescue RestClient::ExceptionWithResponse => e
58
+ puts e.inspect
59
+ raise e
60
+ end
61
+ end
62
+
63
+ it '#delete_bounce' do
64
+ begin
65
+ expect do
66
+ @client.delete_bounce(email: 'a1@bounce.com')
67
+ end.to raise_error(RestClient::ResourceNotFound)
68
+ rescue RestClient::ExceptionWithResponse => e
69
+ puts e.inspect
70
+ raise e
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ describe 'unit test', :ut do
77
+ let(:client) do
78
+ SendGrid4r::Client.new(api_key: '')
79
+ end
80
+
81
+ let(:bounces) do
82
+ JSON.parse(
83
+ '['\
84
+ '{'\
85
+ '"created": 1443651125,'\
86
+ '"email": "testemail1@test.com",'\
87
+ '"reason": "550 5.1.1 The email account that you tried to reach '\
88
+ 'does not exist.'\
89
+ 'Please try double-checking the recipient\'s email address for '\
90
+ 'typos or unnecessary spaces. Learn more at '\
91
+ 'https://support.google.com/mail/answer/6596'\
92
+ 'o186si2389584ioe.63 - gsmtp ",'\
93
+ '"status": "5.1.1"'\
94
+ '},'\
95
+ '{'\
96
+ '"created": 1433800303,'\
97
+ '"email": "testemail2@testing.com",'\
98
+ '"reason": "550 5.1.1 <testemail2@testing.com>: Recipient address '\
99
+ 'rejected: User unknown in virtual alias table ",'\
100
+ '"status": "5.1.1"'\
101
+ '}'\
102
+ ']'
103
+ )
104
+ end
105
+
106
+ let(:bounce) do
107
+ JSON.parse(
108
+ '{'\
109
+ '"created": 1433800303,'\
110
+ '"email": "testemail2@testing.com",'\
111
+ '"reason": "550 5.1.1 <testemail2@testing.com>: Recipient address '\
112
+ 'rejected: User unknown in virtual alias table ",'\
113
+ '"status": "5.1.1"'\
114
+ '}'
115
+ )
116
+ end
117
+
118
+ it '#get_bounces' do
119
+ allow(client).to receive(:execute).and_return(bounces)
120
+ actual = client.get_bounces
121
+ expect(actual).to be_a(Array)
122
+ actual.each do |bounce|
123
+ expect(bounce).to be_a(SendGrid4r::REST::Bounces::Bounce)
124
+ end
125
+ end
126
+
127
+ it '#delete_bounces(delete_all: true)' do
128
+ allow(client).to receive(:execute).and_return('')
129
+ client.delete_bounces(delete_all: true)
130
+ end
131
+
132
+ it '#delete_bounces(emails: [])' do
133
+ allow(client).to receive(:execute).and_return('')
134
+ actual = client.delete_bounces(emails: [])
135
+ expect(actual).to eq('')
136
+ end
137
+
138
+ it '#get_bounce' do
139
+ allow(client).to receive(:execute).and_return(bounces)
140
+ actual = client.get_bounce(email: '')
141
+ expect(actual).to be_a(Array)
142
+ actual.each do |bounce|
143
+ expect(bounce).to be_a(SendGrid4r::REST::Bounces::Bounce)
144
+ end
145
+ end
146
+
147
+ it '#delete_bounce' do
148
+ allow(client).to receive(:execute).and_return('')
149
+ actual = client.delete_bounce(email: '')
150
+ expect(actual).to eq('')
151
+ end
152
+
153
+ it 'creates bounces instance' do
154
+ actual = SendGrid4r::REST::Bounces.create_bounces(bounces)
155
+ expect(actual).to be_a(Array)
156
+ actual.each do |subuser|
157
+ expect(subuser).to be_a(SendGrid4r::REST::Bounces::Bounce)
158
+ end
159
+ end
160
+
161
+ it 'creates bounce instance' do
162
+ actual = SendGrid4r::REST::Bounces.create_bounce(bounce)
163
+ expect(actual).to be_a(SendGrid4r::REST::Bounces::Bounce)
164
+ expect(actual.created).to eq(Time.at(1433800303))
165
+ expect(actual.email).to eq('testemail2@testing.com')
166
+ expect(actual.reason).to eq(
167
+ '550 5.1.1 <testemail2@testing.com>: '\
168
+ 'Recipient address rejected: User unknown in virtual alias table '
169
+ )
170
+ expect(actual.status).to eq('5.1.1')
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,210 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ describe SendGrid4r::REST::CancelScheduledSends 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
+ @scheduled_sends = @client.get_scheduled_sends
11
+ @scheduled_sends.each do |scheduled_send|
12
+ @client.delete_scheduled_send(batch_id: scheduled_send.batch_id)
13
+ end
14
+ rescue RestClient::ExceptionWithResponse => e
15
+ puts e.inspect
16
+ raise e
17
+ end
18
+ end
19
+
20
+ context 'without block call' do
21
+ it '#generate_batch_id' do
22
+ begin
23
+ scheduled_send = @client.generate_batch_id
24
+ expect(scheduled_send).to be_a(
25
+ SendGrid4r::REST::CancelScheduledSends::ScheduledSend
26
+ )
27
+ expect(scheduled_send.batch_id.length).to be > 0
28
+ rescue RestClient::ExceptionWithResponse => e
29
+ puts e.inspect
30
+ raise e
31
+ end
32
+ end
33
+
34
+ it '#validate_batch_id' do
35
+ begin
36
+ batch_id = @client.generate_batch_id.batch_id
37
+ scheduled_send = @client.validate_batch_id(batch_id: batch_id)
38
+ expect(scheduled_send).to be_a(
39
+ SendGrid4r::REST::CancelScheduledSends::ScheduledSend
40
+ )
41
+ expect(scheduled_send.batch_id).to eq(batch_id)
42
+ rescue RestClient::ExceptionWithResponse => e
43
+ puts e.inspect
44
+ raise e
45
+ end
46
+ end
47
+
48
+ it '#post_scheduled_send' do
49
+ begin
50
+ batch_id = @client.generate_batch_id.batch_id
51
+ scheduled_send = @client.post_scheduled_send(
52
+ batch_id: batch_id, status: 'cancel'
53
+ )
54
+ expect(scheduled_send).to be_a(
55
+ SendGrid4r::REST::CancelScheduledSends::ScheduledSend
56
+ )
57
+ rescue RestClient::ExceptionWithResponse => e
58
+ puts e.inspect
59
+ raise e
60
+ end
61
+ end
62
+
63
+ it '#get_scheduled_sends' do
64
+ begin
65
+ scheduled_sends = @client.get_scheduled_sends
66
+ expect(scheduled_sends).to be_a(Array)
67
+ scheduled_sends.each do |scheduled_send|
68
+ expect(scheduled_send).to be_a(
69
+ SendGrid4r::REST::CancelScheduledSends::ScheduledSend
70
+ )
71
+ end
72
+ rescue RestClient::ExceptionWithResponse => e
73
+ puts e.inspect
74
+ raise e
75
+ end
76
+ end
77
+
78
+ it '#patch_scheduled_send' do
79
+ begin
80
+ batch_id = @client.generate_batch_id.batch_id
81
+ expect do
82
+ @client.patch_scheduled_send(
83
+ batch_id: batch_id, status: 'pause'
84
+ )
85
+ end.to raise_error(RestClient::ResourceNotFound)
86
+ rescue RestClient::ExceptionWithResponse => e
87
+ puts e.inspect
88
+ raise e
89
+ end
90
+ end
91
+
92
+ it '#delete_scheduled_send' do
93
+ begin
94
+ scheduled_sends = @client.get_scheduled_sends
95
+ scheduled_sends.each do |scheduled_send|
96
+ @client.delete_scheduled_send(batch_id: scheduled_send.batch_id)
97
+ end
98
+ rescue RestClient::ExceptionWithResponse => e
99
+ puts e.inspect
100
+ raise e
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ describe 'unit test', :ut do
107
+ let(:client) do
108
+ SendGrid4r::Client.new(api_key: '')
109
+ end
110
+
111
+ let(:scheduled_send) do
112
+ JSON.parse(
113
+ '{'\
114
+ '"batch_id": "YOUR_BATCH_ID"'\
115
+ '}'
116
+ )
117
+ end
118
+
119
+ let(:scheduled_sends) do
120
+ JSON.parse(
121
+ '['\
122
+ '{'\
123
+ '"batch_id": "BATCH_ID_1",'\
124
+ '"status": "cancel"'\
125
+ '},'\
126
+ '{'\
127
+ '"batch_id": "BATCH_ID_2",'\
128
+ '"status": "pause"'\
129
+ '}'\
130
+ ']'
131
+ )
132
+ end
133
+
134
+ it '#generate_batch_id' do
135
+ allow(client).to receive(:execute).and_return(scheduled_send)
136
+ actual = client.generate_batch_id
137
+ expect(actual).to be_a(
138
+ SendGrid4r::REST::CancelScheduledSends::ScheduledSend
139
+ )
140
+ expect(actual.batch_id).to eq('YOUR_BATCH_ID')
141
+ end
142
+
143
+ it '#validate_batch_id' do
144
+ allow(client).to receive(:execute).and_return(scheduled_send)
145
+ actual = client.validate_batch_id(batch_id: '')
146
+ expect(actual).to be_a(
147
+ SendGrid4r::REST::CancelScheduledSends::ScheduledSend
148
+ )
149
+ expect(actual.batch_id).to eq('YOUR_BATCH_ID')
150
+ end
151
+
152
+ it '#post_scheduled_send' do
153
+ allow(client).to receive(:execute).and_return(scheduled_send)
154
+ actual = client.post_scheduled_send(batch_id: '', status: '')
155
+ expect(actual).to be_a(
156
+ SendGrid4r::REST::CancelScheduledSends::ScheduledSend
157
+ )
158
+ expect(actual.batch_id).to eq('YOUR_BATCH_ID')
159
+ end
160
+
161
+ it '#get_scheduled_sends' do
162
+ allow(client).to receive(:execute).and_return(scheduled_sends)
163
+ actual = client.get_scheduled_sends
164
+ expect(actual).to be_a(Array)
165
+ actual.each do |scheduled_send|
166
+ expect(scheduled_send).to be_a(
167
+ SendGrid4r::REST::CancelScheduledSends::ScheduledSend
168
+ )
169
+ end
170
+ end
171
+
172
+ it '#patch_scheduled_send' do
173
+ allow(client).to receive(:execute).and_return('')
174
+ actual = client.patch_scheduled_send(batch_id: '', status: '')
175
+ expect(actual).to eq('')
176
+ end
177
+
178
+ it '#delete_scheduled_send' do
179
+ allow(client).to receive(:execute).and_return('')
180
+ actual = client.delete_scheduled_send(batch_id: '')
181
+ expect(actual).to eq('')
182
+ end
183
+
184
+ it 'creates scheduled_sends instance' do
185
+ actual = SendGrid4r::REST::CancelScheduledSends.create_scheduled_sends(
186
+ scheduled_sends
187
+ )
188
+ expect(actual).to be_a(Array)
189
+ actual.each do |scheduled_send|
190
+ expect(scheduled_send).to be_a(
191
+ SendGrid4r::REST::CancelScheduledSends::ScheduledSend
192
+ )
193
+ expect(actual[0].batch_id).to eq('BATCH_ID_1')
194
+ expect(actual[0].status).to eq('cancel')
195
+ expect(actual[1].batch_id).to eq('BATCH_ID_2')
196
+ expect(actual[1].status).to eq('pause')
197
+ end
198
+ end
199
+
200
+ it 'creates scheduled_send instance' do
201
+ actual = SendGrid4r::REST::CancelScheduledSends.create_scheduled_send(
202
+ scheduled_send
203
+ )
204
+ expect(actual).to be_a(
205
+ SendGrid4r::REST::CancelScheduledSends::ScheduledSend
206
+ )
207
+ expect(actual.batch_id).to eq('YOUR_BATCH_ID')
208
+ end
209
+ end
210
+ end
@@ -16,7 +16,6 @@ describe SendGrid4r::REST::Contacts::Lists do
16
16
  @last_name2 = 'Miller'
17
17
  @pet1 = 'Fluffy'
18
18
  @pet2 = 'FrouFrou'
19
- @custom_field_name = 'pet'
20
19
 
21
20
  # celan up test env(lists)
22
21
  lists = @client.get_lists
@@ -41,11 +40,9 @@ describe SendGrid4r::REST::Contacts::Lists do
41
40
  recipient1 = {}
42
41
  recipient1['email'] = @email1
43
42
  recipient1['last_name'] = @last_name1
44
- recipient1[@custom_field_name] = @pet1
45
43
  recipient2 = {}
46
44
  recipient2['email'] = @email2
47
45
  recipient2['last_name'] = @last_name2
48
- recipient2[@custom_field_name] = @pet2
49
46
  result = @client.post_recipients(params: [recipient1, recipient2])
50
47
  @recipients = result.persisted_recipients
51
48
  @client.post_recipient_to_list(
@@ -54,8 +51,6 @@ describe SendGrid4r::REST::Contacts::Lists do
54
51
  @client.post_recipient_to_list(
55
52
  list_id: @list1.id, recipient_id: result.persisted_recipients[1]
56
53
  )
57
- # # Add multiple recipients to a single list
58
- # @client.post_recipients_to_list(@list1.id, @recipients)
59
54
  rescue RestClient::ExceptionWithResponse => e
60
55
  puts e.inspect
61
56
  raise e
@@ -205,7 +200,6 @@ describe SendGrid4r::REST::Contacts::Lists do
205
200
  recipient1 = {}
206
201
  recipient1['email'] = @email1
207
202
  recipient1['last_name'] = @last_name1
208
- recipient1[@custom_field_name] = @pet1
209
203
  result = @client.post_recipients(params: [recipient1])
210
204
  @client.post_recipient_to_list(
211
205
  list_id: @list1.id, recipient_id: result.persisted_recipients[0]
@@ -13,7 +13,6 @@ describe SendGrid4r::REST::Contacts::Recipients do
13
13
  @last_name2 = 'Miller'
14
14
  @pet1 = 'Fluffy'
15
15
  @pet2 = 'FrouFrou'
16
- @custom_field_name = 'pet'
17
16
 
18
17
  # celan up test env
19
18
  recipients = @client.get_recipients
@@ -21,17 +20,10 @@ describe SendGrid4r::REST::Contacts::Recipients do
21
20
  next if recipient.email != @email1 && recipient.email != @email2
22
21
  @client.delete_recipient(recipient_id: recipient.id)
23
22
  end
24
- custom_fields = @client.get_custom_fields
25
- custom_fields.custom_fields.each do |custom_field|
26
- next if custom_field.name != @custom_field_name
27
- @client.delete_custom_field(custom_field_id: custom_field.id)
28
- end
29
- @client.post_custom_field(name: @custom_field_name, type: 'text')
30
23
  # post a recipient
31
24
  params = {}
32
25
  params['email'] = @email1
33
26
  params['last_name'] = @last_name1
34
- params[@custom_field_name] = @pet1
35
27
  @result = @client.post_recipients(params: [params])
36
28
  rescue RestClient::ExceptionWithResponse => e
37
29
  puts e.inspect
@@ -45,7 +37,6 @@ describe SendGrid4r::REST::Contacts::Recipients do
45
37
  params = {}
46
38
  params['email'] = @email2
47
39
  params['last_name'] = @last_name2
48
- params[@custom_field_name] = @pet2
49
40
  result = @client.post_recipients(params: [params])
50
41
  expect(result.error_count).to eq(0)
51
42
  expect(result.error_indices).to eq([])
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
3
 
4
4
  describe SendGrid4r::REST::Subusers do
5
5
  describe 'integration test', :it do
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
3
 
4
4
  describe SendGrid4r::REST::Users do
5
5
  describe 'integration test', :it do
@@ -118,9 +118,6 @@ describe SendGrid4r::REST::Whitelabel::Domains do
118
118
  expect(@domain1.dns.mail_cname).to be_a(
119
119
  SendGrid4r::REST::Whitelabel::Domains::Record
120
120
  )
121
- expect(@domain1.dns.spf).to be_a(
122
- SendGrid4r::REST::Whitelabel::Domains::Record
123
- )
124
121
  expect(@domain1.dns.dkim1).to be_a(
125
122
  SendGrid4r::REST::Whitelabel::Domains::Record
126
123
  )
@@ -146,9 +143,6 @@ describe SendGrid4r::REST::Whitelabel::Domains do
146
143
  expect(@domain2.dns.subdomain_spf).to be_a(
147
144
  SendGrid4r::REST::Whitelabel::Domains::Record
148
145
  )
149
- expect(@domain2.dns.domain_spf).to be_a(
150
- SendGrid4r::REST::Whitelabel::Domains::Record
151
- )
152
146
  expect(@domain2.dns.dkim).to be_a(
153
147
  SendGrid4r::REST::Whitelabel::Domains::Record
154
148
  )
@@ -175,9 +169,6 @@ describe SendGrid4r::REST::Whitelabel::Domains do
175
169
  expect(domain1.dns.mail_cname).to be_a(
176
170
  SendGrid4r::REST::Whitelabel::Domains::Record
177
171
  )
178
- expect(domain1.dns.spf).to be_a(
179
- SendGrid4r::REST::Whitelabel::Domains::Record
180
- )
181
172
  expect(domain1.dns.dkim1).to be_a(
182
173
  SendGrid4r::REST::Whitelabel::Domains::Record
183
174
  )
@@ -202,9 +193,6 @@ describe SendGrid4r::REST::Whitelabel::Domains do
202
193
  expect(domain2.dns.subdomain_spf).to be_a(
203
194
  SendGrid4r::REST::Whitelabel::Domains::Record
204
195
  )
205
- expect(domain2.dns.domain_spf).to be_a(
206
- SendGrid4r::REST::Whitelabel::Domains::Record
207
- )
208
196
  expect(domain2.dns.dkim).to be_a(
209
197
  SendGrid4r::REST::Whitelabel::Domains::Record
210
198
  )
@@ -292,9 +280,6 @@ describe SendGrid4r::REST::Whitelabel::Domains do
292
280
  expect(result1.validation_results.dkim2.valid).to be(
293
281
  false
294
282
  )
295
- expect(result1.validation_results.spf.valid).to be(
296
- false
297
- )
298
283
  result2 = @client.validate_wl_domain(id: @domain2.id)
299
284
  expect(result2).to be_a(
300
285
  SendGrid4r::REST::Whitelabel::Domains::Result
@@ -306,9 +291,6 @@ describe SendGrid4r::REST::Whitelabel::Domains do
306
291
  expect(result2.validation_results.subdomain_spf.valid).to be(
307
292
  false
308
293
  )
309
- expect(result2.validation_results.domain_spf.valid).to be(
310
- false
311
- )
312
294
  expect(result2.validation_results.dkim.valid).to be(
313
295
  false
314
296
  )
@@ -382,12 +364,6 @@ describe SendGrid4r::REST::Whitelabel::Domains do
382
364
  '"data": "u7.wl.sendgrid.net",'\
383
365
  '"valid": true'\
384
366
  '},'\
385
- '"spf": {'\
386
- '"host": "example.com",'\
387
- '"type": "txt",'\
388
- '"data": "v=spf1 include:u7.wl.sendgrid.net -all",'\
389
- '"valid": true'\
390
- '},'\
391
367
  '"dkim1": {'\
392
368
  '"host": "s1._domainkey.example.com",'\
393
369
  '"type": "cname",'\
@@ -432,12 +408,6 @@ describe SendGrid4r::REST::Whitelabel::Domains do
432
408
  '"host": "mail2.example.com",'\
433
409
  '"data": "v=spf1 include:sendgrid.net ~all"'\
434
410
  '},'\
435
- '"domain_spf": {'\
436
- '"valid": false,'\
437
- '"type": "txt",'\
438
- '"host": "example.com",'\
439
- '"data": "v=spf1 include:mail2.example.com -all"'\
440
- '},'\
441
411
  '"dkim": {'\
442
412
  '"valid": false,'\
443
413
  '"type": "txt",'\
@@ -467,10 +437,6 @@ describe SendGrid4r::REST::Whitelabel::Domains do
467
437
  '"dkim2": {'\
468
438
  '"valid": true,'\
469
439
  '"reason": null'\
470
- '},'\
471
- '"spf": {'\
472
- '"valid": true,'\
473
- '"reason": null'\
474
440
  '}'\
475
441
  '}'\
476
442
  '}'
@@ -573,15 +539,6 @@ describe SendGrid4r::REST::Whitelabel::Domains do
573
539
  expect(actual.dns.mail_cname.type).to eq('cname')
574
540
  expect(actual.dns.mail_cname.data).to eq('u7.wl.sendgrid.net')
575
541
  expect(actual.dns.mail_cname.valid).to eq(true)
576
- expect(actual.dns.spf).to be_a(
577
- SendGrid4r::REST::Whitelabel::Domains::Record
578
- )
579
- expect(actual.dns.spf.host).to eq('example.com')
580
- expect(actual.dns.spf.type).to eq('txt')
581
- expect(actual.dns.spf.data).to eq(
582
- 'v=spf1 include:u7.wl.sendgrid.net -all'
583
- )
584
- expect(actual.dns.spf.valid).to eq(true)
585
542
  expect(actual.dns.dkim1).to be_a(
586
543
  SendGrid4r::REST::Whitelabel::Domains::Record
587
544
  )
@@ -629,15 +586,6 @@ describe SendGrid4r::REST::Whitelabel::Domains do
629
586
  'v=spf1 include:sendgrid.net ~all'
630
587
  )
631
588
  expect(actual.dns.subdomain_spf.valid).to eq(false)
632
- expect(actual.dns.domain_spf).to be_a(
633
- SendGrid4r::REST::Whitelabel::Domains::Record
634
- )
635
- expect(actual.dns.domain_spf.host).to eq('example.com')
636
- expect(actual.dns.domain_spf.type).to eq('txt')
637
- expect(actual.dns.domain_spf.data).to eq(
638
- 'v=spf1 include:mail2.example.com -all'
639
- )
640
- expect(actual.dns.domain_spf.valid).to eq(false)
641
589
  expect(actual.dns.dkim).to be_a(
642
590
  SendGrid4r::REST::Whitelabel::Domains::Record
643
591
  )
@@ -667,11 +615,6 @@ describe SendGrid4r::REST::Whitelabel::Domains do
667
615
  )
668
616
  expect(actual.validation_results.dkim2.valid).to be(true)
669
617
  expect(actual.validation_results.dkim2.reason).to be(nil)
670
- expect(actual.validation_results.spf).to be_a(
671
- SendGrid4r::REST::Whitelabel::Domains::ValidationResult
672
- )
673
- expect(actual.validation_results.spf.valid).to be(true)
674
- expect(actual.validation_results.spf.reason).to be(nil)
675
618
  end
676
619
  end
677
620
  end
@@ -85,7 +85,7 @@ describe SendGrid4r::REST::Whitelabel::Links do
85
85
  expect(@link2.subdomain).to eq(@subdomain_name + '2')
86
86
  expect(@link2.username).to eq(@username)
87
87
  expect(@link2.user_id).to be_a(Numeric)
88
- expect(@link2.default).to eq(true)
88
+ expect(@link2.default).to eq(false)
89
89
  expect(@link2.valid).to eq(false)
90
90
  expect(@link2.legacy).to eq(false)
91
91
  expect(@link2.dns.domain_cname).to be_a(
@@ -108,7 +108,7 @@ describe SendGrid4r::REST::Whitelabel::Links do
108
108
  expect(link2.subdomain).to eq(@subdomain_name + '2')
109
109
  expect(link2.username).to eq(@username)
110
110
  expect(link2.user_id).to be_a(Numeric)
111
- expect(link2.default).to eq(true)
111
+ expect(link2.default).to eq(false)
112
112
  expect(link2.valid).to eq(false)
113
113
  expect(link2.legacy).to eq(false)
114
114
  expect(link2.dns.domain_cname).to be_a(
@@ -148,7 +148,7 @@ describe SendGrid4r::REST::Whitelabel::Links do
148
148
 
149
149
  it '#delete_wl_link' do
150
150
  begin
151
- @client.delete_wl_link(id: @id1)
151
+ @client.delete_wl_link(id: @link2.id)
152
152
  rescue RestClient::ExceptionWithResponse => e
153
153
  puts e.inspect
154
154
  raise e
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.3.0
4
+ version: 1.4.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: 2015-09-26 00:00:00.000000000 Z
11
+ date: 2015-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -132,7 +132,9 @@ files:
132
132
  - lib/sendgrid4r/rest/asm/global_suppressions.rb
133
133
  - lib/sendgrid4r/rest/asm/groups.rb
134
134
  - lib/sendgrid4r/rest/asm/suppressions.rb
135
+ - lib/sendgrid4r/rest/bounces.rb
135
136
  - lib/sendgrid4r/rest/campaigns/campaigns.rb
137
+ - lib/sendgrid4r/rest/cancel_scheduled_sends.rb
136
138
  - lib/sendgrid4r/rest/categories/categories.rb
137
139
  - lib/sendgrid4r/rest/contacts/custom_fields.rb
138
140
  - lib/sendgrid4r/rest/contacts/lists.rb
@@ -155,10 +157,10 @@ files:
155
157
  - lib/sendgrid4r/rest/stats/parse.rb
156
158
  - lib/sendgrid4r/rest/stats/stats.rb
157
159
  - lib/sendgrid4r/rest/stats/subuser.rb
158
- - lib/sendgrid4r/rest/subusers/subusers.rb
160
+ - lib/sendgrid4r/rest/subusers.rb
159
161
  - lib/sendgrid4r/rest/templates/templates.rb
160
162
  - lib/sendgrid4r/rest/templates/versions.rb
161
- - lib/sendgrid4r/rest/users/users.rb
163
+ - lib/sendgrid4r/rest/users.rb
162
164
  - lib/sendgrid4r/rest/whitelabel/domains.rb
163
165
  - lib/sendgrid4r/rest/whitelabel/ips.rb
164
166
  - lib/sendgrid4r/rest/whitelabel/links.rb
@@ -174,7 +176,9 @@ files:
174
176
  - spec/rest/asm/global_suppressions_spec.rb
175
177
  - spec/rest/asm/groups_spec.rb
176
178
  - spec/rest/asm/suppressions_spec.rb
179
+ - spec/rest/bounces_spec.rb
177
180
  - spec/rest/campaigns/campaigns_spec.rb
181
+ - spec/rest/cancel_scheduled_sends_spec.rb
178
182
  - spec/rest/categories/categories_spec.rb
179
183
  - spec/rest/contacts/custom_fields_spec.rb
180
184
  - spec/rest/contacts/lists_spec.rb
@@ -196,10 +200,10 @@ files:
196
200
  - spec/rest/stats/parse_spec.rb
197
201
  - spec/rest/stats/stats_spec.rb
198
202
  - spec/rest/stats/subuser_spec.rb
199
- - spec/rest/subusers/subusers_spec.rb
203
+ - spec/rest/subusers_spec.rb
200
204
  - spec/rest/templates/templates_spec.rb
201
205
  - spec/rest/templates/versions_spec.rb
202
- - spec/rest/users/users_spec.rb
206
+ - spec/rest/users_spec.rb
203
207
  - spec/rest/whitelabel/domains_spec.rb
204
208
  - spec/rest/whitelabel/ips_spec.rb
205
209
  - spec/rest/whitelabel/links_spec.rb
@@ -239,7 +243,9 @@ test_files:
239
243
  - spec/rest/asm/global_suppressions_spec.rb
240
244
  - spec/rest/asm/groups_spec.rb
241
245
  - spec/rest/asm/suppressions_spec.rb
246
+ - spec/rest/bounces_spec.rb
242
247
  - spec/rest/campaigns/campaigns_spec.rb
248
+ - spec/rest/cancel_scheduled_sends_spec.rb
243
249
  - spec/rest/categories/categories_spec.rb
244
250
  - spec/rest/contacts/custom_fields_spec.rb
245
251
  - spec/rest/contacts/lists_spec.rb
@@ -261,10 +267,10 @@ test_files:
261
267
  - spec/rest/stats/parse_spec.rb
262
268
  - spec/rest/stats/stats_spec.rb
263
269
  - spec/rest/stats/subuser_spec.rb
264
- - spec/rest/subusers/subusers_spec.rb
270
+ - spec/rest/subusers_spec.rb
265
271
  - spec/rest/templates/templates_spec.rb
266
272
  - spec/rest/templates/versions_spec.rb
267
- - spec/rest/users/users_spec.rb
273
+ - spec/rest/users_spec.rb
268
274
  - spec/rest/whitelabel/domains_spec.rb
269
275
  - spec/rest/whitelabel/ips_spec.rb
270
276
  - spec/rest/whitelabel/links_spec.rb