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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd341d82e042f3fe4520d76418d70b183a15f680642789f974f518eaf2237502
4
- data.tar.gz: f1ead372dbb9278aecc3e6c925f46ad0bee55ee283b8090f153443e055f9303c
3
+ metadata.gz: 9cc3320dc6e0337106f9909f4e066b59f15a3c21048917896e070740183755e9
4
+ data.tar.gz: d248316415db95b24fb932ff2dd98f7730cc81be574b5ebb790aa65f224412d7
5
5
  SHA512:
6
- metadata.gz: 622037865ff00661fb309237b4509b88d0285e9913852895f4c21fda7dc86e738497b3eb58061322afbeef8df7c3cf7c90d1b33215cebc4bedcb17e1ea696b16
7
- data.tar.gz: 2f50f4a8b623f5546f8c167fb7936d7338bd58e6f28ddc2545395ea9f1ef717e8cb755b5c39c99e8acc255dc578ca9c7a2ac80a97709ba74231b32b1e075a32c
6
+ metadata.gz: 56b4389a3ce504bb9b3724ff4677cd937a3fb75a30ec3defff791691fa71a6d1c99f84258042ecbb3a0ca2170ae405f55fe8752b34f190cc24b0bd4e9057da9e
7
+ data.tar.gz: 71b067af6335bbda34a81c769ec530b25b976b26fdb4707e34192a8dc2d5127bf09fd1c5fc8ed86d9851b531238a299215928f441a2445816d760632fd33b594
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CorePro
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
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['data'].is_a?(Hash)
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['errors'] || super(response, 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
- !(200..299).cover?(response.code) && parsed_response['errors'].any?
99
+ errors = parsed_response&.fetch('errors', nil) || []
100
+ !(200..299).cover?(response.code) || errors.any?
100
101
  end
101
102
  end
102
103
 
@@ -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.2
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-08 00:00:00.000000000 Z
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