core_pro.rb 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/core_pro/version.rb +1 -1
- data/lib/core_pro.rb +5 -4
- data/spec/core_pro_spec.rb +7 -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: 9cc3320dc6e0337106f9909f4e066b59f15a3c21048917896e070740183755e9
|
4
|
+
data.tar.gz: d248316415db95b24fb932ff2dd98f7730cc81be574b5ebb790aa65f224412d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56b4389a3ce504bb9b3724ff4677cd937a3fb75a30ec3defff791691fa71a6d1c99f84258042ecbb3a0ca2170ae405f55fe8752b34f190cc24b0bd4e9057da9e
|
7
|
+
data.tar.gz: 71b067af6335bbda34a81c769ec530b25b976b26fdb4707e34192a8dc2d5127bf09fd1c5fc8ed86d9851b531238a299215928f441a2445816d760632fd33b594
|
data/lib/core_pro/version.rb
CHANGED
data/lib/core_pro.rb
CHANGED
@@ -52,11 +52,11 @@ module CorePro
|
|
52
52
|
# @param payload [Hash] response payload to build a resource.
|
53
53
|
# @return [Object] instance or a list of instances.
|
54
54
|
def self.objectify(payload)
|
55
|
-
if payload['data'].is_a?(Array)
|
55
|
+
if payload.is_a?(Hash) && payload['data'].is_a?(Array)
|
56
56
|
return payload['data'].map { |data| new(data) }
|
57
57
|
end
|
58
58
|
|
59
|
-
return new(payload['data']) if payload
|
59
|
+
return new(payload['data']) if payload&.fetch('data', nil).is_a?(Hash)
|
60
60
|
|
61
61
|
payload
|
62
62
|
end
|
@@ -84,7 +84,7 @@ module CorePro
|
|
84
84
|
#
|
85
85
|
# @return [String]
|
86
86
|
def self.extract_error(response, parsed_response)
|
87
|
-
parsed_response
|
87
|
+
parsed_response&.fetch('errors', nil) || super(response, parsed_response)
|
88
88
|
end
|
89
89
|
|
90
90
|
# Validate error response
|
@@ -96,7 +96,8 @@ module CorePro
|
|
96
96
|
#
|
97
97
|
# @return [TrueClass] if status code is not a successful standard value
|
98
98
|
def self.error_response?(response, parsed_response)
|
99
|
-
|
99
|
+
errors = parsed_response&.fetch('errors', nil) || []
|
100
|
+
!(200..299).cover?(response.code) || errors.any?
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
data/spec/core_pro_spec.rb
CHANGED
@@ -178,4 +178,11 @@ RSpec.describe CorePro::Resource do
|
|
178
178
|
expect(new_account).to be_a(CorePro::Account)
|
179
179
|
end
|
180
180
|
end
|
181
|
+
|
182
|
+
describe '#error_response?', vcr: 'core_pro_errors' do
|
183
|
+
it do
|
184
|
+
expect { CorePro::Account.all }
|
185
|
+
.to raise_error(HTTP::RestClient::ResponseError, '502 Bad Gateway')
|
186
|
+
end
|
187
|
+
end
|
181
188
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: core_pro.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stas SUȘCOV
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http-rest_client
|