xhash_client 0.3.2 → 0.3.3

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: 677093e282f54841ba892b25b0f35ed46df8c2b2ce58dea9204a49c089dd4596
4
- data.tar.gz: 18fc5c71735aacead2a901e4de38bdb62da8d0fab5d5e979378bb8e9a8c2335a
3
+ metadata.gz: 21dcbe25c117136469c5d4771d19702d88bd72d53049facee20ed68af710c4d9
4
+ data.tar.gz: ef284cac9fc9d8abde1732204705c0c56887cc2124ad4ed85fef5ae895a10a6a
5
5
  SHA512:
6
- metadata.gz: b463f5437405c26eced23fbd141938b46e16adbb1f1a47858878767b4ba89a804a5394252a606ab047373a7dab3c78af7de427fb5b291c9cccda2ded15397647
7
- data.tar.gz: c9fbed3159c04ec214192dcb3433c3cf3c4f029a58ea4261aaa4b62802962b1f9b51361df67e14ffac4de2b7fbd79f5a7bd3025af26fbed3ea3ba3f30c369c7c
6
+ metadata.gz: b8864b24dc5d915a72d7a55deb07950f431e7a748286b3a0fcb6bf53b44282902a3db215ab501eb9e61de3d2626dfbfd20a809544f4cddfb21180506ac83ed9e
7
+ data.tar.gz: cd939aed1627caf3be233bd18ae3e5db0ed53c25ddf8e19a05fb3183aec2a37d24c22dbf01b78c14542976857ae4c8010b97f622013a478437bbbab5a92730ae
data/Gemfile.lock CHANGED
@@ -1,22 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xhash_client (0.3.2)
5
- activesupport (~> 5.2)
4
+ xhash_client (0.3.3)
6
5
  httparty (~> 0.16.0)
7
6
  json (~> 2.0)
8
7
 
9
8
  GEM
10
9
  remote: https://rubygems.org/
11
10
  specs:
12
- activesupport (5.2.4.1)
13
- concurrent-ruby (~> 1.0, >= 1.0.2)
14
- i18n (>= 0.7, < 2)
15
- minitest (~> 5.1)
16
- tzinfo (~> 1.1)
17
11
  addressable (2.7.0)
18
12
  public_suffix (>= 2.0.2, < 5.0)
19
- concurrent-ruby (1.1.5)
20
13
  crack (0.4.3)
21
14
  safe_yaml (~> 1.0.0)
22
15
  diff-lcs (1.3)
@@ -25,13 +18,10 @@ GEM
25
18
  httparty (0.16.4)
26
19
  mime-types (~> 3.0)
27
20
  multi_xml (>= 0.5.2)
28
- i18n (1.7.1)
29
- concurrent-ruby (~> 1.0)
30
21
  json (2.2.0)
31
22
  mime-types (3.3.1)
32
23
  mime-types-data (~> 3.2015)
33
24
  mime-types-data (3.2019.1009)
34
- minitest (5.13.0)
35
25
  multi_xml (0.6.0)
36
26
  public_suffix (4.0.1)
37
27
  rspec (3.8.0)
@@ -53,9 +43,6 @@ GEM
53
43
  json (>= 1.8, < 3)
54
44
  simplecov-html (~> 0.10.0)
55
45
  simplecov-html (0.10.2)
56
- thread_safe (0.3.6)
57
- tzinfo (1.2.6)
58
- thread_safe (~> 0.1)
59
46
  webmock (3.7.2)
60
47
  addressable (>= 2.3.6)
61
48
  crack (>= 0.3.2)
@@ -13,7 +13,13 @@ module Xhash
13
13
  custom_headers = headers.merge(default_headers)
14
14
  response = HTTParty.get(Xhash.api_base + url, headers: custom_headers)
15
15
 
16
- JSON.parse(response.body, symbolize_names: true)
16
+ raise Xhash::Error.new(response) unless response_ok?(response)
17
+
18
+ begin
19
+ JSON.parse(response.body, symbolize_names: true)
20
+ rescue => exception
21
+ raise Xhash::MalformedResponse.new
22
+ end
17
23
  end
18
24
 
19
25
  def api_post(url:, body: {}, headers: {})
@@ -25,7 +31,13 @@ module Xhash
25
31
  body: body.to_json, headers: custom_headers
26
32
  )
27
33
 
28
- JSON.parse(response.body, symbolize_names: true)
34
+ raise Xhash::Error.new(response) unless response_ok?(response)
35
+
36
+ begin
37
+ JSON.parse(response.body, symbolize_names: true)
38
+ rescue => exception
39
+ raise Xhash::MalformedResponse.new
40
+ end
29
41
  end
30
42
 
31
43
  def api_post_multipart(url:, body: {}, headers: {})
@@ -37,8 +49,13 @@ module Xhash
37
49
  multipart: true, body: body, headers: custom_headers
38
50
  )
39
51
 
52
+ raise Xhash::Error.new(response) unless response_ok?(response)
40
53
  response.body
41
54
  end
55
+
56
+ def response_ok?(response)
57
+ !(response.code == 404 || response.code >= 500)
58
+ end
42
59
  end
43
60
 
44
61
  def self.included(base)
data/lib/xhash/error.rb CHANGED
@@ -12,4 +12,6 @@ module Xhash
12
12
  class MissingRequiredFieldError < Error; end
13
13
 
14
14
  class InvalidFieldError < Error; end
15
+
16
+ class MalformedResponse < Error; end
15
17
  end
data/lib/xhash/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Xhash
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.3'
3
3
  end
@@ -76,6 +76,19 @@ describe Xhash::SAT do
76
76
  end
77
77
  end
78
78
 
79
+ it 'fails with html error' do
80
+ curp = 'JIQJ890611HDFXNN04'
81
+
82
+ stub_request(:post, 'https://xhash.dev/api/database-lookup/renapo')
83
+ .to_return(body: '<p>bad</p>', status: 200)
84
+
85
+ begin
86
+ Xhash::DatabaseLookup.renapo(curp)
87
+ rescue => exception
88
+ expect(exception).to be_a(Xhash::MalformedResponse)
89
+ end
90
+ end
91
+
79
92
  it 'fails with malformed CURP' do
80
93
  curp = 'asdf'
81
94
 
@@ -88,7 +88,8 @@ describe Xhash::OCR do
88
88
  payload: {
89
89
  full_name: 'Prof Francesco Reichert',
90
90
  neighborhood: 'Parkerchester',
91
- full_address: 'CLL 59 E DIAGONAL 623\n76 Y 74 A Y RED CANALIZA\nLAS AMERICAS\nMERIDA, MERIDA YU\nC.P. 97302-CR -97111',
91
+ full_address:
92
+ 'CLL 59 E DIAGONAL 623\n76 Y 74 A Y RED CANALIZA\nLAS AMERICAS\nMERIDA, MERIDA YU\nC.P. 97302-CR -97111',
92
93
  zip_code: '97302',
93
94
  province: 'Port Rosemarieview,VT',
94
95
  date: '2019-09-01',
@@ -112,7 +113,9 @@ describe Xhash::OCR do
112
113
  expect(proof_of_address.type).to eq('TELMEX')
113
114
  expect(proof_of_address.date).to eq('2019-09-01')
114
115
  expect(proof_of_address.zip_code).to eq('97302')
115
- expect(proof_of_address.full_address).to eq('CLL 59 E DIAGONAL 623\n76 Y 74 A Y RED CANALIZA\nLAS AMERICAS\nMERIDA, MERIDA YU\nC.P. 97302-CR -97111')
116
+ expect(proof_of_address.full_address).to eq(
117
+ 'CLL 59 E DIAGONAL 623\n76 Y 74 A Y RED CANALIZA\nLAS AMERICAS\nMERIDA, MERIDA YU\nC.P. 97302-CR -97111'
118
+ )
116
119
  end
117
120
 
118
121
  it 'successfully serialize proof of address to document by file' do
@@ -158,7 +161,7 @@ describe Xhash::OCR do
158
161
  'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/7cd6994d9ad52e8943be1ae00bac60c461430cdf2af6159afa4b9be749706472.png'
159
162
  )
160
163
  rescue => exception
161
- expect(exception).to be_a(JSON::ParserError)
164
+ expect(exception).to be_a(Xhash::MalformedResponse)
162
165
  end
163
166
  end
164
167
 
data/xhash_client.gemspec CHANGED
@@ -20,7 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency 'httparty', "~> 0.16.0"
22
22
  spec.add_dependency "json", "~> 2.0"
23
- spec.add_dependency 'activesupport', "~> 5.2"
24
23
 
25
24
  spec.add_development_dependency "rspec", "~> 3.8"
26
25
  spec.add_development_dependency "webmock", "~> 3.7"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xhash_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yellowme
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
- - !ruby/object:Gem::Dependency
42
- name: activesupport
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '5.2'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '5.2'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rspec
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -152,8 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
138
  - !ruby/object:Gem::Version
153
139
  version: '0'
154
140
  requirements: []
155
- rubyforge_project:
156
- rubygems_version: 2.7.6
141
+ rubygems_version: 3.0.3
157
142
  signing_key:
158
143
  specification_version: 4
159
144
  summary: Ruby library built for Xhash API