iwoca 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .env
10
+ .DS_Store
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
4
+ --order random
@@ -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
@@ -0,0 +1 @@
1
+ 2.6.3
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in iwoca.gemspec
6
+ gemspec
@@ -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
@@ -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).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -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
@@ -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