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 +4 -4
- data/Gemfile.lock +3 -16
- data/lib/xhash.rb +8 -0
- data/lib/xhash/client/api_client.rb +8 -0
- data/lib/xhash/client/json_api.rb +22 -5
- data/lib/xhash/error.rb +10 -2
- data/lib/xhash/ocr.rb +1 -1
- data/lib/xhash/structs/curp.rb +7 -6
- data/lib/xhash/version.rb +1 -1
- data/spec/spec_helper.rb +4 -1
- data/spec/xhash/database_lookup_spec.rb +13 -0
- data/spec/xhash/ocr_spec.rb +36 -6
- data/xhash_client.gemspec +0 -1
- metadata +5 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a9138a8aa4d278ebdf067d812d06a9f87ef30390ee0f86a33fb07f49f140dd4
|
4
|
+
data.tar.gz: 4be4b3647acfa20a10b42ab3b9b0c6f0548825d2d5a2120916b8ddc000f62e3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e43d879d10faf34886641bc1e0ccd20387e92017c0818ad8b77306b403f71182ac8e0e46890ec2a04febb7625f58e49bf460b7df164f915dfeb0fff7c61df95f
|
7
|
+
data.tar.gz: 3d13a691f4e44acc2958837ce3094f388409504dd1fbaee8c8c2d38d98f8ad82f7b25a1ee9f7f57e7a2b1450080e3402169536adef82f8a9fee6eac49bd338e6
|
data/Gemfile.lock
CHANGED
@@ -1,22 +1,15 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
|
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.
|
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
|
-
|
58
|
+
xhash_client!
|
72
59
|
|
73
60
|
BUNDLED WITH
|
74
61
|
1.17.3
|
data/lib/xhash.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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)
|
data/lib/xhash/error.rb
CHANGED
@@ -3,8 +3,14 @@ module Xhash
|
|
3
3
|
attr_reader :message, :response
|
4
4
|
|
5
5
|
def initialize(options = {})
|
6
|
-
|
7
|
-
|
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
|
data/lib/xhash/ocr.rb
CHANGED
data/lib/xhash/structs/curp.rb
CHANGED
@@ -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
|
-
:
|
7
|
+
:day_of_birth,
|
8
|
+
:gender,
|
9
|
+
:id,
|
6
10
|
:last_name,
|
7
11
|
:mothers_last_name,
|
8
|
-
:
|
12
|
+
:name,
|
9
13
|
:province_of_birth,
|
10
|
-
:
|
11
|
-
:updated_at,
|
12
|
-
:created_at,
|
13
|
-
:id
|
14
|
+
:updated_at
|
14
15
|
)
|
15
16
|
end
|
data/lib/xhash/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -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
|
|
data/spec/xhash/ocr_spec.rb
CHANGED
@@ -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:
|
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(
|
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(
|
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
|
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,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.
|
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
|
-
|
156
|
-
|
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:
|