phaxio 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/phaxio/client.rb +12 -6
- data/lib/phaxio/error.rb +1 -0
- data/lib/phaxio/version.rb +1 -1
- data/spec/client_spec.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 414f3c2357ed3a6ea5afec63b0f365640fac3ac2cd3409554e36f579582b4931
|
4
|
+
data.tar.gz: b1409dd06f09a01afec33edded877041e682cfefad226bfa54fa86b77efef9b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e79bb9271d141517d2d3cd640caf37dbd8a73a7783ee900ff27f51c12e485579b3bd2ae3f17fa0cf0c13b47cb621829d4c13b9b13ecc57fef083c791a1bdf0b7
|
7
|
+
data.tar.gz: 85199d1532aa1c29df9e1a1fae05b394f22af825bf9f23d35508b7267fdb8182337e554bf27024bda0b41f59988f8213f40a4606bd7d3aec810c0f036fc573d6
|
data/lib/phaxio/client.rb
CHANGED
@@ -52,13 +52,17 @@ module Phaxio
|
|
52
52
|
def handle_response response
|
53
53
|
content_type = response.headers[:content_type]
|
54
54
|
|
55
|
-
if content_type
|
56
|
-
|
55
|
+
if content_type
|
56
|
+
if content_type.start_with? 'application/json'
|
57
|
+
body = JSON.parse(response.body).with_indifferent_access
|
58
|
+
else
|
59
|
+
extension = MimeTypeHelper.extension_for_mimetype content_type
|
60
|
+
filename = File.join Dir.tmpdir, tmpname(extension)
|
61
|
+
File.open(filename, 'wb') { |file| file.write response.body }
|
62
|
+
body = {'success' => response.success?, 'data' => File.open(filename, 'rb')}
|
63
|
+
end
|
57
64
|
else
|
58
|
-
|
59
|
-
filename = File.join Dir.tmpdir, tmpname(extension)
|
60
|
-
File.open(filename, 'wb') { |file| file.write response.body }
|
61
|
-
body = {'success' => response.success?, 'data' => File.open(filename, 'rb')}
|
65
|
+
body = {}
|
62
66
|
end
|
63
67
|
|
64
68
|
if response.success?
|
@@ -85,6 +89,8 @@ module Phaxio
|
|
85
89
|
raise Error::InvalidRequestError, "#{status}: #{message}"
|
86
90
|
when 429
|
87
91
|
raise Error::RateLimitExceededError, "#{status}: #{message}"
|
92
|
+
when 503
|
93
|
+
raise Error::ServiceUnavailableError, "#{status}: #{message}"
|
88
94
|
else
|
89
95
|
raise Error::GeneralError, "#{status}: #{message}"
|
90
96
|
end
|
data/lib/phaxio/error.rb
CHANGED
data/lib/phaxio/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -19,6 +19,16 @@ RSpec.describe Phaxio::Client do
|
|
19
19
|
)
|
20
20
|
end
|
21
21
|
|
22
|
+
def test_response_503
|
23
|
+
instance_double(
|
24
|
+
Faraday::Response,
|
25
|
+
status: 503,
|
26
|
+
success?: false,
|
27
|
+
headers: {},
|
28
|
+
body: nil
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
22
32
|
describe 'making a request' do
|
23
33
|
it 'sends the request to Phaxio' do
|
24
34
|
endpoint = 'public/countries/'
|
@@ -118,6 +128,13 @@ RSpec.describe Phaxio::Client do
|
|
118
128
|
}.to raise_error(Phaxio::Error::RateLimitExceededError, '429: This is a test.')
|
119
129
|
end
|
120
130
|
|
131
|
+
it 'raises a service unavailable error if the response status is 503' do
|
132
|
+
expect(test_connection).to receive(:get) { test_response_503 }
|
133
|
+
expect {
|
134
|
+
client.request :get, 'test'
|
135
|
+
}.to raise_error(Phaxio::Error::ServiceUnavailableError, '503: ')
|
136
|
+
end
|
137
|
+
|
121
138
|
it 'raises a general error for if the response status is 5XX' do
|
122
139
|
expect(test_connection).to receive(:get) { test_response 500 }
|
123
140
|
expect {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phaxio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julien Negrotto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04
|
11
|
+
date: 2022-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|