parity-sendgrid-api 0.0.4
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/.gitignore +6 -0
- data/.rspec +3 -0
- data/.travis.yml +3 -0
- data/.yardopts +6 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +67 -0
- data/LICENSE +22 -0
- data/README.md +261 -0
- data/Rakefile +12 -0
- data/lib/sendgrid/api.rb +7 -0
- data/lib/sendgrid/api/client.rb +43 -0
- data/lib/sendgrid/api/entities/category.rb +13 -0
- data/lib/sendgrid/api/entities/email.rb +13 -0
- data/lib/sendgrid/api/entities/entity.rb +83 -0
- data/lib/sendgrid/api/entities/list.rb +30 -0
- data/lib/sendgrid/api/entities/marketing_email.rb +20 -0
- data/lib/sendgrid/api/entities/profile.rb +14 -0
- data/lib/sendgrid/api/entities/response.rb +21 -0
- data/lib/sendgrid/api/entities/response_insert.rb +23 -0
- data/lib/sendgrid/api/entities/response_remove.rb +23 -0
- data/lib/sendgrid/api/entities/schedule.rb +13 -0
- data/lib/sendgrid/api/entities/sender_address.rb +13 -0
- data/lib/sendgrid/api/entities/stats.rb +14 -0
- data/lib/sendgrid/api/newsletter/categories.rb +74 -0
- data/lib/sendgrid/api/newsletter/emails.rb +69 -0
- data/lib/sendgrid/api/newsletter/lists.rb +64 -0
- data/lib/sendgrid/api/newsletter/marketing_emails.rb +72 -0
- data/lib/sendgrid/api/newsletter/recipients.rb +55 -0
- data/lib/sendgrid/api/newsletter/schedule.rb +70 -0
- data/lib/sendgrid/api/newsletter/sender_addresses.rb +80 -0
- data/lib/sendgrid/api/newsletter/utils.rb +34 -0
- data/lib/sendgrid/api/rest/errors/error.rb +66 -0
- data/lib/sendgrid/api/rest/resource.rb +58 -0
- data/lib/sendgrid/api/rest/response/parse_error.rb +19 -0
- data/lib/sendgrid/api/rest/response/parse_json.rb +24 -0
- data/lib/sendgrid/api/service.rb +23 -0
- data/lib/sendgrid/api/version.rb +5 -0
- data/lib/sendgrid/api/web/mail.rb +44 -0
- data/lib/sendgrid/api/web/profile.rb +38 -0
- data/lib/sendgrid/api/web/stats.rb +36 -0
- data/sendgrid-api.gemspec +23 -0
- data/spec/fixtures/categories.json +11 -0
- data/spec/fixtures/emails/email.json +6 -0
- data/spec/fixtures/emails/emails.json +10 -0
- data/spec/fixtures/errors/already_exists.json +3 -0
- data/spec/fixtures/errors/bad_request.json +6 -0
- data/spec/fixtures/errors/database_error.json +3 -0
- data/spec/fixtures/errors/does_not_exist.json +3 -0
- data/spec/fixtures/errors/forbidden.json +3 -0
- data/spec/fixtures/errors/invalid_fields.json +3 -0
- data/spec/fixtures/errors/not_scheduled.json +3 -0
- data/spec/fixtures/errors/unauthorized.json +6 -0
- data/spec/fixtures/lists/list.json +5 -0
- data/spec/fixtures/lists/lists.json +11 -0
- data/spec/fixtures/marketing_emails/marketing_email.json +19 -0
- data/spec/fixtures/marketing_emails/marketing_emails.json +10 -0
- data/spec/fixtures/profile.json +18 -0
- data/spec/fixtures/recipients.json +8 -0
- data/spec/fixtures/schedule.json +3 -0
- data/spec/fixtures/sender_addresses/sender_address.json +11 -0
- data/spec/fixtures/sender_addresses/sender_addresses.json +11 -0
- data/spec/fixtures/stats.json +50 -0
- data/spec/fixtures/success.json +3 -0
- data/spec/sendgrid/api/client_spec.rb +38 -0
- data/spec/sendgrid/api/entities/category_spec.rb +14 -0
- data/spec/sendgrid/api/entities/email_spec.rb +15 -0
- data/spec/sendgrid/api/entities/entity_spec.rb +279 -0
- data/spec/sendgrid/api/entities/list_spec.rb +34 -0
- data/spec/sendgrid/api/entities/marketing_email_spec.rb +31 -0
- data/spec/sendgrid/api/entities/profile_spec.rb +26 -0
- data/spec/sendgrid/api/entities/response_insert_spec.rb +28 -0
- data/spec/sendgrid/api/entities/response_remove_spec.rb +28 -0
- data/spec/sendgrid/api/entities/response_spec.rb +28 -0
- data/spec/sendgrid/api/entities/schedule_spec.rb +14 -0
- data/spec/sendgrid/api/entities/sender_address_spec.rb +21 -0
- data/spec/sendgrid/api/entities/stats_spec.rb +25 -0
- data/spec/sendgrid/api/newsletter/categories_spec.rb +247 -0
- data/spec/sendgrid/api/newsletter/emails_spec.rb +265 -0
- data/spec/sendgrid/api/newsletter/lists_spec.rb +307 -0
- data/spec/sendgrid/api/newsletter/marketing_emails_spec.rb +306 -0
- data/spec/sendgrid/api/newsletter/recipients_spec.rb +252 -0
- data/spec/sendgrid/api/newsletter/schedule_spec.rb +263 -0
- data/spec/sendgrid/api/newsletter/sender_addresses_spec.rb +300 -0
- data/spec/sendgrid/api/rest/errors/error_spec.rb +121 -0
- data/spec/sendgrid/api/rest/resource_spec.rb +145 -0
- data/spec/sendgrid/api/rest/response/parse_error_spec.rb +39 -0
- data/spec/sendgrid/api/rest/response/parse_json_spec.rb +45 -0
- data/spec/sendgrid/api/service_spec.rb +44 -0
- data/spec/sendgrid/api/version_spec.rb +11 -0
- data/spec/sendgrid/api/web/mail_spec.rb +111 -0
- data/spec/sendgrid/api/web/profile_spec.rb +110 -0
- data/spec/sendgrid/api/web/stats_spec.rb +94 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/support/helpers.rb +23 -0
- data/spec/support/mock.rb +30 -0
- data/spec/support/online.rb +114 -0
- data/spec/support/shared_examples.rb +104 -0
- metadata +225 -0
@@ -0,0 +1,263 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Sendgrid
|
4
|
+
module API
|
5
|
+
module Newsletter
|
6
|
+
module Schedule
|
7
|
+
describe Services do
|
8
|
+
|
9
|
+
subject { service }
|
10
|
+
let(:service) { described_class.new(resource) }
|
11
|
+
let(:resource) { REST::Resource.new(user, key) }
|
12
|
+
let(:user) { 'my_user' }
|
13
|
+
let(:key) { 'my_key' }
|
14
|
+
let(:sg_mock) { Sendgrid::Mock.new(user, key) }
|
15
|
+
|
16
|
+
let(:marketing_email_name) { 'my marketing email' }
|
17
|
+
let(:marketing_email) { Entities::MarketingEmail.new(:name => marketing_email_name) }
|
18
|
+
|
19
|
+
describe '#add' do
|
20
|
+
let(:url) { 'newsletter/schedule/add.json' }
|
21
|
+
let(:stub_post) { sg_mock.stub_post(url, :name => marketing_email_name) }
|
22
|
+
subject { service.add(marketing_email) }
|
23
|
+
|
24
|
+
context 'when add a schedule successfully' do
|
25
|
+
context 'with object' do
|
26
|
+
it_behaves_like 'a success response'
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with name' do
|
30
|
+
subject { service.add(marketing_email_name) }
|
31
|
+
it_behaves_like 'a success response'
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with after option' do
|
35
|
+
let(:after) { 10 }
|
36
|
+
let(:stub_post) { sg_mock.stub_post(url, :name => marketing_email_name, :after => after.to_s) }
|
37
|
+
subject { service.add(marketing_email_name, :after => after) }
|
38
|
+
it_behaves_like 'a success response'
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with at option' do
|
42
|
+
context 'when at is a string object' do
|
43
|
+
let(:at) { 'time in string' }
|
44
|
+
let(:stub_post) { sg_mock.stub_post(url, :name => marketing_email_name, :at => at) }
|
45
|
+
subject { service.add(marketing_email_name, :at => at) }
|
46
|
+
it_behaves_like 'a success response'
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when at is a time object' do
|
50
|
+
let(:at) { Time.now }
|
51
|
+
let(:stub_post) { sg_mock.stub_post(url, :name => marketing_email_name, :at => at.strftime('%Y-%m-%d %H:%M:%S%:z')) }
|
52
|
+
subject { service.add(marketing_email_name, :at => at) }
|
53
|
+
it_behaves_like 'a success response'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'with invalid options' do
|
58
|
+
let(:other) { 'other' }
|
59
|
+
let(:stub_post) { sg_mock.stub_post(url, :name => marketing_email_name) }
|
60
|
+
subject { service.add(marketing_email_name, :other => other) }
|
61
|
+
it_behaves_like 'a success response'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'when the schedule params are invalid' do
|
66
|
+
it_behaves_like 'an invalid fields response'
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'when the marketing email does not exist' do
|
70
|
+
it_behaves_like 'a does not exist response'
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when permission failed' do
|
74
|
+
it_behaves_like 'a forbidden response'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#get' do
|
79
|
+
let(:url) { 'newsletter/schedule/get.json' }
|
80
|
+
let(:stub_post) { sg_mock.stub_post(url, :name => marketing_email_name) }
|
81
|
+
subject { service.get(marketing_email) }
|
82
|
+
|
83
|
+
context 'when get the schedule successfully' do
|
84
|
+
before do
|
85
|
+
stub_post.to_return(:body => fixture('schedule.json'))
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'with object' do
|
89
|
+
its(:date) { should == '2013-10-30 18:01:40' }
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'with name' do
|
93
|
+
subject { service.get(marketing_email_name) }
|
94
|
+
its(:date) { should == '2013-10-30 18:01:40' }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'when the marketing email does not exist' do
|
99
|
+
it_behaves_like 'a does not exist response'
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'when permission failed' do
|
103
|
+
it_behaves_like 'a forbidden response'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '#delete' do
|
108
|
+
let(:url) { 'newsletter/schedule/delete.json' }
|
109
|
+
let(:stub_post) { sg_mock.stub_post(url, :name => marketing_email_name) }
|
110
|
+
subject { service.delete(marketing_email) }
|
111
|
+
|
112
|
+
context 'when delete the schedule successfully' do
|
113
|
+
context 'with object' do
|
114
|
+
it_behaves_like 'a success response'
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'with name' do
|
118
|
+
subject { service.delete(marketing_email_name) }
|
119
|
+
it_behaves_like 'a success response'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'when there is no previous schedule' do
|
124
|
+
it_behaves_like 'a not scheduled response'
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'when the marketing email does not exist' do
|
128
|
+
it_behaves_like 'a does not exist response'
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'when permission failed' do
|
132
|
+
it_behaves_like 'a forbidden response'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe 'online tests', :online => true do
|
137
|
+
include_examples 'online tests'
|
138
|
+
let(:online) { Online.new(env_user, env_key) }
|
139
|
+
let(:marketing_email) { online.marketing_email_example }
|
140
|
+
let(:client) { online.client }
|
141
|
+
|
142
|
+
context 'when credentials are valid' do
|
143
|
+
let(:resource) { REST::Resource.new(env_user, env_key) }
|
144
|
+
|
145
|
+
describe '#add' do
|
146
|
+
context 'when add a schedule successfully' do
|
147
|
+
before do
|
148
|
+
online.add_marketing_email_with_list
|
149
|
+
end
|
150
|
+
after do
|
151
|
+
online.delete_marketing_email_with_list
|
152
|
+
end
|
153
|
+
context 'with after option' do
|
154
|
+
it 'schedules a marketing email' do
|
155
|
+
subject.add(marketing_email, :after => 10).success?.should be_true
|
156
|
+
end
|
157
|
+
end
|
158
|
+
context 'with at option' do
|
159
|
+
it 'schedules a marketing email' do
|
160
|
+
subject.add(marketing_email, :at => (Time.now + 10*60)).success?.should be_true
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'when the schedule params are invalid' do
|
166
|
+
before do
|
167
|
+
online.add_marketing_email
|
168
|
+
end
|
169
|
+
after do
|
170
|
+
online.delete_marketing_email
|
171
|
+
end
|
172
|
+
it 'raises an error' do
|
173
|
+
expect { subject.add(marketing_email, :at => '2013') }.to raise_error(REST::Errors::BadRequest)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'when the marketing email does not exist' do
|
178
|
+
it 'raises an error' do
|
179
|
+
expect { subject.add(marketing_email) }.to raise_error(REST::Errors::Unauthorized)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe '#get' do
|
185
|
+
context 'when get the schedule successfully' do
|
186
|
+
before do
|
187
|
+
online.add_marketing_email_with_list
|
188
|
+
subject.add(marketing_email, :after => 10)
|
189
|
+
end
|
190
|
+
after do
|
191
|
+
online.delete_marketing_email_with_list
|
192
|
+
end
|
193
|
+
it 'gets the schedule' do
|
194
|
+
subject.get(marketing_email).date.should_not be_empty
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context 'when the marketing email does not exist' do
|
199
|
+
it 'raises an error' do
|
200
|
+
expect { subject.get(marketing_email) }.to raise_error(REST::Errors::Unauthorized)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
describe '#delete' do
|
206
|
+
context 'when delete the schedule successfully' do
|
207
|
+
before do
|
208
|
+
online.add_marketing_email_with_list
|
209
|
+
subject.add(marketing_email, :after => 10)
|
210
|
+
end
|
211
|
+
after do
|
212
|
+
online.delete_marketing_email_with_list
|
213
|
+
end
|
214
|
+
it 'deletes the schedule' do
|
215
|
+
subject.delete(marketing_email).success?.should be_true
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
context 'when there is no previous schedule' do
|
220
|
+
before do
|
221
|
+
online.add_marketing_email
|
222
|
+
end
|
223
|
+
after do
|
224
|
+
online.delete_marketing_email
|
225
|
+
end
|
226
|
+
it 'raises an error' do
|
227
|
+
expect { subject.delete(marketing_email) }.to raise_error(REST::Errors::Unauthorized)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context 'when the marketing email does not exist' do
|
232
|
+
it 'raises an error' do
|
233
|
+
expect { subject.delete(marketing_email) }.to raise_error(REST::Errors::Unauthorized)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
context 'when credentials are invalid' do
|
240
|
+
describe '#add' do
|
241
|
+
it 'raises an error' do
|
242
|
+
expect { subject.add(marketing_email) }.to raise_error(REST::Errors::Forbidden)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
describe '#get' do
|
247
|
+
it 'raises an error' do
|
248
|
+
expect { subject.get(marketing_email) }.to raise_error(REST::Errors::Forbidden)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
describe '#delete' do
|
253
|
+
it 'raises an error' do
|
254
|
+
expect { subject.delete(marketing_email) }.to raise_error(REST::Errors::Forbidden)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
@@ -0,0 +1,300 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Sendgrid
|
4
|
+
module API
|
5
|
+
module Newsletter
|
6
|
+
module SenderAddresses
|
7
|
+
describe Services do
|
8
|
+
|
9
|
+
subject { service }
|
10
|
+
let(:service) { described_class.new(resource) }
|
11
|
+
let(:resource) { REST::Resource.new(user, key) }
|
12
|
+
let(:user) { 'my_user' }
|
13
|
+
let(:key) { 'my_key' }
|
14
|
+
let(:sg_mock) { Sendgrid::Mock.new(user, key) }
|
15
|
+
|
16
|
+
let(:sender_address) { Entities::SenderAddress.new(:identity => identity, :email => email) }
|
17
|
+
let(:identity) { 'my sender address' }
|
18
|
+
let(:email) { 'john@example.com' }
|
19
|
+
|
20
|
+
describe '#add' do
|
21
|
+
let(:url) { 'newsletter/identity/add.json' }
|
22
|
+
let(:stub_post) { sg_mock.stub_post(url, sender_address.as_json) }
|
23
|
+
subject { service.add(sender_address) }
|
24
|
+
|
25
|
+
context 'when add a sender address successfully' do
|
26
|
+
it_behaves_like 'a success response'
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when the sender address already exists' do
|
30
|
+
it_behaves_like 'an unauthorized response'
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when the sender address is invalid' do
|
34
|
+
it_behaves_like 'an invalid fields response'
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when permission failed' do
|
38
|
+
it_behaves_like 'a forbidden response'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#edit' do
|
43
|
+
let(:url) { 'newsletter/identity/edit.json' }
|
44
|
+
let(:stub_post) { sg_mock.stub_post(url, sender_address.as_json) }
|
45
|
+
subject { service.edit(sender_address) }
|
46
|
+
|
47
|
+
context 'when edit a sender address successfully' do
|
48
|
+
it_behaves_like 'a success response'
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when edit the sender address identity successfully' do
|
52
|
+
let(:stub_post) { sg_mock.stub_post(url, sender_address.as_json.merge(:newidentity => new_identity)) }
|
53
|
+
let(:new_identity) { 'my new sender address' }
|
54
|
+
subject { service.edit(sender_address, new_identity) }
|
55
|
+
it_behaves_like 'a success response'
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when the sender address is invalid' do
|
59
|
+
it_behaves_like 'a does not exist response'
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when permission failed' do
|
63
|
+
it_behaves_like 'a forbidden response'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#get' do
|
68
|
+
let(:url) { 'newsletter/identity/get.json' }
|
69
|
+
let(:stub_post) { sg_mock.stub_post(url, :identity => identity) }
|
70
|
+
subject { service.get(sender_address) }
|
71
|
+
|
72
|
+
context 'when get the sender address successfully' do
|
73
|
+
before do
|
74
|
+
stub_post.to_return(:body => fixture('sender_addresses/sender_address.json'))
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'with name' do
|
78
|
+
subject { service.get(identity) }
|
79
|
+
its(:identity) { should == 'sendgrid' }
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'with object' do
|
83
|
+
its(:identity) { should == 'sendgrid' }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'when the sender address is not found' do
|
88
|
+
before do
|
89
|
+
stub_post.to_return(:body => fixture('errors/does_not_exist.json'), :status => 401)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'raises an error' do
|
93
|
+
expect { subject }.to raise_error(REST::Errors::Unauthorized)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when permission failed' do
|
98
|
+
it_behaves_like 'a forbidden response'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '#list' do
|
103
|
+
let(:url) { 'newsletter/identity/list.json' }
|
104
|
+
let(:stub_post) { sg_mock.stub_post(url) }
|
105
|
+
subject { service.list }
|
106
|
+
|
107
|
+
context 'when list sender addresses successfully' do
|
108
|
+
before do
|
109
|
+
stub_post.to_return(:body => fixture('sender_addresses/sender_addresses.json'))
|
110
|
+
end
|
111
|
+
it { should have(3).items }
|
112
|
+
describe 'first item' do
|
113
|
+
subject { service.list.first }
|
114
|
+
its(:identity) { should == 'sendgrid' }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'when permission failed' do
|
119
|
+
it_behaves_like 'a forbidden response'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe '#delete' do
|
124
|
+
let(:url) { 'newsletter/identity/delete.json' }
|
125
|
+
let(:stub_post) { sg_mock.stub_post(url, :identity => identity) }
|
126
|
+
subject { service.delete(sender_address) }
|
127
|
+
|
128
|
+
context 'when delete the sender address successfully' do
|
129
|
+
it_behaves_like 'a success response'
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'when the sender address is not found' do
|
133
|
+
it_behaves_like 'a does not exist response'
|
134
|
+
end
|
135
|
+
|
136
|
+
context 'when permission failed' do
|
137
|
+
it_behaves_like 'a forbidden response'
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe 'online tests', :online => true do
|
142
|
+
include_examples 'online tests'
|
143
|
+
let(:online) { Online.new(env_user, env_key) }
|
144
|
+
let(:sender_address) { online.sender_address_example }
|
145
|
+
|
146
|
+
context 'when credentials are valid' do
|
147
|
+
let(:resource) { REST::Resource.new(env_user, env_key) }
|
148
|
+
|
149
|
+
describe '#add' do
|
150
|
+
context 'when add a sender address successfully' do
|
151
|
+
after do
|
152
|
+
subject.delete(sender_address)
|
153
|
+
end
|
154
|
+
it 'adds the sender address' do
|
155
|
+
subject.add(sender_address).success?.should be_true
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'when the sender address already exists' do
|
160
|
+
before do
|
161
|
+
subject.add(sender_address)
|
162
|
+
end
|
163
|
+
after do
|
164
|
+
subject.delete(sender_address)
|
165
|
+
end
|
166
|
+
it 'raises an error' do
|
167
|
+
expect { subject.add(sender_address) }.to raise_error(Sendgrid::API::REST::Errors::Unauthorized)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context 'when the sender address is invalid' do
|
172
|
+
let(:email) { nil }
|
173
|
+
it 'raises an error' do
|
174
|
+
sender_address.email = email
|
175
|
+
expect { subject.add(sender_address) }.to raise_error(Sendgrid::API::REST::Errors::BadRequest)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe '#edit' do
|
181
|
+
context 'when edit a sender address successfully' do
|
182
|
+
let(:address) { 'new address' }
|
183
|
+
before do
|
184
|
+
subject.add(sender_address)
|
185
|
+
end
|
186
|
+
after do
|
187
|
+
subject.delete(sender_address)
|
188
|
+
end
|
189
|
+
it 'edits the sender address' do
|
190
|
+
sender_address.address = address
|
191
|
+
subject.edit(sender_address).success?.should be_true
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
context 'when edit the sender address identity successfully' do
|
196
|
+
let(:newidentity) { 'sendgrid-api sender address new' }
|
197
|
+
before do
|
198
|
+
subject.add(sender_address)
|
199
|
+
end
|
200
|
+
after do
|
201
|
+
subject.delete(newidentity)
|
202
|
+
end
|
203
|
+
it 'edits the sender address' do
|
204
|
+
subject.edit(sender_address, newidentity).success?.should be_true
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
context 'when the sender address is invalid' do
|
209
|
+
it 'raises an error' do
|
210
|
+
expect { subject.edit(sender_address) }.to raise_error(Sendgrid::API::REST::Errors::Unauthorized)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe '#get' do
|
216
|
+
context 'when get the sender address successfully' do
|
217
|
+
before do
|
218
|
+
subject.add(sender_address)
|
219
|
+
end
|
220
|
+
after do
|
221
|
+
subject.delete(sender_address)
|
222
|
+
end
|
223
|
+
it 'edits the sender address' do
|
224
|
+
sender = subject.get(sender_address)
|
225
|
+
sender.name.should == sender_address.name
|
226
|
+
sender.address.should == sender_address.address
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
context 'when the sender address is not found' do
|
231
|
+
it 'raises an error' do
|
232
|
+
expect { subject.edit(sender_address) }.to raise_error(Sendgrid::API::REST::Errors::Unauthorized)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
describe '#list' do
|
238
|
+
context 'when list sender addresses successfully' do
|
239
|
+
it 'gets all the sender addresses' do
|
240
|
+
subject.list.should_not be_empty
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
describe '#delete' do
|
246
|
+
context 'when delete the sender address successfully' do
|
247
|
+
before do
|
248
|
+
subject.add(sender_address)
|
249
|
+
end
|
250
|
+
it 'deletes the sender address' do
|
251
|
+
subject.delete(sender_address).success?.should be_true
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
context 'when the sender address is not found' do
|
256
|
+
it 'raises an error' do
|
257
|
+
expect { subject.delete(sender_address) }.to raise_error(Sendgrid::API::REST::Errors::Unauthorized)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
context 'when credentials are invalid' do
|
264
|
+
describe '#add' do
|
265
|
+
it 'raises an error' do
|
266
|
+
expect { subject.add(sender_address) }.to raise_error(REST::Errors::Forbidden)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
describe '#edit' do
|
271
|
+
it 'raises an error' do
|
272
|
+
expect { subject.edit(sender_address) }.to raise_error(REST::Errors::Forbidden)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
describe '#get' do
|
277
|
+
it 'raises an error' do
|
278
|
+
expect { subject.get(sender_address) }.to raise_error(REST::Errors::Forbidden)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
describe '#list' do
|
283
|
+
it 'raises an error' do
|
284
|
+
expect { subject.list }.to raise_error(REST::Errors::Forbidden)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
describe '#delete' do
|
289
|
+
it 'raises an error' do
|
290
|
+
expect { subject.delete(sender_address) }.to raise_error(REST::Errors::Forbidden)
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|