iwoca 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc06c9b15b3cf293d246f1cce76c9dada20bb1b0b5185fa3375e6b12a1e096fc
4
- data.tar.gz: e5de537071c70452a658693a671f8335fb983e8a908a27433f935b9ec5306242
3
+ metadata.gz: 198e9be11e22df1a0eeaaf7aeadf91a8d915890c83c034232f6c4f6bdf950d6b
4
+ data.tar.gz: 36a2b9b54228c00b077e2bb8a4f4be34e3f71b32631ae90a23fbc5a1d88c32a4
5
5
  SHA512:
6
- metadata.gz: dc29294dd0453a1785c521e276fafc7de7fc91f8d53a7fe43bbe776f576094a8f0fa283f232938a7f986dcc404e598d6c98ebae2e57180a1eebab0adf3665643
7
- data.tar.gz: a77cf2fb8cd03df9977d62831f9ce1766fd6d3d9342aba8343873a20911f1a27cae2772643742df0f14abee09d8a03f88e0818ba7cfa4d63de4d98455a04e3d2
6
+ metadata.gz: 9551708a25561b0ea8355ad4372e6fb65161d9e2b0ad418d48938fab648efe07b26d5191d8b80b99151f206873bef71662c7ad96485dd864629e03ac9f6ae446
7
+ data.tar.gz: 4683b1b27606c672d0feecc6c1160ec51218b223f57c253f4e4a266544587dba07393f6465752a916b0bf6788d2e24050d4252d7a410d0c55ad952bd96d46cbe
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.3
1
+ 3.1.2
data/Gemfile CHANGED
@@ -4,3 +4,15 @@ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in iwoca.gemspec
6
6
  gemspec
7
+
8
+ # Development dependencies
9
+ gem 'dotenv'
10
+ gem 'faker'
11
+ gem 'pry-byebug'
12
+ gem 'rake'
13
+ gem 'rspec'
14
+ gem 'rubocop'
15
+ gem 'rubocop-rspec'
16
+ gem 'simplecov'
17
+ gem 'vcr'
18
+ gem 'webmock'
data/Gemfile.lock CHANGED
@@ -1,86 +1,95 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- iwoca (1.0.0)
4
+ iwoca (1.1.0)
5
5
  addressable
6
- faraday
7
- faraday_middleware
8
- multi_json
6
+ faraday (~> 2.7)
7
+ json-schema
9
8
  rainbow
10
9
 
11
10
  GEM
12
11
  remote: https://rubygems.org/
13
12
  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)
13
+ addressable (2.8.1)
14
+ public_suffix (>= 2.0.2, < 6.0)
15
+ ast (2.4.2)
16
+ byebug (11.1.3)
17
+ coderay (1.1.3)
18
+ concurrent-ruby (1.2.2)
19
+ crack (0.4.5)
20
+ rexml
21
+ diff-lcs (1.5.0)
22
+ docile (1.4.0)
23
+ dotenv (2.8.1)
24
+ faker (3.1.1)
25
+ i18n (>= 1.8.11, < 2)
26
+ faraday (2.7.4)
27
+ faraday-net_http (>= 2.0, < 3.1)
28
+ ruby2_keywords (>= 0.0.4)
29
+ faraday-net_http (3.0.2)
30
+ hashdiff (1.0.1)
31
+ i18n (1.12.0)
33
32
  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)
33
+ json (2.6.3)
34
+ json-schema (4.0.0)
35
+ addressable (>= 2.8)
36
+ method_source (1.0.0)
37
+ parallel (1.22.1)
38
+ parser (3.2.1.0)
39
+ ast (~> 2.4.1)
40
+ pry (0.14.2)
41
+ coderay (~> 1.1)
42
+ method_source (~> 1.0)
43
+ pry-byebug (3.10.1)
46
44
  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)
45
+ pry (>= 0.13, < 0.15)
46
+ public_suffix (5.0.1)
47
+ rainbow (3.1.1)
48
+ rake (13.0.6)
49
+ regexp_parser (2.7.0)
50
+ rexml (3.2.5)
51
+ rspec (3.12.0)
52
+ rspec-core (~> 3.12.0)
53
+ rspec-expectations (~> 3.12.0)
54
+ rspec-mocks (~> 3.12.0)
55
+ rspec-core (3.12.1)
56
+ rspec-support (~> 3.12.0)
57
+ rspec-expectations (3.12.2)
58
58
  diff-lcs (>= 1.2.0, < 2.0)
59
- rspec-support (~> 3.9.0)
60
- rspec-mocks (3.9.1)
59
+ rspec-support (~> 3.12.0)
60
+ rspec-mocks (3.12.3)
61
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)
62
+ rspec-support (~> 3.12.0)
63
+ rspec-support (3.12.0)
64
+ rubocop (1.47.0)
65
+ json (~> 2.3)
66
66
  parallel (~> 1.10)
67
- parser (>= 2.7.0.1)
67
+ parser (>= 3.2.0.0)
68
68
  rainbow (>= 2.2.2, < 4.0)
69
+ regexp_parser (>= 1.8, < 3.0)
70
+ rexml (>= 3.2.5, < 4.0)
71
+ rubocop-ast (>= 1.26.0, < 2.0)
69
72
  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)
73
+ unicode-display_width (>= 2.4.0, < 3.0)
74
+ rubocop-ast (1.27.0)
75
+ parser (>= 3.2.1.0)
76
+ rubocop-capybara (2.17.1)
77
+ rubocop (~> 1.41)
78
+ rubocop-rspec (2.18.1)
79
+ rubocop (~> 1.33)
80
+ rubocop-capybara (~> 2.17)
81
+ ruby-progressbar (1.12.0)
82
+ ruby2_keywords (0.0.5)
83
+ simplecov (0.22.0)
76
84
  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)
85
+ simplecov-html (~> 0.11)
86
+ simplecov_json_formatter (~> 0.1)
87
+ simplecov-html (0.12.3)
88
+ simplecov_json_formatter (0.1.4)
89
+ unicode-display_width (2.4.2)
90
+ vcr (6.1.0)
91
+ webmock (3.18.1)
92
+ addressable (>= 2.8.0)
84
93
  crack (>= 0.3.2)
85
94
  hashdiff (>= 0.4.0, < 2.0.0)
86
95
 
@@ -88,13 +97,12 @@ PLATFORMS
88
97
  ruby
89
98
 
90
99
  DEPENDENCIES
91
- bundler
92
100
  dotenv
93
101
  faker
94
102
  iwoca!
95
103
  pry-byebug
96
- rake (~> 10.0)
97
- rspec (~> 3.0)
104
+ rake
105
+ rspec
98
106
  rubocop
99
107
  rubocop-rspec
100
108
  simplecov
@@ -102,4 +110,4 @@ DEPENDENCIES
102
110
  webmock
103
111
 
104
112
  BUNDLED WITH
105
- 2.0.2
113
+ 2.4.7
data/README.md CHANGED
@@ -36,28 +36,68 @@ Iwoca.configure do |config|
36
36
  end
37
37
  ```
38
38
 
39
- ### Quote
39
+ ### Check authentication
40
40
 
41
- All the available methods are encapsulated in the `Quote` class. The available methods are:
41
+ To check if you're using a good API Key you can invoke the `authentication_check` endpoint by
42
+ running:
42
43
 
43
44
  ```ruby
44
- Iwoca.create_customer(CUSTOMER_JSON)
45
+ Iwoca.authentication_check
46
+ # => Authentication check successful: {"version":"v2.1"}
47
+ ```
48
+
49
+ ### Customer
50
+
51
+ First thing you want to do is to create a customer:
52
+
53
+ ```ruby
54
+ customer_json = Iwoca::CustomerGenerator.generate # for test purposes
55
+ response = Iwoca::Customer.create(data: customer_json)
45
56
  # => This will return a state_key, if the JSON is valid. You need this key to call other methods.
46
57
 
47
- Iwoca.update_customer(state_key, CUSTOMER_JSON)
58
+ customer_id = response.data[:customer_id]
59
+ ```
60
+
61
+ Then you can update it, if you keep track of the customer_id that is returned:
62
+
63
+ ```ruby
64
+ Iwoca::Customer.update(customer_id: customer_id, data: customer_json)
65
+ ```
66
+
67
+ And finally you can get a login link:
68
+
69
+ ```ruby
70
+ Iwoca::Customer.login_link(customer_id: customer_id)
71
+ ```
72
+
73
+ ### Application
48
74
 
49
- Iwoca.approval(state_key)
75
+ After the customer is correctly created you can create an application:
50
76
 
51
- Iwoca.login_link(state_key)
77
+ ```ruby
78
+ app_json = Iwoca::ApplicationGenerator.generate # for test purposes
79
+ response = Iwoca::Application.create(customer_id: customer_id, data: app_json)
80
+
81
+ application_id = response.data[:application_id]
82
+ ```
83
+
84
+ This can then be used to check the status of the latest application for a customer:
52
85
 
53
- Iwoca.credit_facility_status(state_key)
86
+ ```ruby
87
+ Iwoca::Application.latest(customer_id: customer_id)
88
+ ```
89
+
90
+ Or, equally important, to check the offers:
91
+
92
+ ```ruby
93
+ Iwoca::Application.offers(application_id: application_id)
54
94
  ```
55
95
 
56
96
  Every call will return a `Iwoca::Response` instance, that you can use to get all the information
57
97
  you need:
58
98
 
59
99
  ```ruby
60
- response = Iwoca.login_link(state_key)
100
+ response = Iwoca::Customer.login_link(customer_id: customer_id)
61
101
 
62
102
  response.status #=> 200
63
103
  response.success? #=> true
@@ -65,6 +105,19 @@ response.errors #=> []
65
105
  response.data #=> { login_link: 'http://login_link' }
66
106
  ```
67
107
 
108
+ ### Webhooks
109
+
110
+ Newest iwoca version has a nice way to manage the webhooks, so we can change and check the status of
111
+ webhooks at any point.
112
+
113
+ ```ruby
114
+ Iwoca::Webhooks.configuration # what's the webook url and the secret token
115
+ Iwoca::Webhooks.update(config: {}) # update webhook configuration
116
+ Iwoca::Webhooks.event_types # list the webhook event types
117
+ Iwoca::Webhooks.subscribe(event_types: []) # subscribe to an event
118
+ Iwoca::Webhooks.subscriptions # list subscriptions
119
+ ```
120
+
68
121
  ## Development
69
122
 
70
123
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run
@@ -78,9 +131,9 @@ https://developer.iwoca.co.uk/lending-api-v1/testing-your-integration/core-test-
78
131
  In `spec/data` we have the stored customer data that will return a 'approved' state. Use this to
79
132
  generate valid state keys and follow their instructions to generate the other states.
80
133
 
81
- ### Webhook
134
+ ### Webhooks
82
135
 
83
- Iwoca webhook will target this address:
136
+ To test webhooks you may find it easier to use a test endpoint like:
84
137
  https://dev-finpointdev.pagekite.me/fast_lender_webhooks/iwoca_event
85
138
 
86
139
  How to install:
@@ -95,10 +148,5 @@ How to run:
95
148
 
96
149
  pagekite.net details:
97
150
 
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).
151
+ - u: hello@finpoint.co.uk
152
+ - p: fckx7989
data/bin/console CHANGED
@@ -15,8 +15,17 @@ end
15
15
 
16
16
  # Useful if we need to do some tests
17
17
  require 'iwoca/customer_generator'
18
+ require 'iwoca/application_generator'
18
19
 
19
20
  send(:include, Iwoca)
20
21
 
22
+ def generate_customer
23
+ CustomerGenerator.generate
24
+ end
25
+
26
+ def generate_app
27
+ ApplicationGenerator.generate
28
+ end
29
+
21
30
  require 'pry'
22
31
  Pry.start
data/iwoca.gemspec CHANGED
@@ -27,20 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ['lib']
28
28
 
29
29
  spec.add_dependency 'addressable'
30
- spec.add_dependency 'faraday'
31
- spec.add_dependency 'faraday_middleware'
32
- spec.add_dependency 'multi_json'
30
+ spec.add_dependency 'faraday', '~> 2.7'
33
31
  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'
32
+ spec.add_dependency 'json-schema'
46
33
  end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Iwoca
4
+ class Application
5
+ # This needs to be used after the customer has been created. It returns an application_id that
6
+ # can be used to identify the application in all future requests.
7
+ # The params argument needs to have the following structure:
8
+ # {
9
+ # data: {
10
+ # requests: [
11
+ # {
12
+ # amount: 15000,
13
+ # duration: {
14
+ # amount: 12,
15
+ # unit: "months"
16
+ # },
17
+ # product_type: "flexi_loan", # check the schema JSON for more options
18
+ # purpose: "equipment_purchase", # check the schema JSON for more options
19
+ # urgency: "asap"
20
+ # }
21
+ # ]
22
+ # }
23
+ # }
24
+ def self.create(customer_id:, data: {})
25
+ requests = (data.dig(:data, :requests) || []).first.to_json
26
+
27
+ # # Add the introducer so we can get a login link later
28
+ # data[:data][:introducer] = {
29
+ # entity_to_contact: 'customer',
30
+ # introducer_id: customer_id
31
+ # }
32
+
33
+ JSON::Validator.validate!('lib/iwoca/schemas/requested_product.json', requests)
34
+
35
+ Iwoca.connection.post("customers/#{customer_id}/applications/", data)
36
+ end
37
+
38
+ # Sending across the customer_id in the URL - you will receive back an object with the latest
39
+ # application information that we have.
40
+ #
41
+ # This will include a status field that can be one of the following options:
42
+ # open, deferred, declined, offered, conditional_offer, customer_to_link_open_banking,
43
+ # action_required, awaiting_underwriter, in_underwriting, expired, funded, offer_revoked,
44
+ # talking_to_customer.
45
+ #
46
+ # Check more info in the docs:
47
+ # https://iwoca.stoplight.io/docs/lapi-uk/branches/2.1.0/84660933e0b17-get-user-latest-application
48
+ def self.latest(customer_id:)
49
+ Iwoca.connection.get("customers/#{customer_id}/applications/latest/")
50
+ end
51
+
52
+ # Use this endpoint after creating an application to generate offers that your customer is
53
+ # eligible for.
54
+ # Offers are associated with the Application, so are retrieved using the customer's current
55
+ # application_id that you would have received in the previous request.
56
+ def self.offers(application_id:)
57
+ Iwoca.connection.get("applications/#{application_id}/offers/")
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal
2
+
3
+ module Iwoca
4
+ class ApplicationGenerator
5
+ def self.generate(params: {})
6
+ new(params:).generate
7
+ end
8
+
9
+ def initialize(params: {})
10
+ @params = params
11
+ end
12
+
13
+ def generate
14
+ {
15
+ data: {
16
+ last_12_months_turnover: { amount: 700000, valid_from: '2019-08-24T14:15:22Z' },
17
+ requests: [
18
+ {
19
+ amount: 15000,
20
+ product_type: 'flexi_loan',
21
+ duration: { amount: 12, unit: "months" },
22
+ purpose: 'equipment_purchase',
23
+ urgency: 'asap'
24
+ }
25
+ ]
26
+ }
27
+ }
28
+ end
29
+ end
30
+ end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'faraday'
4
- require 'faraday_middleware'
5
4
  require 'rainbow'
6
5
  require 'addressable'
7
6
 
@@ -9,7 +8,12 @@ require 'iwoca/response'
9
8
 
10
9
  module Iwoca
11
10
  class Connection
12
- BASE_PATH = '/api/lending/v1'
11
+ BASE_PATH = '/api/lending/v2.1'
12
+ BASE_NOTIFICATIONS_PATH = '/api/notifications/v1'
13
+
14
+ def initialize(type = 'base')
15
+ @base_path = type == 'notifications' ? BASE_NOTIFICATIONS_PATH : BASE_PATH
16
+ end
13
17
 
14
18
  def get(path, params = {})
15
19
  log "GET #{path} with #{params}"
@@ -50,17 +54,16 @@ module Iwoca
50
54
  end
51
55
 
52
56
  def base_url
53
- Addressable::URI.join(Iwoca.configuration.api_domain, BASE_PATH).to_s
57
+ Addressable::URI.join(Iwoca.configuration.api_domain, @base_path).to_s
54
58
  end
55
59
 
56
60
  def adapter
57
61
  token = Iwoca.configuration.api_key
58
62
 
59
63
  Faraday.new(url: base_url) do |conn|
60
- conn.headers['Authorization'] = "Token #{token}" unless token.to_s.empty?
64
+ conn.headers['Authorization'] = "Bearer #{token}" unless token.to_s.empty?
61
65
  conn.headers['Content-Type'] = 'application/json'
62
66
  conn.headers['User-Agent'] = "ruby-iwoca-#{VERSION}"
63
- conn.use FaradayMiddleware::ParseJson
64
67
  conn.response :json, parser_options: { symbolize_names: true }
65
68
  conn.response :logger if Iwoca.configuration.debug?
66
69
  conn.adapter Faraday.default_adapter
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Iwoca
4
+ class Customer
5
+ # The POST request should be used to create an iwoca account for the customer. It's always the
6
+ # first endpoint and method you should call when submitting a new customer. It returns a
7
+ # customer_id used to identify the customer in all future requests.
8
+ #
9
+ # Successful request will return a 201 status code and a JSON response containing a customer_id:
10
+ # Example: { data: { customer_id: "fd48781e-3ad3-4a94-b4a6-60fafeebab0b" } }
11
+ def self.create(data: {})
12
+ # Validate the schema first, to avoid making a request with invalid data.
13
+ JSON::Validator.validate!('lib/iwoca/schemas/customer_payload.json', data.to_json)
14
+
15
+ Iwoca.connection.post('customers/', data)
16
+ end
17
+
18
+ # The PUT request should be used to add or update data for a customer. Note that the entire
19
+ # State should be submitted each time you use this endpoint, even if you are just updating a
20
+ # few fields.
21
+ def self.update(customer_id:, data: {})
22
+ Iwoca.connection.put("customers/#{customer_id}/", data)
23
+ end
24
+
25
+ # Get a login link for a customer from a given customer_id
26
+ def self.login_link(customer_id:)
27
+ Iwoca.connection.get("customers/#{customer_id}/login_link/")
28
+ end
29
+ end
30
+ end