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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 508fcbe635de23974bfdefe06aec6811fd7f91bd03377dd4a90b971cd1b6a44f
4
- data.tar.gz: e33347de232350332fe604ecae8c0f511a3774fb9ef7c863f6a269bb53bad787
3
+ metadata.gz: 414f3c2357ed3a6ea5afec63b0f365640fac3ac2cd3409554e36f579582b4931
4
+ data.tar.gz: b1409dd06f09a01afec33edded877041e682cfefad226bfa54fa86b77efef9b3
5
5
  SHA512:
6
- metadata.gz: 6a041ed3d71f144ae2c2776a69be5d947982f1eb76c2a2e748f07b245d48ac8714c9199702b71a9b8c0cd404ea6318518834cb9da9365f569cc6b35633c66e83
7
- data.tar.gz: d50baaa1fc873a3a20268fb0c56d1b902d0b922d8fcdb731d40e23d89c74bd9c6fea3e35aa66e8c7472502b5af7ac1ad060b5cec22d3fe244e816d98d9be10d5
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.start_with? 'application/json'
56
- body = JSON.parse(response.body).with_indifferent_access
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
- extension = MimeTypeHelper.extension_for_mimetype content_type
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
@@ -6,6 +6,7 @@ module Phaxio
6
6
  NotFoundError
7
7
  InvalidRequestError
8
8
  RateLimitExceededError
9
+ ServiceUnavailableError
9
10
  GeneralError
10
11
  ApiConnectionError
11
12
  ].each { |error_klass_name| const_set error_klass_name, Class.new(PhaxioError) }
@@ -1,3 +1,3 @@
1
1
  module Phaxio
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.1"
3
3
  end
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.0
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-27 00:00:00.000000000 Z
11
+ date: 2022-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday