idnow 1.3.0 → 2.1.1

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -1
  3. data/.travis.yml +1 -2
  4. data/Dockerfile +13 -0
  5. data/Gemfile +2 -0
  6. data/README.md +42 -12
  7. data/circle.yml +1 -1
  8. data/examples/idnow_automated_testing.rb +3 -1
  9. data/examples/idnow_download_identification.rb +3 -1
  10. data/examples/idnow_get_identification.rb +3 -1
  11. data/examples/idnow_upload_download_default_document.rb +3 -1
  12. data/idnow-client.gemspec +10 -8
  13. data/lib/idnow.rb +20 -8
  14. data/lib/idnow/API/authentication.rb +2 -0
  15. data/lib/idnow/API/automated_testing.rb +2 -1
  16. data/lib/idnow/API/document_definitions.rb +6 -4
  17. data/lib/idnow/API/download_documents.rb +3 -1
  18. data/lib/idnow/API/request_identifications.rb +2 -0
  19. data/lib/idnow/API/retrieve_identifications.rb +6 -4
  20. data/lib/idnow/API/upload_documents.rb +3 -1
  21. data/lib/idnow/client.rb +13 -9
  22. data/lib/idnow/configuration.rb +3 -2
  23. data/lib/idnow/exception.rb +2 -0
  24. data/lib/idnow/get_request.rb +2 -0
  25. data/lib/idnow/helpers.rb +2 -0
  26. data/lib/idnow/http_client.rb +3 -1
  27. data/lib/idnow/json_response.rb +3 -1
  28. data/lib/idnow/models/contact_data.rb +2 -0
  29. data/lib/idnow/models/document_definition.rb +2 -0
  30. data/lib/idnow/models/identification.rb +2 -0
  31. data/lib/idnow/models/identification_data.rb +15 -11
  32. data/lib/idnow/models/identification_document.rb +11 -18
  33. data/lib/idnow/models/identification_process.rb +3 -1
  34. data/lib/idnow/models/identification_request.rb +2 -0
  35. data/lib/idnow/models/login.rb +2 -0
  36. data/lib/idnow/models/login_data.rb +2 -0
  37. data/lib/idnow/models/user_data.rb +2 -0
  38. data/lib/idnow/modules/jsonable.rb +2 -0
  39. data/lib/idnow/post_binary_request.rb +2 -0
  40. data/lib/idnow/post_json_request.rb +2 -0
  41. data/lib/idnow/raw_response.rb +4 -2
  42. data/lib/idnow/sftp_client.rb +8 -3
  43. metadata +25 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7636a8ddecbc36e100f54413150590a4ace73ea
4
- data.tar.gz: 7457d857840d07698651ad9353a72dd8e08a9cfc
3
+ metadata.gz: 71c54deac5050e48ce75bb19ff81ab76ca827055
4
+ data.tar.gz: 5e47156913a5f7127277cb5c6ef5a1e343ecad15
5
5
  SHA512:
6
- metadata.gz: cc4b30834b1f450d9c9e56e43c3fabb37f6029760f25bd0178c06dd48e7bf5358b6dbee6b4243eb1d863828adfb8724dd334bf5ebcb9b64506e28edd1d2ed09a
7
- data.tar.gz: ecded6e3fc954b139141d84c88aa6fdf64aa95773aefef95cfa30b720bab12b97313d451ca503e4b1532c025577ad3f92d052e421c6f415b0b4d6fb1a1c612a1
6
+ metadata.gz: 303055651e8474d3f2d42f76c331f11ba45c8ca85eff341fa9b3b2fb05c5dbe31e581b854bf3fb84f9e481eea682420f82b024cc317251dc6c194703a986f4ed
7
+ data.tar.gz: 6de474e0a88f7e24adf051327bbd14438ae93352a0304aa3660af81f79cdddb487d8d5eec051b418fdb18bd3358af543fe925d0cc4c6668b508b099681778fd8
@@ -1,6 +1,6 @@
1
1
  AllCops:
2
2
  DisplayCopNames: true
3
- TargetRubyVersion: 2.2
3
+ TargetRubyVersion: 2.3
4
4
 
5
5
  # This configuration was generated by
6
6
  # `rubocop --auto-gen-config`
@@ -19,6 +19,9 @@ Metrics/LineLength:
19
19
  Metrics/MethodLength:
20
20
  Max: 31
21
21
 
22
+ Metrics/BlockLength:
23
+ Max: 190
24
+
22
25
  Metrics/AbcSize:
23
26
  Enabled: false
24
27
 
@@ -1,7 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.3
4
- - 2.3.1
3
+ - 2.3.3
5
4
 
6
5
  script:
7
6
  - make test
@@ -0,0 +1,13 @@
1
+ FROM ruby:2.3-alpine
2
+
3
+ RUN mkdir /gem
4
+ WORKDIR /gem
5
+
6
+ RUN apk update
7
+ RUN apk add git build-base
8
+ RUN gem install bundler
9
+
10
+ COPY Gemfile idnow-client.gemspec /gem/
11
+ RUN bundle install
12
+
13
+ COPY . /gem/
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in idnow.gemspec
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Idnow Client
2
- Library to consume the [IDnow API](http://www.idnow.eu/developers) in Ruby.
3
2
 
3
+ Library to consume the [IDnow API](http://www.idnow.eu/developers) in Ruby.
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,6 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install idnow
20
20
 
21
-
22
21
  ## Configuration
23
22
 
24
23
  The Idnow client takes three settings:
@@ -32,6 +31,7 @@ The Idnow client takes three settings:
32
31
 
33
32
  * **company_id**
34
33
  * **api_key**
34
+ * **custom_environments** (optional)
35
35
 
36
36
  You have the option of using a global singleton client:
37
37
 
@@ -39,6 +39,18 @@ You have the option of using a global singleton client:
39
39
  Idnow.env = :test
40
40
  Idnow.company_id = "mycompany"
41
41
  Idnow.api_key = "1234api_key"
42
+
43
+ # optional
44
+ Idnow.custom_environments = {
45
+ test: {
46
+ host: 'https://gateway.test.idnow.example.com',
47
+ target_host: 'https://go.test.idnow.example.com'
48
+ },
49
+ live: {
50
+ host: 'https://gateway.idnow.example.com',
51
+ target_host: 'https://go.idnow.example.com'
52
+ }
53
+ }
42
54
  ```
43
55
 
44
56
  Or many clients can be initialized with:
@@ -48,11 +60,15 @@ client = Idnow::Client.new(env: @env, company_id: @company_id, api_key: @api_key
48
60
  ```
49
61
 
50
62
  ## API Summary
51
- Please read the official IDnow documentation for details. Some examples can also be found at the examples folder.
52
63
 
53
- ####Identifications
64
+ Please read the official IDnow documentation for details. Some examples can also be found in the examples folder.
65
+
66
+ #### Identifications
67
+
54
68
  ```ruby
55
- # Identification data, all fields are optional. If you want to use a testing robot instead of a real agent for the identification, write the robot name at the first_name, last_name or any custom field.
69
+ # Identification data, all fields are optional.
70
+ # If you want to use a testing robot instead of a real agent for the identification,
71
+ # write the robot name at the first_name, last_name or any custom field.
56
72
  data = Idnow::IdentificationData.new({
57
73
  birthday: '1984-07-20',
58
74
  birthplace: 'Buxtehude',
@@ -86,22 +102,24 @@ Idnow.client.testing_start(transaction_number: transaction_number)
86
102
  # Testing video chat - Only needed for automated robot testing
87
103
  Idnow.client.testing_request_video_chat(transaction_number: transaction_number)
88
104
 
89
- # List successful identifications. When using automated robots, keep in mind that it might take a while until the identification is completed.
105
+ # List successful identifications. When using automated robots,
106
+ # keep in mind that it might take a while until the identification is completed.
90
107
  Idnow.client.login
91
108
  Idnow.client.list_identifications
92
109
 
93
110
  # List identifications by status pending or failed
94
111
  Idnow.client.list_identifications(status: 'pending')
95
112
 
96
- # Get identification. When using automated robots, keep in mind that it might take a while until the identification is completed.
113
+ # Get identification. When using automated robots,
114
+ # keep in mind that it might take a while until the identification is completed.
97
115
  Idnow.client.get_identification(transaction_number: transaction_number)
98
116
 
99
117
  # Download identification files
100
118
  Idnow.client.download_identification(transaction_number: transaction_number)
101
-
102
119
  ```
103
120
 
104
- ####Esigning
121
+ #### Esigning
122
+
105
123
  ```ruby
106
124
  # Create document definition
107
125
  document_identifier = "doc_id"
@@ -132,11 +150,23 @@ Idnow.client.upload_default_document(document_identifier, file_data)
132
150
  Idnow.client.download_default_document(document_identifier)
133
151
  ```
134
152
 
135
-
136
- ## Development
153
+ ## Development & testing
137
154
 
138
155
  RSpec is used for testing.
156
+
157
+ ### Coverage report
158
+
139
159
  To enable code coverage check, set COV environment variable:
140
160
 
141
- ```COV=true bundle exec rspec```
161
+ ```sh
162
+ COV=true make test
163
+ ```
164
+
165
+ ### Testing with docker
142
166
 
167
+ To run the tests through docker, you can use the included `Dockerfile`:
168
+
169
+ ```sh
170
+ docker build . -t idnow-client
171
+ docker run -it idnow-client:latest make test
172
+ ```
data/circle.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  machine:
2
2
  ruby:
3
- version: 2.2.3
3
+ version: 2.3.3
4
4
 
5
5
  test:
6
6
  override:
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'idnow'
2
4
 
3
- fail 'please call with a transaction number' unless ARGV[0]
5
+ raise 'please call with a transaction number' unless ARGV[0]
4
6
 
5
7
  company_id = ENV.fetch('IDNOW_COMPANY_ID')
6
8
  api_key = ENV.fetch('IDNOW_API_KEY')
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'idnow'
2
4
 
3
- fail 'please call with a transaction number' unless ARGV[0]
5
+ raise 'please call with a transaction number' unless ARGV[0]
4
6
 
5
7
  company_id = ENV.fetch('IDNOW_COMPANY_ID')
6
8
  api_key = ENV.fetch('IDNOW_API_KEY')
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'idnow'
2
4
 
3
- fail 'please call with a transaction number' unless ARGV[0]
5
+ raise 'please call with a transaction number' unless ARGV[0]
4
6
 
5
7
  company_id = ENV.fetch('IDNOW_COMPANY_ID')
6
8
  api_key = ENV.fetch('IDNOW_API_KEY')
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'idnow'
2
4
 
3
- fail 'please call with a document identifier (must be unique)' unless ARGV[0]
5
+ raise 'please call with a document identifier (must be unique)' unless ARGV[0]
4
6
 
5
7
  company_id = ENV.fetch('IDNOW_COMPANY_ID')
6
8
  api_key = ENV.fetch('IDNOW_API_KEY')
@@ -1,15 +1,15 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'idnow'
5
- spec.version = '1.3.0'
5
+ spec.version = '2.1.1'
6
6
  spec.authors = ['Joan Martinez, Tobias Bielohlawek']
7
- spec.email = ['joan.martinez.ripoll@gmail.com']
7
+ spec.email = ['joan.martinez@solarisbank.de']
8
8
 
9
9
  spec.summary = 'Ruby client for the IDnow API'
10
10
  spec.description = 'Library to consume the IDnow API in Ruby, http://www.idnow.eu/developers'
11
11
 
12
- fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
12
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
13
13
 
14
14
  spec.homepage = 'https://github.com/solarisBank/idnow-client'
15
15
  spec.license = 'MIT'
@@ -21,10 +21,12 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_runtime_dependency 'net-sftp', '~>2.1'
23
23
 
24
+ spec.required_ruby_version = '~> 2.3'
25
+
26
+ spec.add_development_dependency 'factory_bot', '~> 4.5'
24
27
  spec.add_development_dependency 'rspec', '~> 3.3'
25
- spec.add_development_dependency 'webmock', '~> 1.22'
26
- spec.add_development_dependency 'simplecov', '~> 0.10'
27
- spec.add_development_dependency 'rubocop', '~> 0.36.0'
28
- spec.add_development_dependency 'factory_girl', '~> 4.5'
28
+ spec.add_development_dependency 'rubocop', '~> 0.54.0'
29
29
  spec.add_development_dependency 'shoulda-matchers', '~>3.1'
30
+ spec.add_development_dependency 'simplecov', '~> 0.10'
31
+ spec.add_development_dependency 'webmock', '~> 1.22'
30
32
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'idnow/modules/jsonable'
3
4
  require 'idnow/client'
4
5
 
@@ -24,14 +25,16 @@ require 'idnow/models/login_data'
24
25
  require 'idnow/models/document_definition'
25
26
 
26
27
  module Idnow
27
- module Host # Used to request an identification through the idnow API
28
- TEST_SERVER = 'https://gateway.test.idnow.de'.freeze
29
- LIVE_SERVER = 'https://gateway.idnow.de'.freeze
28
+ # Used to request an identification through the idnow API
29
+ module Host
30
+ TEST_SERVER = 'https://gateway.test.idnow.de'
31
+ LIVE_SERVER = 'https://gateway.idnow.de'
30
32
  end
31
33
 
32
- module TargetHost # Used for redirecting the user to the identification process
33
- TEST_SERVER = 'https://go.test.idnow.de'.freeze
34
- LIVE_SERVER = 'https://go.idnow.de'.freeze
34
+ # Used for redirecting the user to the identification process
35
+ module TargetHost
36
+ TEST_SERVER = 'https://go.test.idnow.de'
37
+ LIVE_SERVER = 'https://go.idnow.de'
35
38
  end
36
39
 
37
40
  ENVIRONMENTS = {
@@ -46,7 +49,7 @@ module Idnow
46
49
  }.freeze
47
50
 
48
51
  def env=(env)
49
- fail ArgumentError, 'Please provide a valid enviroment, :test or :live' unless ENVIRONMENTS.keys.include?(env)
52
+ raise ArgumentError, 'Please provide a valid enviroment, :test or :live' unless ENVIRONMENTS.keys.include?(env)
50
53
  @client = nil
51
54
  @env = env
52
55
  end
@@ -61,9 +64,18 @@ module Idnow
61
64
  @api_key = api_key
62
65
  end
63
66
 
67
+ def custom_environments=(custom_environments)
68
+ @client = nil
69
+ @custom_environments = custom_environments
70
+ end
71
+
72
+ def endpoint(env, host)
73
+ (@custom_environments || {}).dig(env, host) || Idnow::ENVIRONMENTS[env][host]
74
+ end
75
+
64
76
  def client
65
77
  @client ||= Idnow::Client.new(env: @env, company_id: @company_id, api_key: @api_key)
66
78
  end
67
79
 
68
- module_function :env=, :company_id=, :api_key=, :client
80
+ module_function :env=, :company_id=, :api_key=, :custom_environments=, :endpoint, :client
69
81
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  module API
3
5
  module Authentication
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Idnow
3
4
  module API
4
5
  module AutomatedTesting
5
- HOST = 'https://api.test.idnow.de'.freeze
6
+ HOST = 'https://api.test.idnow.de'
6
7
 
7
8
  def testing_start(transaction_number:)
8
9
  path = full_path_for("identifications/#{transaction_number}/start")
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  module API
3
5
  module DocumentDefinitions
4
6
  def create_document_definition(document_data)
5
- fail Idnow::AuthenticationException if @auth_token.nil?
7
+ raise Idnow::AuthenticationException if @auth_token.nil?
6
8
 
7
9
  path = full_path_for('documentdefinitions')
8
10
  request = Idnow::PostJsonRequest.new(path, document_data)
@@ -10,7 +12,7 @@ module Idnow
10
12
  end
11
13
 
12
14
  def list_document_definitions
13
- fail Idnow::AuthenticationException if @auth_token.nil?
15
+ raise Idnow::AuthenticationException if @auth_token.nil?
14
16
 
15
17
  path = full_path_for('documentdefinitions')
16
18
  request = Idnow::GetRequest.new(path)
@@ -21,8 +23,8 @@ module Idnow
21
23
  end
22
24
 
23
25
  def list_cached_document_definitions(refresh = false)
24
- return @document_definitions = list_document_definitions if refresh
25
- @document_definitions ||= list_document_definitions
26
+ return @list_cached_document_definitions = list_document_definitions if refresh
27
+ @list_cached_document_definitions ||= list_document_definitions
26
28
  end
27
29
  end
28
30
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  module API
3
5
  module DownloadDocuments
4
6
  def download_default_document(document_definition_identifier)
5
- fail Idnow::AuthenticationException if @auth_token.nil?
7
+ raise Idnow::AuthenticationException if @auth_token.nil?
6
8
 
7
9
  path = full_path_for("documentdefinitions/#{document_definition_identifier}/data")
8
10
  request = Idnow::GetRequest.new(path, '')
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  module API
3
5
  module RequestIdentifications
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  module API
3
5
  module RetrieveIdentifications
4
- IDENTIFICATION_STATUSES = %w(pending failed).freeze
6
+ IDENTIFICATION_STATUSES = %w[pending failed].freeze
5
7
 
6
8
  def list_identifications(status: nil)
7
- fail Idnow::AuthenticationException if @auth_token.nil?
9
+ raise Idnow::AuthenticationException if @auth_token.nil?
8
10
 
9
11
  unless status.nil? || IDENTIFICATION_STATUSES.include?(status)
10
- fail Idnow::InvalidArguments, "Status #{status} not defined, possible options are: #{IDENTIFICATION_STATUSES.join(',')}"
12
+ raise Idnow::InvalidArguments, "Status #{status} not defined, possible options are: #{IDENTIFICATION_STATUSES.join(',')}"
11
13
  end
12
14
  partial_path = status.nil? ? 'identifications' : "identifications?#{status}=true"
13
15
  path = full_path_for(partial_path)
@@ -19,7 +21,7 @@ module Idnow
19
21
  end
20
22
 
21
23
  def get_identification(transaction_number:)
22
- fail Idnow::AuthenticationException if @auth_token.nil?
24
+ raise Idnow::AuthenticationException if @auth_token.nil?
23
25
 
24
26
  path = full_path_for("identifications/#{transaction_number}")
25
27
  request = Idnow::GetRequest.new(path)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  module API
3
5
  module UploadDocuments
@@ -14,7 +16,7 @@ module Idnow
14
16
  private
15
17
 
16
18
  def upload_document(file_data, request_path)
17
- fail Idnow::AuthenticationException if @auth_token.nil?
19
+ raise Idnow::AuthenticationException if @auth_token.nil?
18
20
  request = Idnow::PostBinaryRequest.new(request_path, file_data)
19
21
  execute(request, 'X-API-LOGIN-TOKEN' => @auth_token)
20
22
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'idnow/API/authentication'
3
4
  require 'idnow/API/automated_testing' # shouldn't be included by default
4
5
  require 'idnow/API/request_identifications'
@@ -17,21 +18,24 @@ module Idnow
17
18
  include Idnow::API::UploadDocuments
18
19
  include Idnow::API::DownloadDocuments
19
20
 
20
- API_VERSION = 'v1'.freeze
21
+ API_VERSION = 'v1'
21
22
 
22
23
  attr_reader :host
23
24
 
24
- def initialize(env:, company_id:, api_key:)
25
- fail 'Please set env to :test or :live' unless Idnow::ENVIRONMENTS.keys.include?(env)
26
- fail 'Please set your company_id' if company_id.nil?
27
- fail 'Please set your api_key' if api_key.nil?
28
- @host = Idnow::ENVIRONMENTS[env][:host]
29
- @target_host = Idnow::ENVIRONMENTS[env][:target_host]
25
+ def initialize(env:, company_id:, api_key:, timeout: nil)
26
+ raise 'Please set env to :test or :live' unless Idnow::ENVIRONMENTS.keys.include?(env)
27
+ raise 'Please set your company_id' if company_id.nil?
28
+ raise 'Please set your api_key' if api_key.nil?
29
+ @host = Idnow.endpoint(env, :host)
30
+ @target_host = Idnow.endpoint(env, :target_host)
30
31
  @company_id = company_id
31
32
  @api_key = api_key
32
33
 
33
34
  @http_client = HttpClient.new(host: @host)
34
- @sftp_client = SftpClient.new(host: @host, username: @company_id, password: @api_key)
35
+
36
+ sftp_client_options = { host: @host, username: @company_id, password: @api_key }
37
+ sftp_client_options[:timeout] = timeout if timeout
38
+ @sftp_client = SftpClient.new(sftp_client_options)
35
39
  end
36
40
 
37
41
  private
@@ -46,7 +50,7 @@ module Idnow
46
50
  end
47
51
 
48
52
  response.tap do |r|
49
- fail Idnow::ResponseException, r.errors if r.errors?
53
+ raise Idnow::ResponseException, r.errors if r.errors?
50
54
  end
51
55
  end
52
56
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Idnow
3
4
  class Configuration
4
5
  # TODO: This class is not being used right now, but its aim is to be able for the developers
@@ -15,8 +16,8 @@ module Idnow
15
16
 
16
17
  module Idnow
17
18
  module Host
18
- TEST = 'https://gateway.test.idnow.de'.freeze
19
- PRODUCTION = 'https://gateway.idnow.de'.freeze
19
+ TEST = 'https://gateway.test.idnow.de'
20
+ PRODUCTION = 'https://gateway.idnow.de'
20
21
  end
21
22
  end
22
23
  attr_accessor :host
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  class Exception < StandardError
3
5
  def initialize(message)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/http'
2
4
 
3
5
  module Idnow
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  module Helpers
3
5
  PROJECT_ROOT = File.dirname(File.dirname(File.dirname(__FILE__)))
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  class HttpClient
3
5
  def initialize(host:, read_timout_sec: 30)
@@ -21,7 +23,7 @@ module Idnow
21
23
  def client
22
24
  Net::HTTP.new(@uri.host, @uri.port).tap do |http|
23
25
  http.read_timeout = @read_timeout
24
- http.use_ssl = true
26
+ http.use_ssl = @uri.scheme == 'https'
25
27
  end
26
28
  end
27
29
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  class JsonResponse < RawResponse
3
5
  attr_reader :data
4
6
 
5
7
  def initialize(raw_response)
6
8
  super
7
- raw_response = (raw_response == '') ? '{}' : raw_response
9
+ raw_response = raw_response == '' ? '{}' : raw_response
8
10
  @data = JSON.parse(raw_response)
9
11
  end
10
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  class ContactData
3
5
  include Idnow::Jsonable
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  class DocumentDefinition
3
5
  include Idnow::Jsonable
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'forwardable'
2
4
 
3
5
  module Idnow
@@ -1,20 +1,24 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'json'
3
4
 
4
5
  module Idnow
5
6
  class IdentificationData
6
7
  module Gender
7
- MALE = 'MALE'.freeze
8
- FEMALE = 'FEMALE'.freeze
8
+ MALE = 'MALE'
9
+ FEMALE = 'FEMALE'
9
10
  end
10
11
 
11
- attr_accessor :birthplace, :birthname, :city, :country, :custom1,
12
- :custom2, :custom3, :custom4, :custom5, :trackingid, :email, :firstname, :gender,
13
- :lastname, :mobilephone, :nationality, :street, :streetnumber, :title, :zipcode
12
+ attr_accessor :birthplace, :birthname, :city, :custom1,
13
+ :custom2, :custom3, :custom4, :custom5, :trackingid, :email, :firstname,
14
+ :lastname, :mobilephone, :nationality, :street, :streetnumber, :title, :zipcode,
15
+ :preferredLang
16
+
17
+ attr_reader :country, :gender
14
18
 
15
19
  def initialize(params = {})
16
20
  params.keys.each do |key|
17
- fail ArgumentError, "Attribute #{key} is not supported!" unless respond_to?(key.to_sym)
21
+ raise ArgumentError, "Attribute #{key} is not supported!" unless respond_to?(key.to_sym)
18
22
 
19
23
  send("#{key}=", params[key])
20
24
  end
@@ -31,7 +35,7 @@ module Idnow
31
35
  ########### Getter / Setter ############
32
36
 
33
37
  def birthday
34
- @birthday.strftime('%Y-%m-%d') if @birthday
38
+ @birthday&.strftime('%Y-%m-%d')
35
39
  end
36
40
 
37
41
  def birthday=(birthday)
@@ -43,18 +47,18 @@ module Idnow
43
47
  end
44
48
 
45
49
  def country=(country)
46
- fail ArgumentError, 'Country must be ISO 3166 two letter country code' unless country.instance_of?(String) && country.size == 2
50
+ raise ArgumentError, 'Country must be ISO 3166 two letter country code' unless country.instance_of?(String) && country.size == 2
47
51
 
48
52
  @country = country.upcase
49
53
  end
50
54
 
51
55
  def gender=(gender)
52
- if %w(M MALE).include?(gender.to_s.strip.upcase)
56
+ if %w[M MALE].include?(gender.to_s.strip.upcase)
53
57
  @gender = Gender::MALE
54
- elsif %w(F FEMALE).include?(gender.to_s.strip.upcase)
58
+ elsif %w[F FEMALE].include?(gender.to_s.strip.upcase)
55
59
  @gender = Gender::FEMALE
56
60
  else
57
- fail ArgumentError, 'Provide valid value for gender: MALE or FEMALE'
61
+ raise ArgumentError, 'Provide valid value for gender: MALE or FEMALE'
58
62
  end
59
63
  end
60
64
  end
@@ -1,15 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  class IdentificationDocument
3
5
  include Idnow::Jsonable
4
6
 
5
- attr_accessor :country, :number, :issued_by, :date_issued, :type, :valid_until
7
+ attr_accessor :country, :number, :issued_by, :type
8
+ attr_writer :date_issued, :valid_until
9
+
6
10
  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)
11
+ @country = data.dig('country', 'value')
12
+ @number = data.dig('number', 'value')
13
+ @issued_by = data.dig('issuedby', 'value')
14
+ @date_issued = data.dig('dateissued', 'value')
15
+ @type = data.dig('type', 'value')
16
+ @valid_until = data.dig('validuntil', 'value')
13
17
  end
14
18
 
15
19
  def date_issued
@@ -19,16 +23,5 @@ module Idnow
19
23
  def valid_until
20
24
  Date.parse(@valid_until) if @valid_until
21
25
  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
26
  end
34
27
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  class IdentificationProcess
3
5
  include Idnow::Jsonable
4
6
 
5
- SUCCESSFUL_RESPONSES = %w(SUCCESS SUCCESS_DATA_CHANGED).freeze
7
+ SUCCESSFUL_RESPONSES = %w[SUCCESS SUCCESS_DATA_CHANGED].freeze
6
8
  attr_accessor :result, :reason, :company_id, :filename, :agentname, :identification_time, :id, :href, :type, :transaction_number
7
9
 
8
10
  def initialize(data)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  class IdentificationRequest
3
5
  attr_accessor :id, :transaction_number
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  class Login
3
5
  attr_accessor :auth_token
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
 
3
5
  module Idnow
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  class UserData
3
5
  include Idnow::Jsonable
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  module Jsonable
3
5
  def to_h
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/http'
2
4
 
3
5
  module Idnow
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # require 'json'
2
4
  require 'net/http'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Idnow
2
4
  class RawResponse
3
5
  attr_reader :raw
@@ -23,9 +25,9 @@ module Idnow
23
25
 
24
26
  def valid_json?(json)
25
27
  JSON.parse(json)
26
- return true
28
+ true
27
29
  rescue JSON::ParserError
28
- return false
30
+ false
29
31
  end
30
32
  end
31
33
  end
@@ -1,17 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/sftp'
2
4
 
3
5
  module Idnow
4
6
  class SftpClient
5
- def initialize(host:, username:, password:)
7
+ def initialize(host:, username:, password:, timeout: nil)
6
8
  @host = URI.parse(host).host
7
9
  @username = username
8
10
  @password = password
11
+ @timeout = timeout
9
12
  end
10
13
 
11
14
  def download(file_name)
12
15
  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}" unless file_exists(sftp, file_name)
16
+ options = { password: @password }
17
+ options[:timeout] = @timeout if @timeout
18
+ Net::SFTP.start(@host, @username, options) do |sftp|
19
+ raise Idnow::Exception, "Invalid path. No identification file found under #{file_name}" unless file_exists(sftp, file_name)
15
20
  begin
16
21
  data = sftp.download!(file_name)
17
22
  rescue Net::SFTP::Exception => e
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idnow
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joan Martinez, Tobias Bielohlawek
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-12 00:00:00.000000000 Z
11
+ date: 2018-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-sftp
@@ -25,92 +25,92 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec
28
+ name: factory_bot
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.3'
33
+ version: '4.5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.3'
40
+ version: '4.5'
41
41
  - !ruby/object:Gem::Dependency
42
- name: webmock
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.22'
47
+ version: '3.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.22'
54
+ version: '3.3'
55
55
  - !ruby/object:Gem::Dependency
56
- name: simplecov
56
+ name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.10'
61
+ version: 0.54.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.10'
68
+ version: 0.54.0
69
69
  - !ruby/object:Gem::Dependency
70
- name: rubocop
70
+ name: shoulda-matchers
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.36.0
75
+ version: '3.1'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.36.0
82
+ version: '3.1'
83
83
  - !ruby/object:Gem::Dependency
84
- name: factory_girl
84
+ name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '4.5'
89
+ version: '0.10'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '4.5'
96
+ version: '0.10'
97
97
  - !ruby/object:Gem::Dependency
98
- name: shoulda-matchers
98
+ name: webmock
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '3.1'
103
+ version: '1.22'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '3.1'
110
+ version: '1.22'
111
111
  description: Library to consume the IDnow API in Ruby, http://www.idnow.eu/developers
112
112
  email:
113
- - joan.martinez.ripoll@gmail.com
113
+ - joan.martinez@solarisbank.de
114
114
  executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
@@ -120,6 +120,7 @@ files:
120
120
  - ".rubocop.yml"
121
121
  - ".travis.yml"
122
122
  - CODE_OF_CONDUCT.md
123
+ - Dockerfile
123
124
  - Gemfile
124
125
  - LICENSE.txt
125
126
  - Makefile
@@ -171,9 +172,9 @@ require_paths:
171
172
  - lib
172
173
  required_ruby_version: !ruby/object:Gem::Requirement
173
174
  requirements:
174
- - - ">="
175
+ - - "~>"
175
176
  - !ruby/object:Gem::Version
176
- version: '0'
177
+ version: '2.3'
177
178
  required_rubygems_version: !ruby/object:Gem::Requirement
178
179
  requirements:
179
180
  - - ">="
@@ -181,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
182
  version: '0'
182
183
  requirements: []
183
184
  rubyforge_project:
184
- rubygems_version: 2.6.6
185
+ rubygems_version: 2.6.14
185
186
  signing_key:
186
187
  specification_version: 4
187
188
  summary: Ruby client for the IDnow API