xhash_client 0.3.1 → 0.3.6

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: e41e823bbfa41b059071bc5a93fbb98502d941bfa147b96cf5c3495b114bc847
4
- data.tar.gz: 1193d96715a223e5628c9b8677e5bfebd08208a9094658d34b60368e61cdc716
3
+ metadata.gz: 7a9138a8aa4d278ebdf067d812d06a9f87ef30390ee0f86a33fb07f49f140dd4
4
+ data.tar.gz: 4be4b3647acfa20a10b42ab3b9b0c6f0548825d2d5a2120916b8ddc000f62e3f
5
5
  SHA512:
6
- metadata.gz: 2695f2a228913f1602a7ffa4b18176e23b1b15a61cece17c001e5d5ef1270cbd9681adb487f97f0ae7ca640316964aaeeb99020c8ce0b2674120fcef497d694a
7
- data.tar.gz: be7111ccbf7ff8dba07d3881c18d31c1e0e7b25992ceec868073e40c09aa3966f811f8cce663f095bfee4b41fa6a46eb23e398acb7bd8da1ace27cd6e34af406
6
+ metadata.gz: e43d879d10faf34886641bc1e0ccd20387e92017c0818ad8b77306b403f71182ac8e0e46890ec2a04febb7625f58e49bf460b7df164f915dfeb0fff7c61df95f
7
+ data.tar.gz: 3d13a691f4e44acc2958837ce3094f388409504dd1fbaee8c8c2d38d98f8ad82f7b25a1ee9f7f57e7a2b1450080e3402169536adef82f8a9fee6eac49bd338e6
@@ -1,22 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xhash (0.3.0)
5
- activesupport (~> 5.2)
4
+ xhash_client (0.3.5)
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.0)
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)
@@ -68,7 +55,7 @@ DEPENDENCIES
68
55
  rspec (~> 3.8)
69
56
  simplecov (~> 0.17)
70
57
  webmock (~> 3.7)
71
- xhash!
58
+ xhash_client!
72
59
 
73
60
  BUNDLED WITH
74
61
  1.17.3
@@ -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,15 +1,16 @@
1
1
  module Xhash
2
2
  CURP =
3
3
  Struct.new(
4
+ :country_of_birth,
5
+ :created_at,
4
6
  :curp,
5
- :name,
7
+ :day_of_birth,
8
+ :gender,
9
+ :id,
6
10
  :last_name,
7
11
  :mothers_last_name,
8
- :gender,
12
+ :name,
9
13
  :province_of_birth,
10
- :day_of_birth,
11
- :updated_at,
12
- :created_at,
13
- :id
14
+ :updated_at
14
15
  )
15
16
  end
@@ -1,3 +1,3 @@
1
1
  module Xhash
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.6'
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.1
4
+ version: 0.3.6
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: