send_sonar 1.1.0 → 2.0.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/.travis.yml +5 -8
- data/README.md +113 -37
- data/RELEASE.md +18 -11
- data/lib/send_sonar.rb +39 -5
- data/lib/send_sonar/client.rb +32 -18
- data/lib/send_sonar/configuration.rb +5 -1
- data/lib/send_sonar/endpoints.yml +16 -0
- data/lib/send_sonar/exceptions.rb +5 -2
- data/lib/send_sonar/version.rb +1 -1
- data/send_sonar.gemspec +7 -7
- data/spec/integrations/simple_desk_spec.rb +308 -41
- data/spec/vcr_cassettes/add_update_customer.yml +58 -0
- data/spec/vcr_cassettes/available_phone_number.yml +54 -0
- data/spec/vcr_cassettes/available_phone_number_bad_publishable_key.yml +52 -0
- data/spec/vcr_cassettes/close_customer.yml +58 -0
- data/spec/vcr_cassettes/close_customer_bad_token.yml +56 -0
- data/spec/vcr_cassettes/delete_customer_property_bad_token.yml +56 -0
- data/spec/vcr_cassettes/delete_customer_property_with_email.yml +58 -0
- data/spec/vcr_cassettes/delete_customer_property_with_phone_number.yml +58 -0
- data/spec/vcr_cassettes/get_customer.yml +50 -0
- data/spec/vcr_cassettes/get_customer_bad_token.yml +48 -0
- data/spec/vcr_cassettes/send_campaign.yml +56 -0
- data/spec/vcr_cassettes/send_campaign_bad_token.yml +56 -0
- metadata +67 -20
- data/Gemfile.ruby-18 +0 -6
@@ -24,7 +24,7 @@ module SendSonar
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def inspect
|
27
|
-
@original_exception.
|
27
|
+
"#{self.class.name}: #{@original_exception.to_s}: #{@original_exception.http_body}"
|
28
28
|
end
|
29
29
|
|
30
30
|
def to_s
|
@@ -39,9 +39,11 @@ module SendSonar
|
|
39
39
|
class UnknownRequestError < RequestException; end
|
40
40
|
class RequestTimeout < RequestException; end
|
41
41
|
class ConnectionRefused < RequestException; end
|
42
|
+
class TokenOrPublishableKeyNotFound < RequestException; end
|
42
43
|
|
43
44
|
class Customer < OpenStruct; end
|
44
45
|
class Message < OpenStruct; end
|
46
|
+
class Response < OpenStruct; end
|
45
47
|
|
46
48
|
module Exceptions
|
47
49
|
EXCEPTIONS_MAP = {
|
@@ -49,7 +51,8 @@ module SendSonar
|
|
49
51
|
"No Active Subscription" => NoActiveSubscription,
|
50
52
|
"Api Disabled For Company" => ApiDisabledForCompany,
|
51
53
|
"Request Timed Out" => RequestTimeout,
|
52
|
-
"Invalid Phone Number" => InvalidPhoneNumber
|
54
|
+
"Invalid Phone Number" => InvalidPhoneNumber,
|
55
|
+
"Token or publishable_key not found" => TokenOrPublishableKeyNotFound
|
53
56
|
}
|
54
57
|
end
|
55
58
|
end
|
data/lib/send_sonar/version.rb
CHANGED
data/send_sonar.gemspec
CHANGED
@@ -18,12 +18,12 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.
|
22
|
-
spec.add_development_dependency "rake", "~>
|
23
|
-
spec.add_development_dependency "rspec", "~> 3.
|
24
|
-
spec.add_development_dependency "vcr", "~>
|
25
|
-
spec.add_development_dependency "webmock", "~>
|
26
|
-
spec.add_development_dependency "json"
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.15", ">= 1.15.4"
|
22
|
+
spec.add_development_dependency "rake", "~> 12.1"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.6"
|
24
|
+
spec.add_development_dependency "vcr", "~> 3.0", ">= 3.0.3"
|
25
|
+
spec.add_development_dependency "webmock", "~> 3.0", ">= 3.0.1"
|
26
|
+
spec.add_development_dependency "json", "~> 2.1"
|
27
27
|
|
28
|
-
spec.add_runtime_dependency "rest-client",
|
28
|
+
spec.add_runtime_dependency "rest-client", "~> 2.0", ">= 2.0.2"
|
29
29
|
end
|
@@ -31,13 +31,13 @@ describe 'SendSonar' do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
shared_examples
|
34
|
+
shared_examples 'a mature, error handling gem' do |context|
|
35
35
|
context 'with an invalid token' do
|
36
36
|
let(:token) { 'FAKE_TOKEN' }
|
37
37
|
|
38
|
-
it 'raises a BadToken
|
38
|
+
it 'raises a BadToken exception' do
|
39
39
|
VCR.use_cassette("#{cassette_group}_bad_token") do
|
40
|
-
expect { response }.to
|
40
|
+
expect { response }.to raise_exception(SendSonar::BadToken, 'SendSonar::BadToken')
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -45,9 +45,9 @@ describe 'SendSonar' do
|
|
45
45
|
context 'with an inactive subscription' do
|
46
46
|
let(:token) { 'tKux9Vwkt0UuTVJqGUO80MGJHCAeebpe' }
|
47
47
|
|
48
|
-
it 'raises a
|
48
|
+
it 'raises a NoActiveSubscription exception' do
|
49
49
|
VCR.use_cassette("#{cassette_group}_no_subscription") do
|
50
|
-
expect { response }.to
|
50
|
+
expect { response }.to raise_exception(SendSonar::NoActiveSubscription, 'SendSonar::NoActiveSubscription')
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -55,9 +55,9 @@ describe 'SendSonar' do
|
|
55
55
|
context 'with disabled API' do
|
56
56
|
let(:token) { 'ts9mOO_O5Dc7TOBaEAQym-00RGEl3Uel' }
|
57
57
|
|
58
|
-
it 'raises
|
58
|
+
it 'raises an ApiDisabledForCompany error' do
|
59
59
|
VCR.use_cassette("#{cassette_group}_api_disabled") do
|
60
|
-
expect { response }.to
|
60
|
+
expect { response }.to raise_exception(SendSonar::ApiDisabledForCompany, 'SendSonar::ApiDisabledForCompany')
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -72,28 +72,28 @@ describe 'SendSonar' do
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
let(:cassette_group) {
|
75
|
+
let(:cassette_group) { 'add_customer' }
|
76
76
|
let(:response) { SendSonar.add_customer(params) }
|
77
77
|
let(:token) { '3Z9L8xFjeNmXL7Yn-pFJUBoxkVWBbl5o' }
|
78
78
|
let(:params) do
|
79
|
-
{ :phone_number =>
|
80
|
-
:email =>
|
81
|
-
:first_name =>
|
82
|
-
:last_name =>
|
83
|
-
:properties => { :great_customer =>
|
79
|
+
{ :phone_number => '5555555557',
|
80
|
+
:email => 'user@example.com',
|
81
|
+
:first_name => 'john',
|
82
|
+
:last_name => 'doe',
|
83
|
+
:properties => { :great_customer => 'true' } }
|
84
84
|
end
|
85
85
|
|
86
|
-
it_behaves_like
|
86
|
+
it_behaves_like 'a mature, error handling gem'
|
87
87
|
|
88
88
|
context 'with invalid params' do
|
89
89
|
let(:params) do
|
90
|
-
{ :phone_numbah =>
|
90
|
+
{ :phone_numbah => '5555555558' }
|
91
91
|
end
|
92
92
|
|
93
|
-
it 'raises a BadRequest
|
94
|
-
VCR.use_cassette(
|
95
|
-
expect { response }.to
|
96
|
-
'400 Bad Request: {"error":"phone_number is missing"}')
|
93
|
+
it 'raises a BadRequest exception with hint' do
|
94
|
+
VCR.use_cassette('add_customer_bad_params') do
|
95
|
+
expect { response }.to raise_exception(SendSonar::BadRequest,
|
96
|
+
'SendSonar::BadRequest: 400 Bad Request: {"error":"phone_number is missing"}')
|
97
97
|
end
|
98
98
|
end
|
99
99
|
end
|
@@ -101,10 +101,10 @@ describe 'SendSonar' do
|
|
101
101
|
context 'with an invalid phone number' do
|
102
102
|
let(:token) { 'tKux9Vwkt0UuTVJqGUO80MGJHCAeebpe' }
|
103
103
|
|
104
|
-
it 'raises a Invalid Phone Number error' do
|
104
|
+
it 'raises a BadRequest exception with Invalid Phone Number error message' do
|
105
105
|
VCR.use_cassette("#{cassette_group}_invalid_phone_number") do
|
106
|
-
expect { response }.to
|
107
|
-
'400 Bad Request: {"error":"Invalid Phone Number"}')
|
106
|
+
expect { response }.to raise_exception(SendSonar::BadRequest,
|
107
|
+
'SendSonar::BadRequest: 400 Bad Request: {"error":"Invalid Phone Number"}')
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
@@ -119,16 +119,60 @@ describe 'SendSonar' do
|
|
119
119
|
it 'includes the expected attributes' do
|
120
120
|
VCR.use_cassette('add_customer') do
|
121
121
|
customer = response
|
122
|
-
expect(customer.phone_number).to eq(
|
123
|
-
expect(customer.email).to eq(
|
124
|
-
expect(customer.first_name).to eq(
|
125
|
-
expect(customer.last_name).to eq(
|
126
|
-
expect(customer.properties).to eq({
|
122
|
+
expect(customer.phone_number).to eq('5555555557')
|
123
|
+
expect(customer.email).to eq('user@example.com')
|
124
|
+
expect(customer.first_name).to eq('john')
|
125
|
+
expect(customer.last_name).to eq('doe')
|
126
|
+
expect(customer.properties).to eq({ 'great_customer' => 'true' })
|
127
127
|
end
|
128
128
|
end
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
+
describe '.add_update_customer' do
|
133
|
+
before do
|
134
|
+
SendSonar.configure do |config|
|
135
|
+
config.token = token
|
136
|
+
config.env = :sandbox
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
let(:response) { SendSonar.add_update_customer(params) }
|
141
|
+
let(:token) { '99siwE4WRn6bg_B_ktm6h2w6Kez0JYLL' }
|
142
|
+
let(:phone_number) { '+13105555555' }
|
143
|
+
let(:email) { 'five@example.com' }
|
144
|
+
let(:first_name) { 'Five' }
|
145
|
+
let(:last_name) { 'Example' }
|
146
|
+
let(:properties) { { 'great_customer' => 'true' } }
|
147
|
+
let(:params) do
|
148
|
+
{ :phone_number => phone_number,
|
149
|
+
:email => email,
|
150
|
+
:first_name => first_name,
|
151
|
+
:last_name => last_name,
|
152
|
+
:properties => properties }
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'with proper param, active subscription' do
|
156
|
+
it 'returns a customer' do
|
157
|
+
VCR.use_cassette('add_update_customer') do
|
158
|
+
expect(response).to be_a(SendSonar::Customer)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'includes the expected attributes' do
|
163
|
+
VCR.use_cassette('add_update_customer') do
|
164
|
+
customer = response
|
165
|
+
expect(customer.phone_number).to eq(phone_number)
|
166
|
+
expect(customer.email).to eq(email)
|
167
|
+
expect(customer.first_name).to eq(first_name)
|
168
|
+
expect(customer.last_name).to eq(last_name)
|
169
|
+
expect(customer.properties).to eq(properties)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
132
176
|
describe '.message_customer' do
|
133
177
|
before do
|
134
178
|
SendSonar.configure do |config|
|
@@ -137,24 +181,24 @@ describe 'SendSonar' do
|
|
137
181
|
end
|
138
182
|
end
|
139
183
|
|
140
|
-
let(:cassette_group) {
|
184
|
+
let(:cassette_group) { 'message_customer' }
|
141
185
|
let(:response) { SendSonar.message_customer(params) }
|
142
186
|
let(:token) { '3Z9L8xFjeNmXL7Yn-pFJUBoxkVWBbl5o' }
|
143
187
|
let(:params) do
|
144
|
-
{ :to =>
|
188
|
+
{ :to => '5555555557', :text => 'this is the message text' }
|
145
189
|
end
|
146
190
|
|
147
|
-
it_behaves_like
|
191
|
+
it_behaves_like 'a mature, error handling gem'
|
148
192
|
|
149
193
|
context 'with invalid params' do
|
150
194
|
let(:params) do
|
151
|
-
{ :toz =>
|
195
|
+
{ :toz => '5555555558' }
|
152
196
|
end
|
153
197
|
|
154
|
-
it 'raises a BadRequest
|
155
|
-
VCR.use_cassette(
|
156
|
-
expect { response }.to
|
157
|
-
'400 Bad Request: {"error":"text is missing, to is missing"}')
|
198
|
+
it 'raises a BadRequest exception with hint' do
|
199
|
+
VCR.use_cassette('message_customer_bad_params') do
|
200
|
+
expect { response }.to raise_exception(SendSonar::BadRequest,
|
201
|
+
'SendSonar::BadRequest: 400 Bad Request: {"error":"text is missing, to is missing"}')
|
158
202
|
end
|
159
203
|
end
|
160
204
|
end
|
@@ -162,10 +206,10 @@ describe 'SendSonar' do
|
|
162
206
|
context 'with an invalid phone number' do
|
163
207
|
let(:token) { 'tKux9Vwkt0UuTVJqGUO80MGJHCAeebpe' }
|
164
208
|
|
165
|
-
it 'raises a Invalid Phone Number error' do
|
209
|
+
it 'raises a BadRequest exception with Invalid Phone Number error message' do
|
166
210
|
VCR.use_cassette("#{cassette_group}_invalid_phone_number") do
|
167
|
-
expect { response }.to
|
168
|
-
'400 Bad Request: {"error":"Invalid Phone Number"}')
|
211
|
+
expect { response }.to raise_exception(SendSonar::BadRequest,
|
212
|
+
'SendSonar::BadRequest: 400 Bad Request: {"error":"Invalid Phone Number"}')
|
169
213
|
end
|
170
214
|
end
|
171
215
|
end
|
@@ -180,11 +224,234 @@ describe 'SendSonar' do
|
|
180
224
|
it 'includes the expected attributes' do
|
181
225
|
VCR.use_cassette('message_customer') do
|
182
226
|
message = response
|
183
|
-
expect(message.to).to eq(
|
184
|
-
expect(message.text).to eq(
|
185
|
-
expect(message.status).to eq(
|
227
|
+
expect(message.to).to eq('5555555557')
|
228
|
+
expect(message.text).to eq('this is the message text')
|
229
|
+
expect(message.status).to eq('queued')
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
shared_examples 'an error receiving gem' do |context|
|
236
|
+
context 'with an invalid token' do
|
237
|
+
let(:token) { 'FAKE_TOKEN' }
|
238
|
+
|
239
|
+
it 'raises a BadToken exception' do
|
240
|
+
VCR.use_cassette("#{cassette_group}_bad_token") do
|
241
|
+
expect { response }.to raise_exception(SendSonar::TokenOrPublishableKeyNotFound, 'SendSonar::TokenOrPublishableKeyNotFound')
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
describe '.send_campaign' do
|
248
|
+
before do
|
249
|
+
SendSonar.configure do |config|
|
250
|
+
config.token = token
|
251
|
+
config.env = :sandbox
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
let(:cassette_group) { 'send_campaign' }
|
256
|
+
let(:response) { SendSonar.send_campaign(params) }
|
257
|
+
let(:token) { '99siwE4WRn6bg_B_ktm6h2w6Kez0JYLL' }
|
258
|
+
let(:recepient_number) { '+13105551111' }
|
259
|
+
let(:params) do
|
260
|
+
{ :to => recepient_number, :campaign_id => 'test_d0Bu23' }
|
261
|
+
end
|
262
|
+
|
263
|
+
context 'with proper params, active subscription' do
|
264
|
+
it 'returns a campaign sent receipt' do
|
265
|
+
VCR.use_cassette('send_campaign') do
|
266
|
+
expect(response).to be_a(SendSonar::Response)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'includes the expected attributes' do
|
271
|
+
VCR.use_cassette('send_campaign') do
|
272
|
+
campaign_sent = response
|
273
|
+
expect(campaign_sent.to).to eq(recepient_number)
|
274
|
+
expect(campaign_sent.text).to eq('sent')
|
275
|
+
expect(campaign_sent.status).to eq('queued')
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
it_behaves_like 'an error receiving gem'
|
281
|
+
end
|
282
|
+
|
283
|
+
describe '.close_customer' do
|
284
|
+
before do
|
285
|
+
SendSonar.configure do |config|
|
286
|
+
config.token = token
|
287
|
+
config.env = :sandbox
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
let(:cassette_group) { 'close_customer' }
|
292
|
+
let(:response) { SendSonar.close_customer(params) }
|
293
|
+
let(:token) { '99siwE4WRn6bg_B_ktm6h2w6Kez0JYLL' }
|
294
|
+
let(:params) do
|
295
|
+
{ :phone_number => '+13105551111' }
|
296
|
+
end
|
297
|
+
|
298
|
+
context 'with proper param, active subscription' do
|
299
|
+
it 'returns a customer closed status' do
|
300
|
+
VCR.use_cassette('close_customer') do
|
301
|
+
expect(response).to be_a(SendSonar::Response)
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'includes the expected attributes' do
|
306
|
+
VCR.use_cassette('close_customer') do
|
307
|
+
customer_closed = response
|
308
|
+
expect(customer_closed.success).to eq(true)
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
it_behaves_like 'an error receiving gem'
|
314
|
+
end
|
315
|
+
|
316
|
+
describe '.delete_customer_property' do
|
317
|
+
before do
|
318
|
+
SendSonar.configure do |config|
|
319
|
+
config.token = token
|
320
|
+
config.env = :sandbox
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
let(:cassette_group) { 'delete_customer_property' }
|
325
|
+
let(:response) { SendSonar.delete_customer_property(params) }
|
326
|
+
let(:token) { '99siwE4WRn6bg_B_ktm6h2w6Kez0JYLL' }
|
327
|
+
let(:phone_number) { '+13105551111' }
|
328
|
+
let(:email) { 'one@example.com' }
|
329
|
+
|
330
|
+
context 'using phone_number param' do
|
331
|
+
let(:property_name) { 'foo' }
|
332
|
+
let(:params) do
|
333
|
+
{ :phone_number => phone_number, :property_name => property_name }
|
334
|
+
end
|
335
|
+
it 'returns a customer property deleted' do
|
336
|
+
VCR.use_cassette('delete_customer_property_with_phone_number') do
|
337
|
+
expect(response).to be_a(SendSonar::Response)
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
it 'includes the expected attributes' do
|
342
|
+
VCR.use_cassette('delete_customer_property_with_phone_number') do
|
343
|
+
customer_property_deleted = response
|
344
|
+
expect(customer_property_deleted.phone_number).to eq(phone_number)
|
345
|
+
expect(customer_property_deleted.email).to eq(email)
|
346
|
+
expect(customer_property_deleted.property_name).to eq(property_name)
|
347
|
+
expect(customer_property_deleted.phone_number).to eq(phone_number)
|
348
|
+
expect(customer_property_deleted.deleted).to eq(true)
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
it_behaves_like 'an error receiving gem'
|
353
|
+
end
|
354
|
+
|
355
|
+
context 'using email param' do
|
356
|
+
let(:property_name) { 'bar' }
|
357
|
+
let(:params) do
|
358
|
+
{ :email => email, :property_name => property_name }
|
359
|
+
end
|
360
|
+
it 'returns a customer property deleted' do
|
361
|
+
VCR.use_cassette('delete_customer_property_with_email') do
|
362
|
+
expect(response).to be_a(SendSonar::Response)
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
it 'includes the expected attributes' do
|
367
|
+
VCR.use_cassette('delete_customer_property_with_email') do
|
368
|
+
customer_property_deleted = response
|
369
|
+
expect(customer_property_deleted.phone_number).to eq(phone_number)
|
370
|
+
expect(customer_property_deleted.email).to eq(email)
|
371
|
+
expect(customer_property_deleted.property_name).to eq(property_name)
|
372
|
+
expect(customer_property_deleted.phone_number).to eq(phone_number)
|
373
|
+
expect(customer_property_deleted.deleted).to eq(true)
|
374
|
+
end
|
375
|
+
end
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
describe '.get_customer' do
|
380
|
+
before do
|
381
|
+
SendSonar.configure do |config|
|
382
|
+
config.token = token
|
383
|
+
config.env = :sandbox
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
let(:cassette_group) { 'get_customer' }
|
388
|
+
let(:response) { SendSonar.get_customer(params) }
|
389
|
+
let(:token) { '99siwE4WRn6bg_B_ktm6h2w6Kez0JYLL' }
|
390
|
+
let(:phone_number) { '+13105551111' }
|
391
|
+
let(:params) do
|
392
|
+
{ :phone_number => phone_number }
|
393
|
+
end
|
394
|
+
|
395
|
+
context 'with proper param, active subscription' do
|
396
|
+
it 'returns a customer' do
|
397
|
+
VCR.use_cassette('get_customer') do
|
398
|
+
expect(response).to be_a(SendSonar::Customer)
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
it 'includes the expected attributes' do
|
403
|
+
VCR.use_cassette('get_customer') do
|
404
|
+
customer = response
|
405
|
+
expect(customer.phone_number).to eq(phone_number)
|
406
|
+
expect(customer).to respond_to(:first_name)
|
407
|
+
expect(customer).to respond_to(:last_name)
|
408
|
+
expect(customer).to respond_to(:email)
|
409
|
+
expect(customer).to respond_to(:assigned_phone_number)
|
410
|
+
expect(customer).to respond_to(:subscribed)
|
411
|
+
expect(customer).to respond_to(:unsubscribed_at)
|
412
|
+
expect(customer).to respond_to(:properties)
|
186
413
|
end
|
187
414
|
end
|
188
415
|
end
|
416
|
+
|
417
|
+
it_behaves_like 'an error receiving gem'
|
189
418
|
end
|
419
|
+
|
420
|
+
describe '.available_phone_number' do
|
421
|
+
before do
|
422
|
+
SendSonar.configure do |config|
|
423
|
+
config.publishable_key = publishable_key
|
424
|
+
config.env = :sandbox
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
let(:response) { SendSonar.available_phone_number }
|
429
|
+
let(:publishable_key) { 'f77a884d-4c52-4369-90c2-22a3d5607c24' }
|
430
|
+
|
431
|
+
context 'with proper param, active subscription' do
|
432
|
+
it 'returns an available number' do
|
433
|
+
VCR.use_cassette('available_phone_number') do
|
434
|
+
expect(response).to be_a(SendSonar::Response)
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
it 'includes the expected attributes' do
|
439
|
+
VCR.use_cassette('available_phone_number') do
|
440
|
+
available_number = response
|
441
|
+
expect(available_number).to respond_to(:available_number)
|
442
|
+
end
|
443
|
+
end
|
444
|
+
end
|
445
|
+
|
446
|
+
context 'with an invalid publishable key' do
|
447
|
+
let(:publishable_key) { 'BAD_PUBLISHABLE_KEY' }
|
448
|
+
|
449
|
+
it 'raises a TokenOrPublishableKeyNotFound exception' do
|
450
|
+
VCR.use_cassette('available_phone_number_bad_publishable_key') do
|
451
|
+
expect { response }.to raise_exception(SendSonar::TokenOrPublishableKeyNotFound, 'SendSonar::TokenOrPublishableKeyNotFound')
|
452
|
+
end
|
453
|
+
end
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
190
457
|
end
|