xhash_client 0.3.0 → 0.3.1

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: d7744b9f0b562d4f040b9bc1dd81c9410005c1ec9d8390cd4325c1befe6effcd
4
- data.tar.gz: b2a5b8a32776005f55b6d8f3fade17713994f978a4c666f8c4c093a7faf377d5
3
+ metadata.gz: e41e823bbfa41b059071bc5a93fbb98502d941bfa147b96cf5c3495b114bc847
4
+ data.tar.gz: 1193d96715a223e5628c9b8677e5bfebd08208a9094658d34b60368e61cdc716
5
5
  SHA512:
6
- metadata.gz: cfa44d85264d7d0a57444efa14171c9fc6ab7dcd683dfd63203623d6cd9d46c5c70c1a1dcf646bbc67e6f06a773167d0a45bfe822637e28ff9935804957c92eb
7
- data.tar.gz: 7cf8944d01ae81a9d95231ccad0ea53bbe75402a99c3ef8831e0bbe6c2f25880ff2cfb624818f439fb67449cd41890f1c1052adbfd57ff283f3c98125bf21353
6
+ metadata.gz: 2695f2a228913f1602a7ffa4b18176e23b1b15a61cece17c001e5d5ef1270cbd9681adb487f97f0ae7ca640316964aaeeb99020c8ce0b2674120fcef497d694a
7
+ data.tar.gz: be7111ccbf7ff8dba07d3881c18d31c1e0e7b25992ceec868073e40c09aa3966f811f8cce663f095bfee4b41fa6a46eb23e398acb7bd8da1ace27cd6e34af406
data/.gitignore ADDED
@@ -0,0 +1,59 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+
52
+ # Mac
53
+ .DS_Store
54
+
55
+ # Windows
56
+ Thumbs.db
57
+
58
+ # WebStorm
59
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+
4
+ # Declare your gem's dependencies in commons.gemspec.
5
+ # Bundler will treat runtime dependencies like base dependencies, and
6
+ # development dependencies will be added by default to the :development group.
7
+ gemspec
8
+
9
+ # Declare any dependencies that are still in development here instead of in
10
+ # your gemspec. These might include edge Rails or gems from your path or
11
+ # Git. Remember to move these dependencies to your gemspec before releasing
12
+ # your gem to rubygems.org.
data/Gemfile.lock ADDED
@@ -0,0 +1,74 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ xhash (0.3.0)
5
+ activesupport (~> 5.2)
6
+ httparty (~> 0.16.0)
7
+ json (~> 2.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ 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
+ addressable (2.7.0)
18
+ public_suffix (>= 2.0.2, < 5.0)
19
+ concurrent-ruby (1.1.5)
20
+ crack (0.4.3)
21
+ safe_yaml (~> 1.0.0)
22
+ diff-lcs (1.3)
23
+ docile (1.3.2)
24
+ hashdiff (1.0.0)
25
+ httparty (0.16.4)
26
+ mime-types (~> 3.0)
27
+ multi_xml (>= 0.5.2)
28
+ i18n (1.7.0)
29
+ concurrent-ruby (~> 1.0)
30
+ json (2.2.0)
31
+ mime-types (3.3.1)
32
+ mime-types-data (~> 3.2015)
33
+ mime-types-data (3.2019.1009)
34
+ minitest (5.13.0)
35
+ multi_xml (0.6.0)
36
+ public_suffix (4.0.1)
37
+ rspec (3.8.0)
38
+ rspec-core (~> 3.8.0)
39
+ rspec-expectations (~> 3.8.0)
40
+ rspec-mocks (~> 3.8.0)
41
+ rspec-core (3.8.2)
42
+ rspec-support (~> 3.8.0)
43
+ rspec-expectations (3.8.4)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.8.0)
46
+ rspec-mocks (3.8.1)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.8.0)
49
+ rspec-support (3.8.2)
50
+ safe_yaml (1.0.5)
51
+ simplecov (0.17.0)
52
+ docile (~> 1.1)
53
+ json (>= 1.8, < 3)
54
+ simplecov-html (~> 0.10.0)
55
+ simplecov-html (0.10.2)
56
+ thread_safe (0.3.6)
57
+ tzinfo (1.2.6)
58
+ thread_safe (~> 0.1)
59
+ webmock (3.7.2)
60
+ addressable (>= 2.3.6)
61
+ crack (>= 0.3.2)
62
+ hashdiff (>= 0.4.0, < 2.0.0)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ rspec (~> 3.8)
69
+ simplecov (~> 0.17)
70
+ webmock (~> 3.7)
71
+ xhash!
72
+
73
+ BUNDLED WITH
74
+ 1.17.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Yellowme
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # xhash-ruby
2
+ Ruby Bindings for Xhash API
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ # Default directory to look in is `/spec`
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ require 'singleton'
2
+
3
+ module Xhash
4
+ class ApiClient
5
+ include Xhash::JsonApi
6
+
7
+ def self.config
8
+ yield self
9
+ end
10
+
11
+ def self.api_base
12
+ @api_base
13
+ end
14
+
15
+ def self.api_base=(api_base)
16
+ @api_base = api_base
17
+ end
18
+
19
+ def self.api_key
20
+ @api_key
21
+ end
22
+
23
+ def self.api_key=(api_key)
24
+ @api_key = api_key
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,48 @@
1
+ require 'httparty'
2
+
3
+ module Xhash
4
+ module JsonApi
5
+ module ClassMethods
6
+ def default_headers
7
+ {
8
+ 'Content-type' => 'application/json', 'Authorization' => Xhash.api_key
9
+ }
10
+ end
11
+
12
+ def api_get(url:, headers: {})
13
+ custom_headers = headers.merge(default_headers)
14
+ response = HTTParty.get(Xhash.api_base + url, headers: custom_headers)
15
+
16
+ JSON.parse(response.body, symbolize_names: true)
17
+ end
18
+
19
+ def api_post(url:, body: {}, headers: {})
20
+ custom_headers = headers.merge(default_headers)
21
+
22
+ response =
23
+ HTTParty.post(
24
+ Xhash.api_base + url,
25
+ body: body.to_json, headers: custom_headers
26
+ )
27
+
28
+ JSON.parse(response.body, symbolize_names: true)
29
+ end
30
+
31
+ def api_post_multipart(url:, body: {}, headers: {})
32
+ custom_headers = headers.merge(default_headers)
33
+
34
+ response =
35
+ HTTParty.post(
36
+ Xhash.api_base + url,
37
+ multipart: true, body: body, headers: custom_headers
38
+ )
39
+
40
+ response.body
41
+ end
42
+ end
43
+
44
+ def self.included(base)
45
+ base.extend(ClassMethods)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,28 @@
1
+ module Xhash
2
+ class DatabaseLookup < ApiClient
3
+ def self.renapo(curp)
4
+ url = 'database-lookup/renapo'
5
+ body = { curp: curp }
6
+ response = api_post(url: url, body: body)
7
+ payload = response[:payload]
8
+
9
+ if payload.nil?
10
+ raise Xhash::MissingRequiredFieldError.new(
11
+ {
12
+ message: Xhash::ErrorMessage::MISSING_CURP, response: response
13
+ }
14
+ )
15
+ end
16
+
17
+ if payload[:name] == 'CURP INVALIDO'
18
+ raise Xhash::InvalidFieldError.new(
19
+ {
20
+ message: Xhash::ErrorMessage::INVALID_CURP, response: response
21
+ }
22
+ )
23
+ end
24
+
25
+ Xhash::CURP.new(*payload.values_at(*Xhash::CURP.members))
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ module Xhash
2
+ module DocumentType
3
+ module ID
4
+ INE_FRONT = 1
5
+ PASSPORT = 2
6
+ INE_REVERSE = 7
7
+ MILITARY_ID = 6
8
+ end
9
+ module ProofOfAddress
10
+ CFE = 3
11
+ AXTEL = 4
12
+ TELMEX = 5
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Xhash
2
+ class Error < StandardError
3
+ attr_reader :message, :response
4
+
5
+ def initialize(options = {})
6
+ @message = options[:message]
7
+ @response = options[:response]
8
+ super
9
+ end
10
+ end
11
+
12
+ class MissingRequiredFieldError < Error; end
13
+
14
+ class InvalidFieldError < Error; end
15
+ end
@@ -0,0 +1,8 @@
1
+ module Xhash
2
+ module ErrorMessage
3
+ INVALID_CURP = 'The selected CURP is invalid'
4
+ MISSING_CURP = 'The selected CURP is required'
5
+ INVALID_FILE = 'The selected document is invalid'
6
+ MISSING_FILE = 'The selected document is required'
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ module Xhash
2
+ module Formatters
3
+ def self.invalid_field_message_to_s(hash)
4
+ message = ''
5
+ hash.each { |key, value| message += value[0] + ' ' }
6
+ message.strip
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,63 @@
1
+ module Xhash
2
+ class General < ApiClient
3
+ def self.store_data(*user_body)
4
+ url = 'store-data'
5
+ body = Hash[*user_body]
6
+ response = api_post(url: url, body: body)
7
+
8
+ unless response[:id]
9
+ raise Xhash::MissingRequiredFieldError.new(
10
+ {
11
+ message:
12
+ Xhash::Formatters.invalid_field_message_to_s(response),
13
+ response: response
14
+ }
15
+ )
16
+ end
17
+
18
+ Xhash::Customer.new(*response.values_at(*Xhash::Customer.members))
19
+ end
20
+
21
+ def self.get_customer(customer_id:)
22
+ url = "get-customer/#{customer_id}"
23
+ response = api_get(url: url)
24
+ payload = response[:payload]
25
+
26
+ if payload.nil?
27
+ raise Xhash::MissingRequiredFieldError.new(
28
+ {
29
+ message:
30
+ Xhash::Formatters.invalid_field_message_to_s(response),
31
+ response: response
32
+ }
33
+ )
34
+ end
35
+
36
+ Xhash::Customer.new(*payload.values_at(*Xhash::Customer.members))
37
+ end
38
+
39
+ def self.store_file(customer_id:, document_type:, document:)
40
+ url = 'store-file'
41
+ headers = { 'boundary' => '---011000010111000001101001' }
42
+ body = {
43
+ 'customer_id' => customer_id,
44
+ 'document_type' => document_type,
45
+ 'document' => document
46
+ }
47
+
48
+ response = api_post_multipart(url: url, body: body, headers: headers)
49
+
50
+ unless response == 'Image stored'
51
+ error = JSON.parse(response, symbolize_names: true)
52
+ raise Xhash::MissingRequiredFieldError.new(
53
+ {
54
+ message: Xhash::Formatters.invalid_field_message_to_s(error),
55
+ response: error
56
+ }
57
+ )
58
+ end
59
+
60
+ response
61
+ end
62
+ end
63
+ end
data/lib/xhash/ocr.rb ADDED
@@ -0,0 +1,124 @@
1
+ module Xhash
2
+ class OCR < ApiClient
3
+ IDENTIFICATION_TYPES = ['INE', 'CARTILLA MILITAR', 'PASAPORTE']
4
+
5
+ def self.generic(document_url: nil, document_file: nil)
6
+ url = 'ocr'
7
+
8
+ if document_url.nil? and document_file.nil?
9
+ raise Xhash::MissingRequiredFieldError.new(
10
+ { message: Xhash::ErrorMessage::MISSING_FILE }
11
+ )
12
+ end
13
+
14
+ payload =
15
+ request_by_file_or_url(
16
+ url: url, document_url: document_url, document_file: document_file
17
+ )
18
+
19
+ is_identification = IDENTIFICATION_TYPES.include? payload[:type]
20
+
21
+ document =
22
+ if is_identification
23
+ Xhash::Identification.new(
24
+ *payload.values_at(*Xhash::Identification.members)
25
+ )
26
+ else
27
+ Xhash::ProofOfAddress.new(
28
+ *payload.values_at(*Xhash::ProofOfAddress.members)
29
+ )
30
+ end
31
+
32
+ document
33
+ end
34
+
35
+ def self.identification(document_url: nil, document_file: nil)
36
+ url = 'ocr/identification'
37
+
38
+ if document_url.nil? and document_file.nil?
39
+ raise Xhash::MissingRequiredFieldError.new(
40
+ { message: Xhash::ErrorMessage::MISSING_FILE }
41
+ )
42
+ end
43
+
44
+ payload =
45
+ request_by_file_or_url(
46
+ url: url, document_url: document_url, document_file: document_file
47
+ )
48
+
49
+ Xhash::Identification.new(
50
+ *payload.values_at(*Xhash::Identification.members)
51
+ )
52
+ end
53
+
54
+ def self.proof_of_address(document_url: nil, document_file: nil)
55
+ url = 'ocr/proof-of-address'
56
+
57
+ if document_url.nil? and document_file.nil?
58
+ raise Xhash::MissingRequiredFieldError.new(
59
+ { message: Xhash::ErrorMessage::MISSING_FILE }
60
+ )
61
+ end
62
+
63
+ payload =
64
+ request_by_file_or_url(
65
+ url: url, document_url: document_url, document_file: document_file
66
+ )
67
+
68
+ Xhash::ProofOfAddress.new(
69
+ *payload.values_at(*Xhash::ProofOfAddress.members)
70
+ )
71
+ end
72
+
73
+ def self.ine_reverse(document_url: nil, document_file: nil)
74
+ url = 'ocr/ine-reverse'
75
+
76
+ if document_url.nil? and document_file.nil?
77
+ raise Xhash::MissingRequiredFieldError.new(
78
+ { message: Xhash::ErrorMessage::MISSING_FILE }
79
+ )
80
+ end
81
+
82
+ payload =
83
+ request_by_file_or_url(
84
+ url: url, document_url: document_url, document_file: document_file
85
+ )
86
+
87
+ Xhash::Identification.new(
88
+ *payload.values_at(*Xhash::Identification.members)
89
+ )
90
+ end
91
+
92
+ private
93
+
94
+ def self.request_by_file_or_url(
95
+ url: nil, document_url: nil, document_file: nil
96
+ )
97
+ body = {
98
+ 'document_url' => document_url, 'document_file' => document_file
99
+ }
100
+
101
+ response =
102
+ if document_file.nil?
103
+ api_post(
104
+ url: url,
105
+ body: body,
106
+ headers: { 'boundary' => '---011000010111000001101001' }
107
+ )
108
+ else
109
+ data = api_post_multipart(url: url, body: body)
110
+ JSON.parse(data, symbolize_names: true)
111
+ end
112
+
113
+ payload = response[:payload]
114
+
115
+ if payload.nil?
116
+ raise Xhash::InvalidFieldError.new(
117
+ { message: Xhash::ErrorMessage::INVALID_FILE }
118
+ )
119
+ end
120
+
121
+ payload
122
+ end
123
+ end
124
+ end
data/lib/xhash/sat.rb ADDED
@@ -0,0 +1,18 @@
1
+ module Xhash
2
+ class SAT < ApiClient
3
+ def self.get_rfc(
4
+ name: nil, last_name: nil, mothers_last_name: nil, birth_date: nil
5
+ )
6
+ url = 'sat/get-rfc'
7
+ body = {
8
+ name: name,
9
+ last_name: last_name,
10
+ mothers_last_name: mothers_last_name,
11
+ birth_date: birth_date
12
+ }
13
+ response = api_post(url: url, body: body)
14
+ raise Xhash::MissingRequiredFieldError.new(response) unless response[:rfc]
15
+ Xhash::RFC.new(*response.values_at(*Xhash::RFC.members))
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module Xhash
2
+ CURP =
3
+ Struct.new(
4
+ :curp,
5
+ :name,
6
+ :last_name,
7
+ :mothers_last_name,
8
+ :gender,
9
+ :province_of_birth,
10
+ :day_of_birth,
11
+ :updated_at,
12
+ :created_at,
13
+ :id
14
+ )
15
+ end
@@ -0,0 +1,49 @@
1
+ module Xhash
2
+ Customer =
3
+ Struct.new(
4
+ :id,
5
+ :name,
6
+ :last_name,
7
+ :mothers_last_name,
8
+ :gender,
9
+ :birth_date,
10
+ :birth_city,
11
+ :birth_country,
12
+ :curp,
13
+ :renapo_match,
14
+ :rfc,
15
+ :rfc_match,
16
+ :rfc_is_cancelled,
17
+ :zip_code,
18
+ :neighborhood,
19
+ :province,
20
+ :city,
21
+ :country,
22
+ :address,
23
+ :activity,
24
+ :electoral_key,
25
+ :clabe,
26
+ :ext_address,
27
+ :email,
28
+ :phone_number,
29
+ :in_black_list,
30
+ :black_list_name,
31
+ :liveness_video,
32
+ :liveness_check,
33
+ :document_id,
34
+ :client_id,
35
+ :external_customer_id,
36
+ :update_key,
37
+ :device_fingerprint_id,
38
+ :token_email,
39
+ :email_verified_at,
40
+ :token_sm,
41
+ :sms_verified_at,
42
+ :deleted_at,
43
+ :created_at,
44
+ :updated_at,
45
+ :ip_uniqueness,
46
+ :fingerprint_uniqueness,
47
+ :documents
48
+ )
49
+ end
@@ -0,0 +1,30 @@
1
+ module Xhash
2
+ Identification =
3
+ Struct.new(
4
+ :lines,
5
+ :cic,
6
+ :cic_digit_check,
7
+ :is_cic_digit_check_consistent,
8
+ :section_and_consecutive,
9
+ :date,
10
+ :date_check_digit,
11
+ :expiration_date,
12
+ :expiration_date_digit,
13
+ :nationality,
14
+ :emission_and_fuar,
15
+ :name,
16
+ :mothers_last_name,
17
+ :last_name,
18
+ :last_names,
19
+ :birth_date,
20
+ :gender,
21
+ :elector_key,
22
+ :curp,
23
+ :street,
24
+ :neighborhood,
25
+ :zip_code,
26
+ :city,
27
+ :province,
28
+ :type
29
+ )
30
+ end
@@ -0,0 +1,15 @@
1
+ module Xhash
2
+ ProofOfAddress =
3
+ Struct.new(
4
+ :full_name,
5
+ :full_address,
6
+ :street,
7
+ :neighborhood,
8
+ :zip_code,
9
+ :city,
10
+ :province,
11
+ :type,
12
+ :date,
13
+ :exception
14
+ )
15
+ end
@@ -0,0 +1,3 @@
1
+ module Xhash
2
+ RFC = Struct.new(:name, :last_name, :mothers_last_name, :birth_date, :rfc)
3
+ end
@@ -0,0 +1,3 @@
1
+ module Xhash
2
+ VERSION = '0.3.1'
3
+ end
Binary file
Binary file
Binary file