iwoca 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 +13 -0
- data/.rspec +4 -0
- data/.rubocop.yml +31 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +105 -0
- data/README.md +104 -0
- data/Rakefile +8 -0
- data/bin/console +22 -0
- data/bin/setup +8 -0
- data/iwoca.gemspec +46 -0
- data/lib/iwoca.rb +23 -0
- data/lib/iwoca/configuration.rb +28 -0
- data/lib/iwoca/connection.rb +70 -0
- data/lib/iwoca/customer_generator.rb +130 -0
- data/lib/iwoca/path_sanitizer.rb +13 -0
- data/lib/iwoca/quote.rb +43 -0
- data/lib/iwoca/response.rb +23 -0
- data/lib/iwoca/version.rb +5 -0
- data/vcr_cassettes/approval_invalid.yml +65 -0
- data/vcr_cassettes/approval_valid.yml +65 -0
- data/vcr_cassettes/create_customer_invalid.yml +71 -0
- data/vcr_cassettes/create_customer_no_auth.yml +71 -0
- data/vcr_cassettes/create_customer_valid.yml +71 -0
- data/vcr_cassettes/credit_facility_status_approved.yml +76 -0
- data/vcr_cassettes/credit_facility_status_declined.yml +73 -0
- data/vcr_cassettes/credit_facility_status_invalid.yml +65 -0
- data/vcr_cassettes/credit_facility_status_no_decision_possible.yml +73 -0
- data/vcr_cassettes/credit_facility_status_valid.yml +73 -0
- data/vcr_cassettes/login_link_invalid.yml +65 -0
- data/vcr_cassettes/login_link_valid.yml +65 -0
- metadata +299 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dc06c9b15b3cf293d246f1cce76c9dada20bb1b0b5185fa3375e6b12a1e096fc
|
4
|
+
data.tar.gz: e5de537071c70452a658693a671f8335fb983e8a908a27433f935b9ec5306242
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dc29294dd0453a1785c521e276fafc7de7fc91f8d53a7fe43bbe776f576094a8f0fa283f232938a7f986dcc404e598d6c98ebae2e57180a1eebab0adf3665643
|
7
|
+
data.tar.gz: a77cf2fb8cd03df9977d62831f9ce1766fd6d3d9342aba8343873a20911f1a27cae2772643742df0f14abee09d8a03f88e0818ba7cfa4d63de4d98455a04e3d2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.5.1
|
5
|
+
|
6
|
+
# Don't force top level comments in every class
|
7
|
+
Style/Documentation:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
# A good line length is 100 chars
|
11
|
+
Layout/LineLength:
|
12
|
+
Max: 100
|
13
|
+
AllowURI: true
|
14
|
+
|
15
|
+
Metrics/BlockLength:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/ClassLength:
|
19
|
+
Max: 300
|
20
|
+
|
21
|
+
Metrics/MethodLength:
|
22
|
+
Max: 20
|
23
|
+
|
24
|
+
Metrics/AbcSize:
|
25
|
+
Max: 30
|
26
|
+
|
27
|
+
RSpec/ExampleLength:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
RSpec/MultipleExpectations:
|
31
|
+
Max: 10
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
iwoca (1.0.0)
|
5
|
+
addressable
|
6
|
+
faraday
|
7
|
+
faraday_middleware
|
8
|
+
multi_json
|
9
|
+
rainbow
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
addressable (2.7.0)
|
15
|
+
public_suffix (>= 2.0.2, < 5.0)
|
16
|
+
ast (2.4.0)
|
17
|
+
byebug (11.1.0)
|
18
|
+
coderay (1.1.2)
|
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
|
+
dotenv (2.7.5)
|
25
|
+
faker (2.10.1)
|
26
|
+
i18n (>= 1.6, < 2)
|
27
|
+
faraday (0.17.3)
|
28
|
+
multipart-post (>= 1.2, < 3)
|
29
|
+
faraday_middleware (0.14.0)
|
30
|
+
faraday (>= 0.7.4, < 1.0)
|
31
|
+
hashdiff (1.0.0)
|
32
|
+
i18n (1.8.2)
|
33
|
+
concurrent-ruby (~> 1.0)
|
34
|
+
jaro_winkler (1.5.4)
|
35
|
+
json (2.3.0)
|
36
|
+
method_source (0.9.2)
|
37
|
+
multi_json (1.14.1)
|
38
|
+
multipart-post (2.1.1)
|
39
|
+
parallel (1.19.1)
|
40
|
+
parser (2.7.0.2)
|
41
|
+
ast (~> 2.4.0)
|
42
|
+
pry (0.12.2)
|
43
|
+
coderay (~> 1.1.0)
|
44
|
+
method_source (~> 0.9.0)
|
45
|
+
pry-byebug (3.7.0)
|
46
|
+
byebug (~> 11.0)
|
47
|
+
pry (~> 0.10)
|
48
|
+
public_suffix (4.0.3)
|
49
|
+
rainbow (3.0.0)
|
50
|
+
rake (10.5.0)
|
51
|
+
rspec (3.9.0)
|
52
|
+
rspec-core (~> 3.9.0)
|
53
|
+
rspec-expectations (~> 3.9.0)
|
54
|
+
rspec-mocks (~> 3.9.0)
|
55
|
+
rspec-core (3.9.1)
|
56
|
+
rspec-support (~> 3.9.1)
|
57
|
+
rspec-expectations (3.9.0)
|
58
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
59
|
+
rspec-support (~> 3.9.0)
|
60
|
+
rspec-mocks (3.9.1)
|
61
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
+
rspec-support (~> 3.9.0)
|
63
|
+
rspec-support (3.9.2)
|
64
|
+
rubocop (0.79.0)
|
65
|
+
jaro_winkler (~> 1.5.1)
|
66
|
+
parallel (~> 1.10)
|
67
|
+
parser (>= 2.7.0.1)
|
68
|
+
rainbow (>= 2.2.2, < 4.0)
|
69
|
+
ruby-progressbar (~> 1.7)
|
70
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
71
|
+
rubocop-rspec (1.37.1)
|
72
|
+
rubocop (>= 0.68.1)
|
73
|
+
ruby-progressbar (1.10.1)
|
74
|
+
safe_yaml (1.0.5)
|
75
|
+
simplecov (0.17.1)
|
76
|
+
docile (~> 1.1)
|
77
|
+
json (>= 1.8, < 3)
|
78
|
+
simplecov-html (~> 0.10.0)
|
79
|
+
simplecov-html (0.10.2)
|
80
|
+
unicode-display_width (1.6.1)
|
81
|
+
vcr (5.0.0)
|
82
|
+
webmock (3.8.0)
|
83
|
+
addressable (>= 2.3.6)
|
84
|
+
crack (>= 0.3.2)
|
85
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
86
|
+
|
87
|
+
PLATFORMS
|
88
|
+
ruby
|
89
|
+
|
90
|
+
DEPENDENCIES
|
91
|
+
bundler
|
92
|
+
dotenv
|
93
|
+
faker
|
94
|
+
iwoca!
|
95
|
+
pry-byebug
|
96
|
+
rake (~> 10.0)
|
97
|
+
rspec (~> 3.0)
|
98
|
+
rubocop
|
99
|
+
rubocop-rspec
|
100
|
+
simplecov
|
101
|
+
vcr
|
102
|
+
webmock
|
103
|
+
|
104
|
+
BUNDLED WITH
|
105
|
+
2.0.2
|
data/README.md
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
# iwoca API wrapper
|
2
|
+
|
3
|
+
This is a simple gem to interact with [iwoca's](https://www.iwoca.co.uk/) API.
|
4
|
+
|
5
|
+
The API documentation can be found here: https://developer.iwoca.co.uk/introduction/introduction
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'iwoca'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install iwoca
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
You need to have an api key to use the API. Every request will be authenticated with that key in the header.
|
26
|
+
|
27
|
+
### Configuration
|
28
|
+
|
29
|
+
You can configure Iwoca by providing a configuration block, before you do any call:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Iwoca.configure do |config|
|
33
|
+
config.api_key = YOUR_API_KEY_HERE
|
34
|
+
config.webhook_signature = YOUR_WEBHOOK_SIGNATURE
|
35
|
+
# config.debug = true # This is false by default, keep in mind it will ve VERY verbose
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
### Quote
|
40
|
+
|
41
|
+
All the available methods are encapsulated in the `Quote` class. The available methods are:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
Iwoca.create_customer(CUSTOMER_JSON)
|
45
|
+
# => This will return a state_key, if the JSON is valid. You need this key to call other methods.
|
46
|
+
|
47
|
+
Iwoca.update_customer(state_key, CUSTOMER_JSON)
|
48
|
+
|
49
|
+
Iwoca.approval(state_key)
|
50
|
+
|
51
|
+
Iwoca.login_link(state_key)
|
52
|
+
|
53
|
+
Iwoca.credit_facility_status(state_key)
|
54
|
+
```
|
55
|
+
|
56
|
+
Every call will return a `Iwoca::Response` instance, that you can use to get all the information
|
57
|
+
you need:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
response = Iwoca.login_link(state_key)
|
61
|
+
|
62
|
+
response.status #=> 200
|
63
|
+
response.success? #=> true
|
64
|
+
response.errors #=> []
|
65
|
+
response.data #=> { login_link: 'http://login_link' }
|
66
|
+
```
|
67
|
+
|
68
|
+
## Development
|
69
|
+
|
70
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run
|
71
|
+
the tests. You can also run `bin/console` for an interactive prompt that will allow you to
|
72
|
+
experiment.
|
73
|
+
|
74
|
+
Please refer to iwoca's documentation on how to test different states (we do have recorded VCR
|
75
|
+
responses, but if something changes on their side we need to update). The documentation is here:
|
76
|
+
https://developer.iwoca.co.uk/lending-api-v1/testing-your-integration/core-test-data.
|
77
|
+
|
78
|
+
In `spec/data` we have the stored customer data that will return a 'approved' state. Use this to
|
79
|
+
generate valid state keys and follow their instructions to generate the other states.
|
80
|
+
|
81
|
+
### Webhook
|
82
|
+
|
83
|
+
Iwoca webhook will target this address:
|
84
|
+
https://dev-finpointdev.pagekite.me/fast_lender_webhooks/iwoca_event
|
85
|
+
|
86
|
+
How to install:
|
87
|
+
|
88
|
+
$ curl -O https://pagekite.net/pk/pagekite.py
|
89
|
+
$ chmod +x pagekite.py
|
90
|
+
$ sudo mv -f pagekite.py /usr/local/bin (replace with the name of your directory)
|
91
|
+
|
92
|
+
How to run:
|
93
|
+
|
94
|
+
./pagekite.py 3000 dev-finpointdev.pagekite.me
|
95
|
+
|
96
|
+
pagekite.net details:
|
97
|
+
|
98
|
+
* u: hello@finpoint.co.uk
|
99
|
+
* p: fckx7989
|
100
|
+
|
101
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new
|
102
|
+
version, update the version number in `version.rb`, and then run `bundle exec rake release`, which
|
103
|
+
will create a git tag for the version, push git commits and tags, and push the `.gem` file
|
104
|
+
to [rubygems.org](https://rubygems.org).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'iwoca'
|
6
|
+
require 'date'
|
7
|
+
|
8
|
+
require 'dotenv'
|
9
|
+
Dotenv.load
|
10
|
+
|
11
|
+
Iwoca.configure do |config|
|
12
|
+
config.api_key = ENV['IWOCA_API_KEY']
|
13
|
+
config.webhook_signature = ENV['IWOCA_WEBHOOK_SIGNATURE']
|
14
|
+
end
|
15
|
+
|
16
|
+
# Useful if we need to do some tests
|
17
|
+
require 'iwoca/customer_generator'
|
18
|
+
|
19
|
+
send(:include, Iwoca)
|
20
|
+
|
21
|
+
require 'pry'
|
22
|
+
Pry.start
|
data/bin/setup
ADDED
data/iwoca.gemspec
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'iwoca/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'iwoca'
|
10
|
+
spec.version = Iwoca::VERSION
|
11
|
+
spec.authors = ['rikas']
|
12
|
+
spec.email = ['oterosantos@gmail.com']
|
13
|
+
|
14
|
+
spec.summary = 'Iwoca API wrapper'
|
15
|
+
spec.description = spec.summary
|
16
|
+
spec.homepage = 'https://www.iwoca.com'
|
17
|
+
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
|
29
|
+
spec.add_dependency 'addressable'
|
30
|
+
spec.add_dependency 'faraday'
|
31
|
+
spec.add_dependency 'faraday_middleware'
|
32
|
+
spec.add_dependency 'multi_json'
|
33
|
+
spec.add_dependency 'rainbow'
|
34
|
+
|
35
|
+
spec.add_development_dependency 'bundler'
|
36
|
+
spec.add_development_dependency 'dotenv'
|
37
|
+
spec.add_development_dependency 'faker'
|
38
|
+
spec.add_development_dependency 'pry-byebug'
|
39
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
40
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
41
|
+
spec.add_development_dependency 'rubocop'
|
42
|
+
spec.add_development_dependency 'rubocop-rspec'
|
43
|
+
spec.add_development_dependency 'simplecov'
|
44
|
+
spec.add_development_dependency 'vcr'
|
45
|
+
spec.add_development_dependency 'webmock'
|
46
|
+
end
|
data/lib/iwoca.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'iwoca/version'
|
4
|
+
require 'iwoca/path_sanitizer'
|
5
|
+
require 'iwoca/configuration'
|
6
|
+
require 'iwoca/connection'
|
7
|
+
require 'iwoca/quote'
|
8
|
+
|
9
|
+
module Iwoca
|
10
|
+
module_function
|
11
|
+
|
12
|
+
def configuration
|
13
|
+
@configuration ||= Configuration.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def connection
|
17
|
+
@connection ||= Connection.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def configure
|
21
|
+
yield(configuration)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Iwoca
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :api_key, :webhook_signature, :env
|
6
|
+
attr_writer :debug
|
7
|
+
|
8
|
+
API_DOMAINS = {
|
9
|
+
production: 'https://www.iwoca.co.uk',
|
10
|
+
development: 'https://stage.iwoca-dev.co.uk'
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@api_key = ''
|
15
|
+
@webhook_signature = ''
|
16
|
+
@env = defined?(Rails) ? Rails.env : :development
|
17
|
+
@debug = false
|
18
|
+
end
|
19
|
+
|
20
|
+
def debug?
|
21
|
+
@debug
|
22
|
+
end
|
23
|
+
|
24
|
+
def api_domain
|
25
|
+
API_DOMAINS[@env.to_sym] || API_DOMAINS[:development]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'faraday_middleware'
|
5
|
+
require 'rainbow'
|
6
|
+
require 'addressable'
|
7
|
+
|
8
|
+
require 'iwoca/response'
|
9
|
+
|
10
|
+
module Iwoca
|
11
|
+
class Connection
|
12
|
+
BASE_PATH = '/api/lending/v1'
|
13
|
+
|
14
|
+
def get(path, params = {})
|
15
|
+
log "GET #{path} with #{params}"
|
16
|
+
|
17
|
+
http_response = adapter.get(PathSanitizer.sanitize(path), params)
|
18
|
+
|
19
|
+
log "Response: #{http_response.body}"
|
20
|
+
|
21
|
+
Response.new(http_response)
|
22
|
+
end
|
23
|
+
|
24
|
+
def post(path, params = {})
|
25
|
+
log "POST #{path} with #{params}"
|
26
|
+
|
27
|
+
http_response = adapter.post(PathSanitizer.sanitize(path), params.to_json)
|
28
|
+
|
29
|
+
log "Response: #{http_response.body}"
|
30
|
+
|
31
|
+
Response.new(http_response)
|
32
|
+
end
|
33
|
+
|
34
|
+
def put(path, params = {})
|
35
|
+
log "PUT #{path} with #{params}"
|
36
|
+
|
37
|
+
http_response = adapter.put(PathSanitizer.sanitize(path), params.to_json)
|
38
|
+
|
39
|
+
log "Response: #{http_response.body}"
|
40
|
+
|
41
|
+
Response.new(http_response)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def log(text)
|
47
|
+
return unless Iwoca.configuration.debug?
|
48
|
+
|
49
|
+
puts Rainbow("[Iwoca] #{text}").magenta.bright
|
50
|
+
end
|
51
|
+
|
52
|
+
def base_url
|
53
|
+
Addressable::URI.join(Iwoca.configuration.api_domain, BASE_PATH).to_s
|
54
|
+
end
|
55
|
+
|
56
|
+
def adapter
|
57
|
+
token = Iwoca.configuration.api_key
|
58
|
+
|
59
|
+
Faraday.new(url: base_url) do |conn|
|
60
|
+
conn.headers['Authorization'] = "Token #{token}" unless token.to_s.empty?
|
61
|
+
conn.headers['Content-Type'] = 'application/json'
|
62
|
+
conn.headers['User-Agent'] = "ruby-iwoca-#{VERSION}"
|
63
|
+
conn.use FaradayMiddleware::ParseJson
|
64
|
+
conn.response :json, parser_options: { symbolize_names: true }
|
65
|
+
conn.response :logger if Iwoca.configuration.debug?
|
66
|
+
conn.adapter Faraday.default_adapter
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|