youlend 1.0.0 → 1.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2354061ae0d7285b3e71cdc4755a8d2f471d4ad0790baa4a1cb2656bbafdf796
4
- data.tar.gz: d59850f7a58272e68184c0a27f6b22ad138648cfcadb3361256a3e3855dfb2d3
3
+ metadata.gz: 4a0d506952a24eb9ecccb2ee7d2d89cf3d00306d093ff764793ab0895c3d68a9
4
+ data.tar.gz: 1aea5c48cb985851f2f5190c25b45727eb52d6b09e6017560e8616adf4e3f965
5
5
  SHA512:
6
- metadata.gz: 506fdac262543c0e1350810ed47ba72f4b814329aaab06cfbc4adf4089bd943db26ba1af53e9418c6f7d7147548cc9397569949c57a3bfec807ec4d55772bd22
7
- data.tar.gz: 8bca12acbdd170f27821f81499c3f254872c0b87d6c82f62ee05dda3af6c7fe26507d9e67dd0e2d6f6a87fd3509df64c9d7441bd54c72ca979c4947a4fba5aeb
6
+ metadata.gz: '049795bc3e787d888f7b6ca39bbb227bb0eccf85b1e0e83d3d6b366564b2fdd5209d5ad8083b93ee5e720bf4b13c30fd058463174fd9c582a68f44a56854cbf1'
7
+ data.tar.gz: 9b4d8c822433b93f95999c1f2ba355bf369c3516fa6917b3034732d3a60f9c0b974d12c954014967515960bba84131f776d54977e08547463326caccf36af4ae
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- youlend (1.0.0)
4
+ youlend (1.1.3)
5
5
  addressable
6
6
  faraday
7
7
  faraday_middleware
@@ -24,9 +24,11 @@ GEM
24
24
  dotenv (2.7.5)
25
25
  faker (2.11.0)
26
26
  i18n (>= 1.6, < 2)
27
- faraday (1.1.0)
27
+ faraday (1.3.0)
28
+ faraday-net_http (~> 1.0)
28
29
  multipart-post (>= 1.2, < 3)
29
30
  ruby2_keywords
31
+ faraday-net_http (1.0.1)
30
32
  faraday_middleware (1.0.0)
31
33
  faraday (~> 1.0)
32
34
  hashdiff (1.0.1)
@@ -73,7 +75,7 @@ GEM
73
75
  rubocop-rspec (1.39.0)
74
76
  rubocop (>= 0.68.1)
75
77
  ruby-progressbar (1.10.1)
76
- ruby2_keywords (0.0.2)
78
+ ruby2_keywords (0.0.4)
77
79
  safe_yaml (1.0.5)
78
80
  simplecov (0.18.5)
79
81
  docile (~> 1.1)
@@ -104,4 +106,4 @@ DEPENDENCIES
104
106
  youlend!
105
107
 
106
108
  BUNDLED WITH
107
- 2.1.4
109
+ 2.2.5
data/bin/console CHANGED
@@ -3,8 +3,8 @@
3
3
 
4
4
  require 'bundler/setup'
5
5
  require 'youlend'
6
- require 'youlend/merchant_generator'
7
- require 'youlend/lead_generator'
6
+ require 'youlend/params_generators/prequalification'
7
+ require 'youlend/params_generators/lead'
8
8
 
9
9
  require 'dotenv'
10
10
  Dotenv.load
@@ -15,12 +15,12 @@ Youlend.configure do |config|
15
15
  config.debug = true
16
16
  end
17
17
 
18
- def generate_merchant
19
- Youlend::MerchantGenerator.generate
18
+ def generate_prequalification
19
+ Youlend::ParamsGenerators::Prequalification.generate
20
20
  end
21
21
 
22
22
  def generate_lead
23
- Youlend::LeadGenerator.generate
23
+ Youlend::ParamsGenerators::Lead.generate
24
24
  end
25
25
 
26
26
  require 'pry'
data/lib/youlend.rb CHANGED
@@ -4,7 +4,7 @@ require 'youlend/version'
4
4
  require 'youlend/auth'
5
5
  require 'youlend/configuration'
6
6
  require 'youlend/connection'
7
- require 'youlend/quote'
7
+ require 'youlend/prequalification'
8
8
  require 'youlend/lead'
9
9
 
10
10
  module Youlend
data/lib/youlend/auth.rb CHANGED
@@ -9,7 +9,10 @@ module Youlend
9
9
  class Auth
10
10
  extend Forwardable
11
11
 
12
- AUTH_URL = 'https://youlend-stag.eu.auth0.com'
12
+ AUTH_URLS = {
13
+ production: 'https://youlend.eu.auth0.com',
14
+ development: 'https://youlend-stag.eu.auth0.com'
15
+ }.freeze
13
16
 
14
17
  AUDIENCES = %i[prequalification onboarding].freeze
15
18
  DEFAULT_AUDIENCE = :prequalification
@@ -46,7 +49,9 @@ module Youlend
46
49
  private
47
50
 
48
51
  def adapter
49
- Faraday.new(url: AUTH_URL) do |conn|
52
+ auth_url = AUTH_URLS[Youlend.configuration.env]
53
+
54
+ Faraday.new(url: auth_url) do |conn|
50
55
  conn.headers['Content-Type'] = 'application/json'
51
56
  conn.headers['User-Agent'] = "ruby-youlend-#{VERSION}"
52
57
  conn.use FaradayMiddleware::ParseJson
@@ -5,15 +5,20 @@ module Youlend
5
5
  attr_accessor :tokens, :client_id, :client_secret, :env
6
6
  attr_writer :debug
7
7
 
8
+ DOMAINS = {
9
+ production: 'https://youlend.com',
10
+ development: 'https://staging.youlend.com'
11
+ }.freeze
12
+
8
13
  API_DOMAINS = {
9
- production: '',
14
+ production: 'https://youlendapi.com',
10
15
  development: 'https://staging.youlendapi.com'
11
16
  }.freeze
12
17
 
13
18
  def initialize
14
19
  @tokens = { onboarding: '', prequalification: '' }
15
20
  @webhook_signature = ''
16
- @env = defined?(::Rails) ? ::Rails.env : :development
21
+ @env = defined?(::Rails) ? ::Rails.env.to_sym : :development
17
22
  @debug = false
18
23
  end
19
24
 
@@ -24,5 +29,9 @@ module Youlend
24
29
  def api_domain
25
30
  API_DOMAINS[@env.to_sym] || API_DOMAINS[:development]
26
31
  end
32
+
33
+ def domain
34
+ DOMAINS[@env.to_sym] || DOMAINS[:development]
35
+ end
27
36
  end
28
37
  end
@@ -40,6 +40,14 @@ module Youlend
40
40
  Response.new(http_response)
41
41
  end
42
42
 
43
+ def get(path, audience)
44
+ http_response = with_token_refresh(audience) do
45
+ adapter(audience).get(PathSanitizer.sanitize(path))
46
+ end
47
+
48
+ Response.new(http_response)
49
+ end
50
+
43
51
  private
44
52
 
45
53
  def log(text)
data/lib/youlend/lead.rb CHANGED
@@ -3,6 +3,10 @@
3
3
  # Following the API description here: https://staging.youlend.com/developer/main/onboardingdoc
4
4
  module Youlend
5
5
  class Lead
6
+ def self.create(params)
7
+ new(params).create
8
+ end
9
+
6
10
  def initialize(params)
7
11
  @id = nil
8
12
  @params = params
@@ -12,12 +16,15 @@ module Youlend
12
16
  Youlend.connection.post('/onboarding/Leads', :onboarding, @params)
13
17
  end
14
18
 
15
- def self.create(params)
16
- new(params).create
19
+ def self.details(lead_id)
20
+ Youlend.connection.get("/onboarding/Leads/#{lead_id}", :onboarding)
17
21
  end
18
22
 
19
- def self.details(lead_id)
20
- Youlend.connection.get("/onboarding/Leads/#{lead_id}/details", :onboarding)
23
+ def self.onboard_link(lead_id, email_address)
24
+ domain = Youlend.configuration.domain
25
+
26
+ url = Addressable::Template.new("#{domain}/dashboard/youlendapisignup{?query*}")
27
+ url.expand(query: { emailAddress: email_address, leadId: lead_id }).to_s
21
28
  end
22
29
  end
23
30
  end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faker'
4
+
5
+ module Youlend
6
+ module ParamsGenerators
7
+ class Lead
8
+ def self.generate
9
+ new.generate
10
+ end
11
+
12
+ def initialize
13
+ Faker::Config.locale = 'en-GB'
14
+
15
+ generate
16
+ end
17
+
18
+ # Mandatory fields:
19
+ # * CompanyName
20
+ # * CompanyType (ltd, plc, llp, dac, soleTrader, aps, as, ks, ivs and is)
21
+ # * MonthsTrading
22
+ # * CountryISOCode (GBR, DNK and IRE)
23
+ # * KeyContactName
24
+ # * ThirdPartyLeadId
25
+ # * RegisteredAddress
26
+ # * ContactPhoneNumber
27
+ # * MonthlyCardRevenue (must be greater than or equal to '1000')
28
+ # * ContactEmailAddress
29
+ # * LoanCurrencyISOCode (ISO 4217 currency code. Valid codes are GBP, EUR and DKK)
30
+ # * ThirdPartyCustomerId
31
+ def generate
32
+ {
33
+ companyName: 'HOKO LTD',
34
+ companyType: 'ltd',
35
+ monthsTrading: rand(3..10),
36
+ countryISOCode: 'GBR',
37
+ keyContactName: Faker::Name.name,
38
+ thirdPartyLeadId: SecureRandom.uuid,
39
+ registeredAddress: address,
40
+ contactPhoneNumber: Faker::PhoneNumber.phone_number,
41
+ monthlyCardRevenue: 10_000,
42
+ contactEmailAddress: Faker::Internet.email,
43
+ loanCurrencyISOCode: 'GBP',
44
+ thirdPartyCustomerId: SecureRandom.uuid,
45
+ companyNumber: '09525857', # optional
46
+ notificationURL: Faker::Internet.url, # optional
47
+ thirdPartyMerchantId: SecureRandom.uuid # optional
48
+ }
49
+ end
50
+
51
+ private
52
+
53
+ def address
54
+ {
55
+ line1: Faker::Address.street_address,
56
+ line2: Faker::Address.secondary_address,
57
+ city: 'London',
58
+ region: 'London',
59
+ areaCode: Faker::Address.zip_code,
60
+ country: 'UK'
61
+ }
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faker'
4
+
5
+ module Youlend
6
+ module ParamsGenerators
7
+ class Prequalification
8
+ def self.generate
9
+ new.generate
10
+ end
11
+
12
+ def initialize
13
+ Faker::Config.locale = 'en-GB'
14
+
15
+ generate
16
+ end
17
+
18
+ # Mandatory fields:
19
+ # * CompanyType (ltd, plc, llp, dac, partnership, soleTrader, aps, as, ks, ivs and is)
20
+ # * FinancialData
21
+ # * CountryISOCode (GBR, DNK and IRE)
22
+ # * LoanCurrencyISOCode (ISO 4217 currency code. Valid codes are GBP, EUR and DKK)
23
+ # * ThirdPartyMerchantId
24
+ #
25
+ # The only mandatory field should be the financial data. You SHOULD NOT provide company
26
+ # number, otherwise Youlend needs to ask for permission on credit checks.
27
+ def generate
28
+ {
29
+ companyType: 'ltd',
30
+ financialData: financial_data,
31
+ countryISOCode: 'GBR',
32
+ loanCurrencyISOCode: 'GBP',
33
+ thirdPartyMerchantId: SecureRandom.uuid,
34
+ companyName: 'HOKO LTD', # optional
35
+ companyNumber: '09525857', # optional
36
+ significantPersons: [significant_person], # optional
37
+ contactEmailAddress: 'oterosantos@gmail.com' # optional
38
+ }
39
+ end
40
+
41
+ private
42
+
43
+ def financial_data
44
+ {
45
+ monthlyCardRevenue: 0,
46
+ monthlyValueOfPurchaseTransactions: 0,
47
+ monthlyRevenueFromInvoices: 0,
48
+ paymentData: payment_data
49
+ }
50
+ end
51
+
52
+ def payment_data
53
+ (1..12).to_a.map do |month|
54
+ formatted_month = format('%02<month>d', month: month)
55
+
56
+ {
57
+ paymentDate: "#{Date.today.year - 1}-#{formatted_month}-01",
58
+ amount: 5000,
59
+ currencyISOCode: 'GBP'
60
+ }
61
+ end
62
+ end
63
+
64
+ def significant_person
65
+ {
66
+ firstName: Faker::Name.first_name,
67
+ surname: Faker::Name.last_name,
68
+ address: address,
69
+ dateOfBirth: Date.parse('1980-01-01').to_s
70
+ }
71
+ end
72
+
73
+ def address
74
+ {
75
+ line1: Faker::Address.street_address,
76
+ line2: Faker::Address.secondary_address,
77
+ city: 'London',
78
+ region: 'London',
79
+ areaCode: Faker::Address.zip_code,
80
+ country: 'UK'
81
+ }
82
+ end
83
+ end
84
+ end
85
+ end
@@ -2,24 +2,40 @@
2
2
 
3
3
  # Following the API description here: https://staging.youlendapi.com/prequalification/index.html
4
4
  module Youlend
5
- class Quote
6
- def self.pre_qualification(params)
7
- response = Youlend.connection.post('/prequalification/Requests', :prequalification, params)
5
+ class Prequalification
6
+ def self.verify(params)
7
+ new(params).verify
8
+ end
9
+
10
+ def initialize(params)
11
+ @params = params
12
+ end
13
+
14
+ def verify
15
+ response = Youlend.connection.post('/prequalification/Requests', :prequalification, @params)
16
+
17
+ # If there are errors in the data just return the response right away
18
+ return response if response.status == 422
8
19
 
9
20
  # If we got back a response but all the funded amounts are 0.0 it means that the load was
10
21
  # actually rejected! We'll replace the response body with an error message instead and change
11
22
  # the success code.
12
- if loan_accepted?(response.body)
13
- response
14
- else
23
+ unless loan_accepted?(response.body)
15
24
  response.http_response.env.status = 422
16
- response.http_response.env.body = { error: 'Rejected', error_description: 'Loan was rejected' }
17
- response
25
+ response.http_response.env.body = {
26
+ error: 'Rejected',
27
+ error_description: 'Loan was rejected'
28
+ }
18
29
  end
30
+
31
+ response
19
32
  end
20
33
 
21
- def self.loan_accepted?(data)
34
+ private
35
+
36
+ def loan_accepted?(data)
22
37
  return false unless data[:loanOptions]
38
+
23
39
  options = data[:loanOptions]
24
40
 
25
41
  funded_amounts = options.map { |option| option[:fundedAmount] }
@@ -24,5 +24,15 @@ module Youlend
24
24
 
25
25
  auth_header.match?(/.*token is expired.*/)
26
26
  end
27
+
28
+ def errors
29
+ return [] unless unauthorized? || token_expired?
30
+
31
+ @http_response.body
32
+ end
33
+
34
+ def data
35
+ @http_response.body
36
+ end
27
37
  end
28
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Youlend
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.3'
5
5
  end
@@ -163,7 +163,7 @@ http_interactions:
163
163
  body:
164
164
  encoding: UTF-8
165
165
  string: '{"thirdPartyMerchantId":"b97b0834-74e5-4da6-a3df-c8dbe017fe09","mid":null,"companyName":"Test
166
- company","overallCreditRiskScore":3.5,"overrideCreditRiskScore":1.0,"loanOptions":[{"fundedAmount":0.0,"fee":0.00,"loanAmount":0.00,"sweep":0.0,"currencyISOCode":"GBP"},{"fundedAmount":0.0,"fee":0.0,"loanAmount":0.0,"sweep":0.0,"currencyISOCode":"GBP"},{"fundedAmount":0.0,"fee":0.0,"loanAmount":0.0,"sweep":0.0,"currencyISOCode":"GBP"}]}'
166
+ company","overallCreditRiskScore":3.5,"overrideCreditRiskScore":1.0,"loanOptions":[{"fundedAmount":100.0,"fee":0.00,"loanAmount":0.00,"sweep":0.0,"currencyISOCode":"GBP"},{"fundedAmount":0.0,"fee":0.0,"loanAmount":0.0,"sweep":0.0,"currencyISOCode":"GBP"},{"fundedAmount":0.0,"fee":0.0,"loanAmount":0.0,"sweep":0.0,"currencyISOCode":"GBP"}]}'
167
167
  http_version:
168
168
  recorded_at: Tue, 02 Feb 2021 16:57:58 GMT
169
169
  recorded_with: VCR 5.0.0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: youlend
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - rikas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-03 00:00:00.000000000 Z
11
+ date: 2021-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -256,11 +256,10 @@ files:
256
256
  - lib/youlend/configuration.rb
257
257
  - lib/youlend/connection.rb
258
258
  - lib/youlend/lead.rb
259
- - lib/youlend/lead_generator.rb
260
- - lib/youlend/merchant.rb
261
- - lib/youlend/merchant_generator.rb
259
+ - lib/youlend/params_generators/lead.rb
260
+ - lib/youlend/params_generators/prequalification.rb
262
261
  - lib/youlend/path_sanitizer.rb
263
- - lib/youlend/quote.rb
262
+ - lib/youlend/prequalification.rb
264
263
  - lib/youlend/response.rb
265
264
  - lib/youlend/version.rb
266
265
  - vcr_cassettes/auth_incorrect.yml
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'faker'
4
-
5
- module Youlend
6
- class LeadGenerator
7
- def self.generate
8
- new.generate
9
- end
10
-
11
- def initialize
12
- Faker::Config.locale = 'en-GB'
13
-
14
- generate
15
- end
16
-
17
- # Mandatory fields:
18
- # * CompanyName
19
- # * CompanyType (ltd, plc, llp, dac, soleTrader, aps, as, ks, ivs and is)
20
- # * MonthsTrading
21
- # * CountryISOCode (GBR, DNK and IRE)
22
- # * KeyContactName
23
- # * ThirdPartyLeadId
24
- # * RegisteredAddress
25
- # * ContactPhoneNumber
26
- # * MonthlyCardRevenue (must be greater than or equal to '1000')
27
- # * ContactEmailAddress
28
- # * LoanCurrencyISOCode (ISO 4217 currency code. Valid codes are GBP, EUR and DKK)
29
- # * ThirdPartyCustomerId
30
- def generate
31
- {
32
- companyName: 'HOKO LTD',
33
- companyType: 'ltd',
34
- monthsTrading: rand(3..10),
35
- countryISOCode: 'GBR',
36
- keyContactName: Faker::Name.name,
37
- thirdPartyLeadId: SecureRandom.uuid,
38
- registeredAddress: address,
39
- contactPhoneNumber: Faker::PhoneNumber.phone_number,
40
- monthlyCardRevenue: 10_000,
41
- contactEmailAddress: Faker::Internet.email,
42
- loanCurrencyISOCode: 'GBP',
43
- thirdPartyCustomerId: SecureRandom.uuid,
44
- companyNumber: '09525857', # optional
45
- notificationURL: Faker::Internet.url, # optional
46
- thirdPartyMerchantId: SecureRandom.uuid # optional
47
- }
48
- end
49
-
50
- private
51
-
52
- def address
53
- {
54
- line1: Faker::Address.street_address,
55
- line2: Faker::Address.secondary_address,
56
- city: 'London',
57
- region: 'London',
58
- areaCode: Faker::Address.zip_code,
59
- country: 'UK'
60
- }
61
- end
62
- end
63
- end
File without changes
@@ -1,82 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'faker'
4
-
5
- module Youlend
6
- class MerchantGenerator
7
- def self.generate
8
- new.generate
9
- end
10
-
11
- def initialize
12
- Faker::Config.locale = 'en-GB'
13
-
14
- generate
15
- end
16
-
17
- # Mandatory fields:
18
- # * CompanyName
19
- # * CompanyType (ltd, plc, llp, dac, partnership, soleTrader, aps, as, ks, ivs and is)
20
- # * CompanyNumber
21
- # * FinancialData
22
- # * CountryISOCode (GBR, DNK and IRE)
23
- # * LoanCurrencyISOCode (ISO 4217 currency code. Valid codes are GBP, EUR and DKK)
24
- # * ThirdPartyMerchantId
25
- def generate
26
- {
27
- companyName: 'HOKO LTD',
28
- companyType: 'ltd',
29
- companyNumber: '09525857',
30
- financialData: financial_data,
31
- countryISOCode: 'GBR',
32
- loanCurrencyISOCode: 'GBP',
33
- thirdPartyMerchantId: SecureRandom.uuid,
34
- significantPersons: [significant_person], # optional
35
- contactEmailAddress: 'oterosantos@gmail.com' # optional
36
- }
37
- end
38
-
39
- private
40
-
41
- def financial_data
42
- {
43
- monthlyCardRevenue: 0,
44
- monthlyValueOfPurchaseTransactions: 0,
45
- monthlyRevenueFromInvoices: 0,
46
- paymentData: payment_data
47
- }
48
- end
49
-
50
- def payment_data
51
- (1..12).to_a.map do |month|
52
- formatted_month = format('%02<month>d', month: month)
53
-
54
- {
55
- paymentDate: "#{Date.today.year - 1}-#{formatted_month}-01",
56
- amount: 5000,
57
- currencyISOCode: 'GBP'
58
- }
59
- end
60
- end
61
-
62
- def significant_person
63
- {
64
- firstName: Faker::Name.first_name,
65
- surname: Faker::Name.last_name,
66
- address: address,
67
- dateOfBirth: Date.parse('1980-01-01').to_s
68
- }
69
- end
70
-
71
- def address
72
- {
73
- line1: Faker::Address.street_address,
74
- line2: Faker::Address.secondary_address,
75
- city: 'London',
76
- region: 'London',
77
- areaCode: Faker::Address.zip_code,
78
- country: 'UK'
79
- }
80
- end
81
- end
82
- end