onfido 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +161 -0
  3. data/.rspec +3 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +14 -0
  6. data/LICENSE +22 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +154 -0
  9. data/Rakefile +2 -0
  10. data/lib/onfido.rb +23 -0
  11. data/lib/onfido/address.rb +10 -0
  12. data/lib/onfido/api.rb +18 -0
  13. data/lib/onfido/applicant.rb +18 -0
  14. data/lib/onfido/check.rb +21 -0
  15. data/lib/onfido/configuration.rb +35 -0
  16. data/lib/onfido/document.rb +13 -0
  17. data/lib/onfido/null_logger.rb +6 -0
  18. data/lib/onfido/report.rb +11 -0
  19. data/lib/onfido/request_error.rb +23 -0
  20. data/lib/onfido/requestable.rb +12 -0
  21. data/lib/onfido/resource.rb +48 -0
  22. data/lib/onfido/response_handler.rb +38 -0
  23. data/lib/onfido/version.rb +3 -0
  24. data/onfido.gemspec +25 -0
  25. data/spec/integrations/4xx_response_spec.rb +35 -0
  26. data/spec/integrations/address_spec.rb +10 -0
  27. data/spec/integrations/applicant_spec.rb +73 -0
  28. data/spec/integrations/check_spec.rb +36 -0
  29. data/spec/integrations/document_spec.rb +27 -0
  30. data/spec/integrations/report_spec.rb +20 -0
  31. data/spec/onfido/request_error_spec.rb +39 -0
  32. data/spec/onfido/resource_spec.rb +63 -0
  33. data/spec/onfido/response_handler_spec.rb +79 -0
  34. data/spec/onfido_spec.rb +55 -0
  35. data/spec/spec_helper.rb +45 -0
  36. data/spec/support/fake_onfido_api.rb +55 -0
  37. data/spec/support/fixtures/4xx_response.json +14 -0
  38. data/spec/support/fixtures/addresses.json +24 -0
  39. data/spec/support/fixtures/applicant.json +44 -0
  40. data/spec/support/fixtures/applicants.json +12 -0
  41. data/spec/support/fixtures/check.json +30 -0
  42. data/spec/support/fixtures/checks.json +34 -0
  43. data/spec/support/fixtures/document.json +10 -0
  44. data/spec/support/fixtures/report.json +10 -0
  45. data/spec/support/fixtures/reports.json +24 -0
  46. metadata +151 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2b1dc6db6e4973faba6292df170163a8d0d48c7d
4
+ data.tar.gz: 14a83b00ff4b77f746bfaf4d4b916af4cfa01c92
5
+ SHA512:
6
+ metadata.gz: 9f646210c77a49dcb05d9a9c8b8cff9696509cfa16fd6ebbe9fbe591c3f0f219fc352c6230299d2b2c8e494a23244e6a76ace37edb09f3a4acb58435f3b5e2cb
7
+ data.tar.gz: 69243a11afe9e5a9f683210d7d0ad5f0165b7b778812d75571db9cb989254754296e0a93515c8708df61e01ed05329e0c5d7e5959ab3007e6015a64af8336782
data/.gitignore ADDED
@@ -0,0 +1,161 @@
1
+ # Created by https://www.gitignore.io
2
+
3
+ ### Emacs ###
4
+ # -*- mode: gitignore; -*-
5
+ *~
6
+ \#*\#
7
+ /.emacs.desktop
8
+ /.emacs.desktop.lock
9
+ *.elc
10
+ auto-save-list
11
+ tramp
12
+ .\#*
13
+
14
+ # Org-mode
15
+ .org-id-locations
16
+ *_archive
17
+
18
+ # flymake-mode
19
+ *_flymake.*
20
+
21
+ # eshell files
22
+ /eshell/history
23
+ /eshell/lastdir
24
+
25
+ # elpa packages
26
+ /elpa/
27
+
28
+ # reftex files
29
+ *.rel
30
+
31
+ # AUCTeX auto folder
32
+ /auto/
33
+
34
+ # cask packages
35
+ .cask/
36
+
37
+
38
+ ### OSX ###
39
+ .DS_Store
40
+ .AppleDouble
41
+ .LSOverride
42
+
43
+ # Icon must end with two \r
44
+ Icon
45
+
46
+
47
+ # Thumbnails
48
+ ._*
49
+
50
+ # Files that might appear in the root of a volume
51
+ .DocumentRevisions-V100
52
+ .fseventsd
53
+ .Spotlight-V100
54
+ .TemporaryItems
55
+ .Trashes
56
+ .VolumeIcon.icns
57
+
58
+ # Directories potentially created on remote AFP share
59
+ .AppleDB
60
+ .AppleDesktop
61
+ Network Trash Folder
62
+ Temporary Items
63
+ .apdisk
64
+
65
+
66
+ ### Linux ###
67
+ *~
68
+
69
+ # KDE directory preferences
70
+ .directory
71
+
72
+ # Linux trash folder which might appear on any partition or disk
73
+ .Trash-*
74
+
75
+
76
+ ### RubyMine ###
77
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
78
+
79
+ *.iml
80
+
81
+ ## Directory-based project format:
82
+ .idea/
83
+ # if you remove the above rule, at least ignore the following:
84
+
85
+ # User-specific stuff:
86
+ # .idea/workspace.xml
87
+ # .idea/tasks.xml
88
+ # .idea/dictionaries
89
+
90
+ # Sensitive or high-churn files:
91
+ # .idea/dataSources.ids
92
+ # .idea/dataSources.xml
93
+ # .idea/sqlDataSources.xml
94
+ # .idea/dynamic.xml
95
+ # .idea/uiDesigner.xml
96
+
97
+ # Gradle:
98
+ # .idea/gradle.xml
99
+ # .idea/libraries
100
+
101
+ # Mongo Explorer plugin:
102
+ # .idea/mongoSettings.xml
103
+
104
+ ## File-based project format:
105
+ *.ipr
106
+ *.iws
107
+
108
+ ## Plugin-specific files:
109
+
110
+ # IntelliJ
111
+ /out/
112
+
113
+ # mpeltonen/sbt-idea plugin
114
+ .idea_modules/
115
+
116
+ # JIRA plugin
117
+ atlassian-ide-plugin.xml
118
+
119
+ # Crashlytics plugin (for Android Studio and IntelliJ)
120
+ com_crashlytics_export_strings.xml
121
+ crashlytics.properties
122
+ crashlytics-build.properties
123
+
124
+
125
+ ### Ruby ###
126
+ *.gem
127
+ *.rbc
128
+ /.config
129
+ /coverage/
130
+ /InstalledFiles
131
+ /pkg/
132
+ /spec/reports/
133
+ /test/tmp/
134
+ /test/version_tmp/
135
+ /tmp/
136
+
137
+ ## Specific to RubyMotion:
138
+ .dat*
139
+ .repl_history
140
+ build/
141
+
142
+ ## Documentation cache and generated files:
143
+ /.yardoc/
144
+ /_yardoc/
145
+ /doc/
146
+ /rdoc/
147
+
148
+ ## Environment normalisation:
149
+ /.bundle/
150
+ /vendor/bundle
151
+ /lib/bundler/man/
152
+ Gemfile.lock
153
+
154
+ # for a library or gem, you might want to ignore these files since the code is
155
+ # intended to run in multiple environments; otherwise, check them in:
156
+ # Gemfile.lock
157
+ # .ruby-version
158
+ # .ruby-gemset
159
+
160
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
161
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format documentation
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.3
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ group :development, :test do
5
+ gem 'pry'
6
+ gem 'pry-byebug'
7
+ gem 'pry-stack_explorer'
8
+ end
9
+
10
+ group :test do
11
+ gem 'rspec', '~> 3.1.0'
12
+ gem 'webmock', '~> 1.20.4'
13
+ gem 'sinatra', '~> 1.4.6'
14
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Hassle
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.
22
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Pericles Theodorou
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # Onfido
2
+
3
+ A wrapper for Onfido's [API](https://onfido.com/documentation#introduction). You should always refer to the documentation for valid API calls.
4
+
5
+ [!['gitter room'][2]][1]
6
+
7
+ [1]: https://gitter.im/hvssle/onfido
8
+ [2]: https://badges.gitter.im/gitterHQ/developers.png
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'onfido'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install onfido
25
+
26
+
27
+ ## Usage
28
+
29
+ There are 3 configuration options for Onfido, including your `api_key`, throwing exceptions for failed responses and logging the requests. By default, `throws_exceptions` is set to `true`. If set to `false`, the response body will be returned instead.
30
+
31
+ ```ruby
32
+ Onfido.configure do |config|
33
+ config.api_key = 'MY_API_KEY'
34
+ config.logger = Logger.new(STDOUT)
35
+ config.throws_exceptions = false
36
+ end
37
+ ```
38
+
39
+ Assuming you have a valid key, you can conveniently make API calls by using an instance of the `API` class.
40
+
41
+ ```ruby
42
+ api = Onfido::API.new
43
+ ```
44
+
45
+ ### Making calls to Onfido's resources
46
+
47
+ All resources share the same interface when making API calls. For creating a resource you can use `.create`, for finding one `.find` and for fetching all records for a resource `.all`.
48
+
49
+ **Note:** *All param keys should be a symbol e.g. `{type: 'express', reports: [{name: 'identity'}]}`*
50
+
51
+
52
+ ### Applicant
53
+
54
+ To create an applicant, you can simply use
55
+
56
+ ```ruby
57
+ api.applicant.create(params)
58
+ ```
59
+
60
+ To find an existing applicant
61
+
62
+ ```ruby
63
+ api.applicant.find('applicant_id')
64
+ ```
65
+
66
+ To get all applicants
67
+
68
+ ```ruby
69
+ api.applicant.all
70
+ ```
71
+
72
+ ### Document
73
+
74
+ To upload a document for an applicant, you can simply use
75
+
76
+ ```ruby
77
+ api.document.create('applicant_id', {file: 'http://example.com', type: 'passport')
78
+ ```
79
+
80
+ The file can both be a `File` object or a link to an image.
81
+
82
+ ### Check
83
+
84
+ To create a check for an applicant, you can simply use
85
+
86
+ ```ruby
87
+ api.check.create('applicant_id', {type: 'express', reports: [{name: 'identity'}]})
88
+ ```
89
+
90
+ To find an existing check for an applicant
91
+
92
+ ```ruby
93
+ api.check.find('applicant_id', 'check_id')
94
+ ```
95
+
96
+ To get all checks for an applicant
97
+
98
+ ```ruby
99
+ api.check.all('applicant_id')
100
+ ```
101
+
102
+ ### Report
103
+
104
+ To find an existing report for a check
105
+
106
+ ```ruby
107
+ api.report.find('check_id', 'report_id')
108
+ ```
109
+
110
+ To get all reports for a check
111
+
112
+ ```ruby
113
+ api.report.all('check_id')
114
+ ```
115
+
116
+ ### Address Picker
117
+
118
+ To search for addresses by postcode
119
+
120
+ ```ruby
121
+ api.address.all('SE1 4NG')
122
+ ```
123
+
124
+ ## Error Handling
125
+
126
+ By default, Onfido will attempt to raise errors returned by the API automatically.
127
+
128
+ If you set the `throws_exceptions` to false, it will simply return the response body. This allows you to handle errors manually.
129
+
130
+ If you rescue Onfido::RequestError, you are provided with the error message itself as well as the type of error, response code and fields that have errored. Here's how you might do that:
131
+
132
+ ```ruby
133
+ def create_applicant
134
+ api.applicant.create(params)
135
+ rescue Onfido::RequestError => e
136
+ e.type # returns 'validation_error'
137
+ e.fields # returns {"email": {"messages": ["invalid format"]}
138
+ e.response_code # returns '401'
139
+ end
140
+ ```
141
+
142
+ ### Roadmap
143
+
144
+ - Improve test coverage with more scenarios
145
+ - Add custom errors based on the response code.
146
+ - Improve documentation
147
+
148
+ ## Contributing
149
+
150
+ 1. Fork it ( https://github.com/hvssle/onfido/fork )
151
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
152
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
153
+ 4. Push to the branch (`git push origin my-new-feature`)
154
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
data/lib/onfido.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'json'
2
+ require 'rack'
3
+ require 'rest-client'
4
+ require 'open-uri'
5
+
6
+ require 'onfido/version'
7
+ require 'onfido/configuration'
8
+ require 'onfido/request_error'
9
+ require 'onfido/response_handler'
10
+ require 'onfido/null_logger'
11
+ require 'onfido/requestable'
12
+ require 'onfido/resource'
13
+ require 'onfido/address'
14
+ require 'onfido/applicant'
15
+ require 'onfido/document'
16
+ require 'onfido/check'
17
+ require 'onfido/report'
18
+ require 'onfido/api'
19
+
20
+
21
+ module Onfido
22
+ extend Configuration
23
+ end
@@ -0,0 +1,10 @@
1
+ module Onfido
2
+ class Address < Resource
3
+ def all(postcode)
4
+ get(
5
+ url: url_for('addresses/pick'),
6
+ payload: {postcode: postcode.delete(' ')}
7
+ )
8
+ end
9
+ end
10
+ end
data/lib/onfido/api.rb ADDED
@@ -0,0 +1,18 @@
1
+ module Onfido
2
+ class API
3
+ def method_missing(method, *args)
4
+ klass = method.to_s.capitalize
5
+ Object.const_get("Onfido::#{klass}").new
6
+ rescue NameError
7
+ super
8
+ end
9
+
10
+ def respond_to_missing?(method, include_private = false)
11
+ klass = method.to_s.capitalize
12
+ Object.const_get("Onfido::#{klass}")
13
+ true
14
+ rescue NameError
15
+ super
16
+ end
17
+ end
18
+ end