idnow 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +43 -0
- data/.travis.yml +4 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/Makefile +2 -0
- data/README.md +142 -0
- data/circle.yml +7 -0
- data/docs/IDnow_API.pdf +0 -0
- data/examples/idnow_automated_testing.rb +35 -0
- data/examples/idnow_download_identification.rb +16 -0
- data/examples/idnow_get_identification.rb +16 -0
- data/examples/idnow_upload_download_default_document.rb +33 -0
- data/idnow-client.gemspec +30 -0
- data/lib/idnow.rb +68 -0
- data/lib/idnow/API/authentication.rb +13 -0
- data/lib/idnow/API/automated_testing.rb +19 -0
- data/lib/idnow/API/document_definitions.rb +29 -0
- data/lib/idnow/API/download_documents.rb +13 -0
- data/lib/idnow/API/request_identifications.rb +12 -0
- data/lib/idnow/API/retrieve_identifications.rb +36 -0
- data/lib/idnow/API/upload_documents.rb +23 -0
- data/lib/idnow/client.rb +60 -0
- data/lib/idnow/configuration.rb +25 -0
- data/lib/idnow/exception.rb +25 -0
- data/lib/idnow/get_request.rb +10 -0
- data/lib/idnow/helpers.rb +9 -0
- data/lib/idnow/http_client.rb +27 -0
- data/lib/idnow/json_response.rb +11 -0
- data/lib/idnow/models/contact_data.rb +12 -0
- data/lib/idnow/models/document_definition.rb +15 -0
- data/lib/idnow/models/identification.rb +25 -0
- data/lib/idnow/models/identification_data.rb +60 -0
- data/lib/idnow/models/identification_document.rb +34 -0
- data/lib/idnow/models/identification_process.rb +29 -0
- data/lib/idnow/models/identification_request.rb +16 -0
- data/lib/idnow/models/login.rb +9 -0
- data/lib/idnow/models/login_data.rb +13 -0
- data/lib/idnow/models/user_data.rb +39 -0
- data/lib/idnow/modules/jsonable.rb +28 -0
- data/lib/idnow/post_binary_request.rb +11 -0
- data/lib/idnow/post_json_request.rb +12 -0
- data/lib/idnow/raw_response.rb +31 -0
- data/lib/idnow/sftp_client.rb +24 -0
- metadata +187 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
module Idnow
|
2
|
+
class IdentificationDocument
|
3
|
+
include Idnow::Jsonable
|
4
|
+
|
5
|
+
attr_accessor :country, :number, :issued_by, :date_issued, :type, :valid_until
|
6
|
+
def initialize(data)
|
7
|
+
@country = dig_value('country', data)
|
8
|
+
@number = dig_value('number', data)
|
9
|
+
@issued_by = dig_value('issuedby', data)
|
10
|
+
@date_issued = dig_value('dateissued', data)
|
11
|
+
@type = dig_value('type', data)
|
12
|
+
@valid_until = dig_value('validuntil', data)
|
13
|
+
end
|
14
|
+
|
15
|
+
def date_issued
|
16
|
+
Date.parse(@date_issued) if @date_issued
|
17
|
+
end
|
18
|
+
|
19
|
+
def valid_until
|
20
|
+
Date.parse(@valid_until) if @valid_until
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def dig_value(*keys, data)
|
26
|
+
# TODO: use ruby 2.3 and dig
|
27
|
+
result = data
|
28
|
+
keys.each do |key|
|
29
|
+
result = result.fetch(key, {})
|
30
|
+
end
|
31
|
+
result['value']
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Idnow
|
2
|
+
class IdentificationProcess
|
3
|
+
include Idnow::Jsonable
|
4
|
+
|
5
|
+
SUCCESSFUL_RESPONSES = %w(SUCCESS SUCCESS_DATA_CHANGED).freeze
|
6
|
+
attr_accessor :result, :reason, :company_id, :filename, :agentname, :identification_time, :id, :href, :type, :transaction_number
|
7
|
+
|
8
|
+
def initialize(data)
|
9
|
+
@result = data['result']
|
10
|
+
@reason = data['reason']
|
11
|
+
@company_id = data['companyid']
|
12
|
+
@filename = data['filename']
|
13
|
+
@agentname = data['agentname']
|
14
|
+
@identification_time = data['identificationtime']
|
15
|
+
@id = data['id']
|
16
|
+
@href = data['href']
|
17
|
+
@type = data['type']
|
18
|
+
@transaction_number = data['transactionnumber']
|
19
|
+
end
|
20
|
+
|
21
|
+
def successful?
|
22
|
+
SUCCESSFUL_RESPONSES.include?(result)
|
23
|
+
end
|
24
|
+
|
25
|
+
def review_pending?
|
26
|
+
result == 'REVIEW_PENDING'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Idnow
|
2
|
+
class IdentificationRequest
|
3
|
+
attr_accessor :id, :transaction_number
|
4
|
+
|
5
|
+
def initialize(data, transaction_number, target_host, company_id)
|
6
|
+
@id = data['id']
|
7
|
+
@transaction_number = transaction_number
|
8
|
+
@target_host = target_host
|
9
|
+
@company_id = company_id
|
10
|
+
end
|
11
|
+
|
12
|
+
def redirect_url
|
13
|
+
"#{@target_host}/#{@company_id}/identifications/#{@transaction_number}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Idnow
|
2
|
+
class UserData
|
3
|
+
include Idnow::Jsonable
|
4
|
+
|
5
|
+
attr_accessor :birthday, :birthname, :birthplace, :city, :country, :firstname, :gender, :lastname, :nationality, :street, :streetnumber,
|
6
|
+
:title, :zipcode
|
7
|
+
|
8
|
+
def initialize(data)
|
9
|
+
@birthday = dig_value('birthday', data)
|
10
|
+
@birthname = dig_value('birthname', data)
|
11
|
+
@birthplace = dig_value('birthplace', data)
|
12
|
+
@city = dig_value('address', 'city', data)
|
13
|
+
@country = dig_value('address', 'country', data)
|
14
|
+
@firstname = dig_value('firstname', data)
|
15
|
+
@gender = dig_value('gender', data)
|
16
|
+
@lastname = dig_value('lastname', data)
|
17
|
+
@nationality = dig_value('nationality', data)
|
18
|
+
@street = dig_value('address', 'street', data)
|
19
|
+
@streetnumber = dig_value('address', 'streetnumber', data)
|
20
|
+
@title = dig_value('title', data)
|
21
|
+
@zipcode = dig_value('address', 'zipcode', data)
|
22
|
+
end
|
23
|
+
|
24
|
+
def address
|
25
|
+
"#{street} #{streetnumber}, #{zipcode} #{city}, #{country}"
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def dig_value(*keys, data)
|
31
|
+
# TODO: use ruby 2.3 and dig
|
32
|
+
result = data
|
33
|
+
keys.each do |key|
|
34
|
+
result = result.fetch(key, {})
|
35
|
+
end
|
36
|
+
result['value']
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Idnow
|
2
|
+
module Jsonable
|
3
|
+
def to_h
|
4
|
+
instance_variables.each_with_object({}) do |var, result_hash|
|
5
|
+
key = var.to_s.delete('@')
|
6
|
+
value = if instance_variable_get(var).respond_to?(:to_h)
|
7
|
+
instance_variable_get(var).to_h
|
8
|
+
else
|
9
|
+
instance_variable_get(var).to_s
|
10
|
+
end
|
11
|
+
result_hash[key] = value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_json
|
16
|
+
keys_without_underscores(to_h).to_json
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def keys_without_underscores(obj)
|
22
|
+
return obj unless obj.is_a?(Hash)
|
23
|
+
obj.each_with_object({}) do |(k, v), result|
|
24
|
+
result[k.to_s.delete('_')] = keys_without_underscores(v)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Idnow
|
2
|
+
class RawResponse
|
3
|
+
attr_reader :raw
|
4
|
+
|
5
|
+
def initialize(raw_response)
|
6
|
+
@raw = raw_response.nil? ? raw_response.to_s : raw_response
|
7
|
+
end
|
8
|
+
|
9
|
+
# IDNow API always returns JSON-formatted errors,
|
10
|
+
# even if a successful response is raw text
|
11
|
+
def errors
|
12
|
+
if valid_json?(@raw)
|
13
|
+
json_data = JSON.parse(@raw)
|
14
|
+
json_data['errors'] if json_data.class == Hash
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def errors?
|
19
|
+
!errors.nil?
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def valid_json?(json)
|
25
|
+
JSON.parse(json)
|
26
|
+
return true
|
27
|
+
rescue JSON::ParserError
|
28
|
+
return false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'net/sftp'
|
2
|
+
|
3
|
+
module Idnow
|
4
|
+
class SftpClient
|
5
|
+
def initialize(host:, username:, password:)
|
6
|
+
@host = URI.parse(host).host
|
7
|
+
@username = username
|
8
|
+
@password = password
|
9
|
+
end
|
10
|
+
|
11
|
+
def download(file_name)
|
12
|
+
data = nil
|
13
|
+
Net::SFTP.start(@host, @username, password: @password) do |sftp|
|
14
|
+
fail Idnow::Exception, "Invalid path. No identification file found under #{file_name}" if sftp.dir['.', file_name].empty?
|
15
|
+
begin
|
16
|
+
data = sftp.download!(file_name)
|
17
|
+
rescue Net::SFTP::Exception => e
|
18
|
+
raise Idnow::ConnectionException, e
|
19
|
+
end
|
20
|
+
end
|
21
|
+
data
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: idnow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joan Martinez, Tobias Bielohlawek
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: net-sftp
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: webmock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.22'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.22'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.36.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.36.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: factory_girl
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.5'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.5'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: shoulda-matchers
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.1'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.1'
|
111
|
+
description: Library to consume the IDnow API in Ruby, http://www.idnow.eu/developers
|
112
|
+
email:
|
113
|
+
- joan.martinez.ripoll@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".rubocop.yml"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- Makefile
|
125
|
+
- README.md
|
126
|
+
- circle.yml
|
127
|
+
- docs/IDnow_API.pdf
|
128
|
+
- examples/idnow_automated_testing.rb
|
129
|
+
- examples/idnow_download_identification.rb
|
130
|
+
- examples/idnow_get_identification.rb
|
131
|
+
- examples/idnow_upload_download_default_document.rb
|
132
|
+
- idnow-client.gemspec
|
133
|
+
- lib/idnow.rb
|
134
|
+
- lib/idnow/API/authentication.rb
|
135
|
+
- lib/idnow/API/automated_testing.rb
|
136
|
+
- lib/idnow/API/document_definitions.rb
|
137
|
+
- lib/idnow/API/download_documents.rb
|
138
|
+
- lib/idnow/API/request_identifications.rb
|
139
|
+
- lib/idnow/API/retrieve_identifications.rb
|
140
|
+
- lib/idnow/API/upload_documents.rb
|
141
|
+
- lib/idnow/client.rb
|
142
|
+
- lib/idnow/configuration.rb
|
143
|
+
- lib/idnow/exception.rb
|
144
|
+
- lib/idnow/get_request.rb
|
145
|
+
- lib/idnow/helpers.rb
|
146
|
+
- lib/idnow/http_client.rb
|
147
|
+
- lib/idnow/json_response.rb
|
148
|
+
- lib/idnow/models/contact_data.rb
|
149
|
+
- lib/idnow/models/document_definition.rb
|
150
|
+
- lib/idnow/models/identification.rb
|
151
|
+
- lib/idnow/models/identification_data.rb
|
152
|
+
- lib/idnow/models/identification_document.rb
|
153
|
+
- lib/idnow/models/identification_process.rb
|
154
|
+
- lib/idnow/models/identification_request.rb
|
155
|
+
- lib/idnow/models/login.rb
|
156
|
+
- lib/idnow/models/login_data.rb
|
157
|
+
- lib/idnow/models/user_data.rb
|
158
|
+
- lib/idnow/modules/jsonable.rb
|
159
|
+
- lib/idnow/post_binary_request.rb
|
160
|
+
- lib/idnow/post_json_request.rb
|
161
|
+
- lib/idnow/raw_response.rb
|
162
|
+
- lib/idnow/sftp_client.rb
|
163
|
+
homepage: https://github.com/solarisBank/idnow-client
|
164
|
+
licenses:
|
165
|
+
- MIT
|
166
|
+
metadata: {}
|
167
|
+
post_install_message:
|
168
|
+
rdoc_options: []
|
169
|
+
require_paths:
|
170
|
+
- lib
|
171
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
requirements: []
|
182
|
+
rubyforge_project:
|
183
|
+
rubygems_version: 2.4.5.1
|
184
|
+
signing_key:
|
185
|
+
specification_version: 4
|
186
|
+
summary: Ruby client for the IDnow API
|
187
|
+
test_files: []
|