xhash_client 0.3.2 → 0.3.7

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: 677093e282f54841ba892b25b0f35ed46df8c2b2ce58dea9204a49c089dd4596
4
- data.tar.gz: 18fc5c71735aacead2a901e4de38bdb62da8d0fab5d5e979378bb8e9a8c2335a
3
+ metadata.gz: f1ad0c35530e11bc7e3cb01d6eb2d2c59e2fcbd72f0c755d1360d02658d89ded
4
+ data.tar.gz: 10b73ba81a848978e34d43de1a47b5f28a1835e526d507e68d5e3fd5b3ba563d
5
5
  SHA512:
6
- metadata.gz: b463f5437405c26eced23fbd141938b46e16adbb1f1a47858878767b4ba89a804a5394252a606ab047373a7dab3c78af7de427fb5b291c9cccda2ded15397647
7
- data.tar.gz: c9fbed3159c04ec214192dcb3433c3cf3c4f029a58ea4261aaa4b62802962b1f9b51361df67e14ffac4de2b7fbd79f5a7bd3025af26fbed3ea3ba3f30c369c7c
6
+ metadata.gz: dbd173c4794869783b4c9f2324c5fdd8d98083e22e3dbdfb6c32a421996f47362b4504634421b85139a609eed0d5fa8cca78793c1718fae5c22c65b70799d761
7
+ data.tar.gz: 0b45ad9c2de3050768c824e2ab90085062bd05df394ce32e069c371c68f371cc8a6e9047e330f757158aa13532c931433e396cce0c6a59fc316d9b642ed636e2
@@ -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.7)
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
- mime-types-data (3.2019.1009)
34
- minitest (5.13.0)
24
+ mime-types-data (3.2020.0512)
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)
@@ -40,4 +40,12 @@ module Xhash
40
40
  def self.api_key=(api_key)
41
41
  @api_key = api_key
42
42
  end
43
+
44
+ def self.timeout
45
+ @timeout
46
+ end
47
+
48
+ def self.timeout=(timeout)
49
+ @timeout = timeout
50
+ end
43
51
  end
@@ -23,5 +23,13 @@ module Xhash
23
23
  def self.api_key=(api_key)
24
24
  @api_key = api_key
25
25
  end
26
+
27
+ def self.timeout
28
+ @timeout
29
+ end
30
+
31
+ def self.api_key=(timeout)
32
+ @timeout = timeout
33
+ end
26
34
  end
27
35
  end
@@ -11,9 +11,15 @@ module Xhash
11
11
 
12
12
  def api_get(url:, headers: {})
13
13
  custom_headers = headers.merge(default_headers)
14
- response = HTTParty.get(Xhash.api_base + url, headers: custom_headers)
14
+ response = HTTParty.get(Xhash.api_base + url, headers: custom_headers, timeout: Xhash.timeout)
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: {})
@@ -22,10 +28,16 @@ module Xhash
22
28
  response =
23
29
  HTTParty.post(
24
30
  Xhash.api_base + url,
25
- body: body.to_json, headers: custom_headers
31
+ body: body.to_json, headers: custom_headers, timeout: Xhash.timeout
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: {})
@@ -34,11 +46,16 @@ module Xhash
34
46
  response =
35
47
  HTTParty.post(
36
48
  Xhash.api_base + url,
37
- multipart: true, body: body, headers: custom_headers
49
+ multipart: true, body: body, headers: custom_headers, timeout: Xhash.timeout
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)
@@ -3,8 +3,14 @@ module Xhash
3
3
  attr_reader :message, :response
4
4
 
5
5
  def initialize(options = {})
6
- @message = options[:message]
7
- @response = options[:response]
6
+ if options.is_a? Hash
7
+ @message = options[:message]
8
+ @response = options[:response]
9
+ else
10
+ @message = "Server error"
11
+ @response = options
12
+ end
13
+
8
14
  super
9
15
  end
10
16
  end
@@ -12,4 +18,6 @@ module Xhash
12
18
  class MissingRequiredFieldError < Error; end
13
19
 
14
20
  class InvalidFieldError < Error; end
21
+
22
+ class MalformedResponse < Error; end
15
23
  end
@@ -96,7 +96,7 @@ module Xhash
96
96
  )
97
97
  body = {
98
98
  'document_url' => document_url, 'document_file' => document_file
99
- }
99
+ }.compact
100
100
 
101
101
  response =
102
102
  if document_file.nil?
@@ -1,3 +1,3 @@
1
1
  module Xhash
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.7'
3
3
  end
@@ -6,4 +6,7 @@ require 'xhash'
6
6
 
7
7
  SimpleCov.start { add_filter '/spec/' }
8
8
 
9
- RSpec.configure { |config| config.before(:all) { Xhash.api_key = 'api_key' } }
9
+ RSpec.configure { |config| config.before(:all) {
10
+ Xhash.api_key = 'api_key'
11
+ Xhash.timeout = 10
12
+ } }
@@ -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
 
@@ -7,6 +7,8 @@ describe Xhash::OCR do
7
7
  body:
8
8
  JSON.dump(
9
9
  {
10
+ result: true,
11
+ execution_time: 2.7695868015289307,
10
12
  payload: {
11
13
  name: 'MARGARITA',
12
14
  last_name: 'GOMEZ',
@@ -16,7 +18,8 @@ describe Xhash::OCR do
16
18
  neighborhood: 'NACIO PITAGORAS 1253',
17
19
  zip_code: 'INT 4',
18
20
  city: 'COL. MORELOS 04800',
19
- type: 'INE'
21
+ type: 'INE',
22
+ control: "2"
20
23
  }
21
24
  }
22
25
  ),
@@ -46,6 +49,8 @@ describe Xhash::OCR do
46
49
  body:
47
50
  JSON.dump(
48
51
  {
52
+ result: true,
53
+ execution_time: 2.7695868015289307,
49
54
  payload: {
50
55
  name: 'MARGARITA',
51
56
  last_name: 'GOMEZ',
@@ -55,7 +60,8 @@ describe Xhash::OCR do
55
60
  neighborhood: 'NACIO PITAGORAS 1253',
56
61
  zip_code: 'INT 4',
57
62
  city: 'COL. MORELOS 04800',
58
- type: 'INE'
63
+ type: 'INE',
64
+ control: "2"
59
65
  }
60
66
  }
61
67
  ),
@@ -88,7 +94,8 @@ describe Xhash::OCR do
88
94
  payload: {
89
95
  full_name: 'Prof Francesco Reichert',
90
96
  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',
97
+ full_address:
98
+ 'CLL 59 E DIAGONAL 623\n76 Y 74 A Y RED CANALIZA\nLAS AMERICAS\nMERIDA, MERIDA YU\nC.P. 97302-CR -97111',
92
99
  zip_code: '97302',
93
100
  province: 'Port Rosemarieview,VT',
94
101
  date: '2019-09-01',
@@ -112,7 +119,9 @@ describe Xhash::OCR do
112
119
  expect(proof_of_address.type).to eq('TELMEX')
113
120
  expect(proof_of_address.date).to eq('2019-09-01')
114
121
  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')
122
+ expect(proof_of_address.full_address).to eq(
123
+ 'CLL 59 E DIAGONAL 623\n76 Y 74 A Y RED CANALIZA\nLAS AMERICAS\nMERIDA, MERIDA YU\nC.P. 97302-CR -97111'
124
+ )
116
125
  end
117
126
 
118
127
  it 'successfully serialize proof of address to document by file' do
@@ -158,7 +167,7 @@ describe Xhash::OCR do
158
167
  'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/7cd6994d9ad52e8943be1ae00bac60c461430cdf2af6159afa4b9be749706472.png'
159
168
  )
160
169
  rescue => exception
161
- expect(exception).to be_a(JSON::ParserError)
170
+ expect(exception).to be_a(Xhash::MalformedResponse)
162
171
  end
163
172
  end
164
173
 
@@ -178,6 +187,8 @@ describe Xhash::OCR do
178
187
  body:
179
188
  JSON.dump(
180
189
  {
190
+ result: true,
191
+ execution_time: 2.7695868015289307,
181
192
  payload: {
182
193
  name: 'MARGARITA',
183
194
  last_name: 'GOMEZ',
@@ -187,7 +198,8 @@ describe Xhash::OCR do
187
198
  neighborhood: 'NACIO PITAGORAS 1253',
188
199
  zip_code: 'INT 4',
189
200
  city: 'COL. MORELOS 04800',
190
- type: 'INE'
201
+ type: 'INE',
202
+ control: "2"
191
203
  }
192
204
  }
193
205
  ),
@@ -292,6 +304,24 @@ describe Xhash::OCR do
292
304
  expect(exception).to be_a(Xhash::InvalidFieldError)
293
305
  end
294
306
  end
307
+
308
+ it 'fails to serialize to document with html error' do
309
+ stub_request(:post, 'https://xhash.dev/api/ocr/proof-of-address').to_return(
310
+ body: '<p>error</p>',
311
+ status: 500,
312
+ headers: { 'Content-Type' => 'text/html; charset=UTF-8' }
313
+ )
314
+
315
+ begin
316
+ ine =
317
+ Xhash::OCR.proof_of_address(
318
+ document_url:
319
+ 'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/7cd6994d9ad52e8943be1ae00bac60c461430cdf2af6159afa4b9be749706472.png'
320
+ )
321
+ rescue => exception
322
+ expect(exception).to be_a(Xhash::Error)
323
+ end
324
+ end
295
325
  end
296
326
 
297
327
  describe '.ine_reverse' do
@@ -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,11 +1,11 @@
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.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yellowme
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2019-10-10 00:00:00.000000000 Z
@@ -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
@@ -137,7 +123,7 @@ homepage: https://rubygems.org/gems/xhash-ruby
137
123
  licenses:
138
124
  - MIT
139
125
  metadata: {}
140
- post_install_message:
126
+ post_install_message:
141
127
  rdoc_options: []
142
128
  require_paths:
143
129
  - lib
@@ -152,9 +138,8 @@ 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
157
- signing_key:
141
+ rubygems_version: 3.1.2
142
+ signing_key:
158
143
  specification_version: 4
159
144
  summary: Ruby library built for Xhash API
160
145
  test_files: