xhash_client 0.3.0 → 0.3.5

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.
@@ -0,0 +1,395 @@
1
+ require 'spec_helper'
2
+
3
+ describe Xhash::OCR do
4
+ describe '.generic' do
5
+ it 'successfully serialize INE to document by url' do
6
+ stub_request(:post, 'https://xhash.dev/api/ocr').to_return(
7
+ body:
8
+ JSON.dump(
9
+ {
10
+ result: true,
11
+ execution_time: 2.7695868015289307,
12
+ payload: {
13
+ name: 'MARGARITA',
14
+ last_name: 'GOMEZ',
15
+ mothers_last_name: 'VELAZQUEZ',
16
+ expiration_date: '2024-12-31',
17
+ street: 'C',
18
+ neighborhood: 'NACIO PITAGORAS 1253',
19
+ zip_code: 'INT 4',
20
+ city: 'COL. MORELOS 04800',
21
+ type: 'INE',
22
+ control: "2"
23
+ }
24
+ }
25
+ ),
26
+ status: 200
27
+ )
28
+
29
+ ine =
30
+ Xhash::OCR.generic(
31
+ document_url:
32
+ 'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/7cd6994d9ad52e8943be1ae00bac60c461430cdf2af6159afa4b9be749706472.png'
33
+ )
34
+
35
+ expect(ine).to be_a(Xhash::Identification)
36
+ expect(ine.name).to eq('MARGARITA')
37
+ expect(ine.last_name).to eq('GOMEZ')
38
+ expect(ine.mothers_last_name).to eq('VELAZQUEZ')
39
+ expect(ine.expiration_date).to eq('2024-12-31')
40
+ expect(ine.street).to eq('C')
41
+ expect(ine.neighborhood).to eq('NACIO PITAGORAS 1253')
42
+ expect(ine.zip_code).to eq('INT 4')
43
+ expect(ine.city).to eq('COL. MORELOS 04800')
44
+ expect(ine.type).to eq('INE')
45
+ end
46
+
47
+ it 'successfully serialize INE to document by file' do
48
+ stub_request(:post, 'https://xhash.dev/api/ocr').to_return(
49
+ body:
50
+ JSON.dump(
51
+ {
52
+ result: true,
53
+ execution_time: 2.7695868015289307,
54
+ payload: {
55
+ name: 'MARGARITA',
56
+ last_name: 'GOMEZ',
57
+ mothers_last_name: 'VELAZQUEZ',
58
+ expiration_date: '2024-12-31',
59
+ street: 'C',
60
+ neighborhood: 'NACIO PITAGORAS 1253',
61
+ zip_code: 'INT 4',
62
+ city: 'COL. MORELOS 04800',
63
+ type: 'INE',
64
+ control: "2"
65
+ }
66
+ }
67
+ ),
68
+ status: 200
69
+ )
70
+
71
+ document = File.open('spec/files/ife_front.png')
72
+
73
+ ine = Xhash::OCR.generic(document_file: document)
74
+
75
+ document.close
76
+
77
+ expect(ine).to be_a(Xhash::Identification)
78
+ expect(ine.name).to eq('MARGARITA')
79
+ expect(ine.last_name).to eq('GOMEZ')
80
+ expect(ine.mothers_last_name).to eq('VELAZQUEZ')
81
+ expect(ine.expiration_date).to eq('2024-12-31')
82
+ expect(ine.street).to eq('C')
83
+ expect(ine.neighborhood).to eq('NACIO PITAGORAS 1253')
84
+ expect(ine.zip_code).to eq('INT 4')
85
+ expect(ine.city).to eq('COL. MORELOS 04800')
86
+ expect(ine.type).to eq('INE')
87
+ end
88
+
89
+ it 'successfully serialize proof of address to document by url' do
90
+ stub_request(:post, 'https://xhash.dev/api/ocr').to_return(
91
+ body:
92
+ JSON.dump(
93
+ {
94
+ payload: {
95
+ full_name: 'Prof Francesco Reichert',
96
+ neighborhood: 'Parkerchester',
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',
99
+ zip_code: '97302',
100
+ province: 'Port Rosemarieview,VT',
101
+ date: '2019-09-01',
102
+ type: 'TELMEX'
103
+ }
104
+ }
105
+ ),
106
+ status: 200
107
+ )
108
+
109
+ proof_of_address =
110
+ Xhash::OCR.generic(
111
+ document_url:
112
+ 'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/c7d40899ab9ed7aa689837e39b64a6eb07117353f88ce3f8b9d1ca73bea3d80e.png'
113
+ )
114
+
115
+ expect(proof_of_address).to be_a(Xhash::ProofOfAddress)
116
+ expect(proof_of_address.full_name).to eq('Prof Francesco Reichert')
117
+ expect(proof_of_address.neighborhood).to eq('Parkerchester')
118
+ expect(proof_of_address.province).to eq('Port Rosemarieview,VT')
119
+ expect(proof_of_address.type).to eq('TELMEX')
120
+ expect(proof_of_address.date).to eq('2019-09-01')
121
+ expect(proof_of_address.zip_code).to eq('97302')
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
+ )
125
+ end
126
+
127
+ it 'successfully serialize proof of address to document by file' do
128
+ stub_request(:post, 'https://xhash.dev/api/ocr').to_return(
129
+ body:
130
+ JSON.dump(
131
+ {
132
+ payload: {
133
+ full_name: 'Prof Francesco Reichert',
134
+ neighborhood: 'Parkerchester',
135
+ province: 'Port Rosemarieview,VT',
136
+ type: 'TELMEX'
137
+ }
138
+ }
139
+ ),
140
+ status: 200
141
+ )
142
+
143
+ document = File.open('spec/files/telmex.png')
144
+
145
+ proof_of_address = Xhash::OCR.generic(document_file: document)
146
+
147
+ document.close
148
+
149
+ expect(proof_of_address).to be_a(Xhash::ProofOfAddress)
150
+ expect(proof_of_address.full_name).to eq('Prof Francesco Reichert')
151
+ expect(proof_of_address.neighborhood).to eq('Parkerchester')
152
+ expect(proof_of_address.province).to eq('Port Rosemarieview,VT')
153
+ expect(proof_of_address.type).to eq('TELMEX')
154
+ end
155
+
156
+ it 'fails to serialize INE to document with html error' do
157
+ stub_request(:post, 'https://xhash.dev/api/ocr').to_return(
158
+ body: '<p>error</p>',
159
+ status: 200,
160
+ headers: { 'Content-Type' => 'text/html; charset=UTF-8' }
161
+ )
162
+
163
+ begin
164
+ ine =
165
+ Xhash::OCR.generic(
166
+ document_url:
167
+ 'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/7cd6994d9ad52e8943be1ae00bac60c461430cdf2af6159afa4b9be749706472.png'
168
+ )
169
+ rescue => exception
170
+ expect(exception).to be_a(Xhash::MalformedResponse)
171
+ end
172
+ end
173
+
174
+ it 'fails with missing file or url' do
175
+ begin
176
+ ine = Xhash::OCR.generic
177
+ rescue => exception
178
+ expect(exception).to be_a(Xhash::MissingRequiredFieldError)
179
+ expect(exception.message).to eq(Xhash::ErrorMessage::MISSING_FILE)
180
+ end
181
+ end
182
+ end
183
+
184
+ describe '.identification' do
185
+ it 'successfully serialize INE to document' do
186
+ stub_request(:post, 'https://xhash.dev/api/ocr/identification').to_return(
187
+ body:
188
+ JSON.dump(
189
+ {
190
+ result: true,
191
+ execution_time: 2.7695868015289307,
192
+ payload: {
193
+ name: 'MARGARITA',
194
+ last_name: 'GOMEZ',
195
+ mothers_last_name: 'VELAZQUEZ',
196
+ expiration_date: '2024-12-31',
197
+ street: 'C',
198
+ neighborhood: 'NACIO PITAGORAS 1253',
199
+ zip_code: 'INT 4',
200
+ city: 'COL. MORELOS 04800',
201
+ type: 'INE',
202
+ control: "2"
203
+ }
204
+ }
205
+ ),
206
+ status: 200
207
+ )
208
+
209
+ ine_anverse =
210
+ Xhash::OCR.identification(
211
+ document_url:
212
+ 'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/7cd6994d9ad52e8943be1ae00bac60c461430cdf2af6159afa4b9be749706472.png'
213
+ )
214
+
215
+ expect(ine_anverse).to be_a(Xhash::Identification)
216
+ expect(ine_anverse.name).to eq('MARGARITA')
217
+ expect(ine_anverse.last_name).to eq('GOMEZ')
218
+ expect(ine_anverse.mothers_last_name).to eq('VELAZQUEZ')
219
+ expect(ine_anverse.expiration_date).to eq('2024-12-31')
220
+ expect(ine_anverse.street).to eq('C')
221
+ expect(ine_anverse.neighborhood).to eq('NACIO PITAGORAS 1253')
222
+ expect(ine_anverse.zip_code).to eq('INT 4')
223
+ expect(ine_anverse.city).to eq('COL. MORELOS 04800')
224
+ expect(ine_anverse.type).to eq('INE')
225
+ end
226
+
227
+ it 'fails with missing file or url' do
228
+ begin
229
+ ine = Xhash::OCR.identification
230
+ rescue => exception
231
+ expect(exception).to be_a(Xhash::MissingRequiredFieldError)
232
+ end
233
+ end
234
+
235
+ it 'fails with invalid INE document' do
236
+ stub_request(:post, 'https://xhash.dev/api/ocr').to_return(
237
+ body: JSON.dump({ result: false, payload: nil }), status: 200
238
+ )
239
+
240
+ begin
241
+ ine =
242
+ Xhash::OCR.generic(
243
+ document_url:
244
+ 'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/7cd6994d9ad52e8943be1ae00bac60c461430cdf2af6159afa4b9be749706472.png'
245
+ )
246
+ rescue => exception
247
+ expect(exception).to be_a(Xhash::InvalidFieldError)
248
+ end
249
+ end
250
+ end
251
+
252
+ describe '.proof_of_address' do
253
+ it 'successfully serialize proof of address to document' do
254
+ stub_request(:post, 'https://xhash.dev/api/ocr/proof-of-address')
255
+ .to_return(
256
+ body:
257
+ JSON.dump(
258
+ {
259
+ payload: {
260
+ full_name: 'Prof Francesco Reichert',
261
+ neighborhood: 'Parkerchester',
262
+ province: 'Port Rosemarieview,VT',
263
+ type: 'TELMEX'
264
+ }
265
+ }
266
+ ),
267
+ status: 200
268
+ )
269
+
270
+ proof_of_address =
271
+ Xhash::OCR.proof_of_address(
272
+ document_url:
273
+ 'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/c7d40899ab9ed7aa689837e39b64a6eb07117353f88ce3f8b9d1ca73bea3d80e.png'
274
+ )
275
+
276
+ expect(proof_of_address).to be_a(Xhash::ProofOfAddress)
277
+ expect(proof_of_address.full_name).to eq('Prof Francesco Reichert')
278
+ expect(proof_of_address.neighborhood).to eq('Parkerchester')
279
+ expect(proof_of_address.province).to eq('Port Rosemarieview,VT')
280
+ expect(proof_of_address.type).to eq('TELMEX')
281
+ end
282
+
283
+ it 'fails with missing file or url' do
284
+ begin
285
+ proof_of_address = Xhash::OCR.proof_of_address
286
+ rescue => exception
287
+ expect(exception).to be_a(Xhash::MissingRequiredFieldError)
288
+ end
289
+ end
290
+
291
+ it 'fails with invalid proof of address document' do
292
+ stub_request(:post, 'https://xhash.dev/api/ocr/proof-of-address')
293
+ .to_return(
294
+ body: JSON.dump({ result: false, payload: nil }), status: 200
295
+ )
296
+
297
+ begin
298
+ ine =
299
+ Xhash::OCR.proof_of_address(
300
+ document_url:
301
+ 'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/7cd6994d9ad52e8943be1ae00bac60c461430cdf2af6159afa4b9be749706472.png'
302
+ )
303
+ rescue => exception
304
+ expect(exception).to be_a(Xhash::InvalidFieldError)
305
+ end
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
325
+ end
326
+
327
+ describe '.ine_reverse' do
328
+ it 'successfully serialize INE (reverse) to document' do
329
+ stub_request(:post, 'https://xhash.dev/api/ocr/ine-reverse').to_return(
330
+ body:
331
+ JSON.dump(
332
+ {
333
+ is_consistentent: false,
334
+ payload: {
335
+ lines: [
336
+ 'IDMEX1836577170<<0747116375842',
337
+ '8007057M1812315MEX<02<<12345<7',
338
+ 'GOMEZ<VELAZzQUEZ<<MARGARITA<',
339
+ ''
340
+ ],
341
+ cic: '183657717',
342
+ cic_digit_check: '0',
343
+ is_cic_digit_check_consistent: false,
344
+ section_and_consecutive: '0747116375842',
345
+ date: '800705',
346
+ date_check_digit: '7',
347
+ gender: 'M',
348
+ expiration_date: '181231',
349
+ expiration_date_digit: '5',
350
+ nationality: 'MEX',
351
+ emission_and_fuar: '02-12345',
352
+ name: 'MARGARITA ',
353
+ mothers_last_name: 'VELAZzQUEZ',
354
+ last_name: 'GOMEZ',
355
+ last_names: 'GOMEZ VELAZzQUEZ'
356
+ }
357
+ }
358
+ ),
359
+ status: 200
360
+ )
361
+
362
+ ine_reverse =
363
+ Xhash::OCR.ine_reverse(
364
+ document_url:
365
+ 'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/b3f43a31929437c35b8fb22580119fe389d2e758bad8718387701ee8363caee7.jpg'
366
+ )
367
+
368
+ expect(ine_reverse).to be_a(Xhash::Identification)
369
+ end
370
+
371
+ it 'fails with missing file or url' do
372
+ begin
373
+ ine_reverse = Xhash::OCR.ine_reverse
374
+ rescue => exception
375
+ expect(exception).to be_a(Xhash::MissingRequiredFieldError)
376
+ end
377
+ end
378
+
379
+ it 'fails with invalid INE reverse document' do
380
+ stub_request(:post, 'https://xhash.dev/api/ocr/ine-reverse').to_return(
381
+ body: JSON.dump({ result: false, payload: nil }), status: 200
382
+ )
383
+
384
+ begin
385
+ ine =
386
+ Xhash::OCR.ine_reverse(
387
+ document_url:
388
+ 'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/7cd6994d9ad52e8943be1ae00bac60c461430cdf2af6159afa4b9be749706472.png'
389
+ )
390
+ rescue => exception
391
+ expect(exception).to be_a(Xhash::InvalidFieldError)
392
+ end
393
+ end
394
+ end
395
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Xhash::SAT do
4
+ describe '.get_rfc' do
5
+ it 'successfully gets rfc by user data' do
6
+ stub_request(:post, 'https://xhash.dev/api/sat/get-rfc').to_return(
7
+ body:
8
+ JSON.dump(
9
+ {
10
+ name: 'Bernardo',
11
+ last_name: 'Suarez',
12
+ mothers_last_name: 'sepulveda',
13
+ birth_date: '1994-03-19',
14
+ rfc: 'SUSB940319BA5'
15
+ }
16
+ ),
17
+ status: 200
18
+ )
19
+
20
+ rfc =
21
+ Xhash::SAT.get_rfc(
22
+ name: 'Bernardo',
23
+ last_name: 'Suarez',
24
+ mothers_last_name: 'sepulveda',
25
+ birth_date: '1994-03-19'
26
+ )
27
+
28
+ expect(rfc).to be_a(Xhash::RFC)
29
+ expect(rfc.name).to eq('Bernardo')
30
+ expect(rfc.last_name).to eq('Suarez')
31
+ expect(rfc.mothers_last_name).to eq('sepulveda')
32
+ expect(rfc.birth_date).to eq('1994-03-19')
33
+ expect(rfc.rfc).to eq('SUSB940319BA5')
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Xhash do
4
+ describe '.config' do
5
+ it 'sets the api key initializer style' do
6
+ Xhash.config { |c| c.api_key = 'abc' }
7
+
8
+ expect(Xhash.api_key).to eq('abc')
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ $:.push File.expand_path("lib", __dir__)
2
+
3
+ # Maintain your gem's version:
4
+ require "xhash/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "xhash_client"
9
+ spec.version = Xhash::VERSION
10
+ spec.date = '2019-10-10'
11
+ spec.description = "Ruby Bindings for Xhash API"
12
+ spec.summary = "Ruby library built for Xhash API"
13
+ spec.files = `git ls-files`.split($/)
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ spec.authors = ["Yellowme"]
17
+ spec.email = 'hola@yellowme.mx'
18
+ spec.homepage = 'https://rubygems.org/gems/xhash-ruby'
19
+ spec.license = 'MIT'
20
+
21
+ spec.add_dependency 'httparty', "~> 0.16.0"
22
+ spec.add_dependency "json", "~> 2.0"
23
+
24
+ spec.add_development_dependency "rspec", "~> 3.8"
25
+ spec.add_development_dependency "webmock", "~> 3.7"
26
+ spec.add_development_dependency "simplecov", "~> 0.17"
27
+ end