youlend 1.0.0
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 +7 -0
- data/.gitignore +13 -0
- data/.rspec +4 -0
- data/.rubocop.yml +52 -0
- data/.ruby-version +1 -0
- data/.travis.yml +0 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +107 -0
- data/README.md +2 -0
- data/Rakefile +8 -0
- data/bin/console +27 -0
- data/lib/youlend.rb +24 -0
- data/lib/youlend/auth.rb +59 -0
- data/lib/youlend/configuration.rb +28 -0
- data/lib/youlend/connection.rb +69 -0
- data/lib/youlend/lead.rb +23 -0
- data/lib/youlend/lead_generator.rb +63 -0
- data/lib/youlend/merchant.rb +0 -0
- data/lib/youlend/merchant_generator.rb +82 -0
- data/lib/youlend/path_sanitizer.rb +13 -0
- data/lib/youlend/quote.rb +30 -0
- data/lib/youlend/response.rb +28 -0
- data/lib/youlend/version.rb +5 -0
- data/vcr_cassettes/auth_incorrect.yml +84 -0
- data/vcr_cassettes/auth_onboarding_correct.yml +86 -0
- data/vcr_cassettes/auth_prequalification_correct.yml +86 -0
- data/vcr_cassettes/lead_create_correct.yml +170 -0
- data/vcr_cassettes/lead_create_incorrect.yml +169 -0
- data/vcr_cassettes/pre_qualification_incomplete.yml +121 -0
- data/vcr_cassettes/prequalification_correct.yml +169 -0
- data/vcr_cassettes/prequalification_incorrect.yml +167 -0
- data/vcr_cassettes/prequalification_rejection.yml +164 -0
- data/youlend.gemspec +46 -0
- metadata +299 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2354061ae0d7285b3e71cdc4755a8d2f471d4ad0790baa4a1cb2656bbafdf796
|
4
|
+
data.tar.gz: d59850f7a58272e68184c0a27f6b22ad138648cfcadb3361256a3e3855dfb2d3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 506fdac262543c0e1350810ed47ba72f4b814329aaab06cfbc4adf4089bd943db26ba1af53e9418c6f7d7147548cc9397569949c57a3bfec807ec4d55772bd22
|
7
|
+
data.tar.gz: 8bca12acbdd170f27821f81499c3f254872c0b87d6c82f62ee05dda3af6c7fe26507d9e67dd0e2d6f6a87fd3509df64c9d7441bd54c72ca979c4947a4fba5aeb
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,52 @@
|
|
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
|
32
|
+
|
33
|
+
Layout/SpaceAroundMethodCallOperator:
|
34
|
+
Enabled: true
|
35
|
+
|
36
|
+
Lint/RaiseException:
|
37
|
+
Enabled: true
|
38
|
+
|
39
|
+
Lint/StructNewOverride:
|
40
|
+
Enabled: true
|
41
|
+
|
42
|
+
Style/ExponentialNotation:
|
43
|
+
Enabled: true
|
44
|
+
|
45
|
+
Style/HashEachMethods:
|
46
|
+
Enabled: true
|
47
|
+
|
48
|
+
Style/HashTransformKeys:
|
49
|
+
Enabled: true
|
50
|
+
|
51
|
+
Style/HashTransformValues:
|
52
|
+
Enabled: true
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.6
|
data/.travis.yml
ADDED
File without changes
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
youlend (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.3)
|
18
|
+
coderay (1.1.3)
|
19
|
+
concurrent-ruby (1.1.7)
|
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.11.0)
|
26
|
+
i18n (>= 1.6, < 2)
|
27
|
+
faraday (1.1.0)
|
28
|
+
multipart-post (>= 1.2, < 3)
|
29
|
+
ruby2_keywords
|
30
|
+
faraday_middleware (1.0.0)
|
31
|
+
faraday (~> 1.0)
|
32
|
+
hashdiff (1.0.1)
|
33
|
+
i18n (1.8.5)
|
34
|
+
concurrent-ruby (~> 1.0)
|
35
|
+
jaro_winkler (1.5.4)
|
36
|
+
method_source (1.0.0)
|
37
|
+
multi_json (1.15.0)
|
38
|
+
multipart-post (2.1.1)
|
39
|
+
parallel (1.19.1)
|
40
|
+
parser (2.7.1.2)
|
41
|
+
ast (~> 2.4.0)
|
42
|
+
pry (0.13.1)
|
43
|
+
coderay (~> 1.1)
|
44
|
+
method_source (~> 1.0)
|
45
|
+
pry-byebug (3.9.0)
|
46
|
+
byebug (~> 11.0)
|
47
|
+
pry (~> 0.13.0)
|
48
|
+
public_suffix (4.0.5)
|
49
|
+
rainbow (3.0.0)
|
50
|
+
rake (10.5.0)
|
51
|
+
rexml (3.2.4)
|
52
|
+
rspec (3.9.0)
|
53
|
+
rspec-core (~> 3.9.0)
|
54
|
+
rspec-expectations (~> 3.9.0)
|
55
|
+
rspec-mocks (~> 3.9.0)
|
56
|
+
rspec-core (3.9.2)
|
57
|
+
rspec-support (~> 3.9.3)
|
58
|
+
rspec-expectations (3.9.2)
|
59
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
60
|
+
rspec-support (~> 3.9.0)
|
61
|
+
rspec-mocks (3.9.1)
|
62
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
63
|
+
rspec-support (~> 3.9.0)
|
64
|
+
rspec-support (3.9.3)
|
65
|
+
rubocop (0.82.0)
|
66
|
+
jaro_winkler (~> 1.5.1)
|
67
|
+
parallel (~> 1.10)
|
68
|
+
parser (>= 2.7.0.1)
|
69
|
+
rainbow (>= 2.2.2, < 4.0)
|
70
|
+
rexml
|
71
|
+
ruby-progressbar (~> 1.7)
|
72
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
73
|
+
rubocop-rspec (1.39.0)
|
74
|
+
rubocop (>= 0.68.1)
|
75
|
+
ruby-progressbar (1.10.1)
|
76
|
+
ruby2_keywords (0.0.2)
|
77
|
+
safe_yaml (1.0.5)
|
78
|
+
simplecov (0.18.5)
|
79
|
+
docile (~> 1.1)
|
80
|
+
simplecov-html (~> 0.11)
|
81
|
+
simplecov-html (0.12.2)
|
82
|
+
unicode-display_width (1.7.0)
|
83
|
+
vcr (5.0.0)
|
84
|
+
webmock (3.8.3)
|
85
|
+
addressable (>= 2.3.6)
|
86
|
+
crack (>= 0.3.2)
|
87
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
88
|
+
|
89
|
+
PLATFORMS
|
90
|
+
ruby
|
91
|
+
|
92
|
+
DEPENDENCIES
|
93
|
+
bundler
|
94
|
+
dotenv
|
95
|
+
faker
|
96
|
+
pry-byebug
|
97
|
+
rake (~> 10.0)
|
98
|
+
rspec (~> 3.0)
|
99
|
+
rubocop
|
100
|
+
rubocop-rspec
|
101
|
+
simplecov
|
102
|
+
vcr
|
103
|
+
webmock
|
104
|
+
youlend!
|
105
|
+
|
106
|
+
BUNDLED WITH
|
107
|
+
2.1.4
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'youlend'
|
6
|
+
require 'youlend/merchant_generator'
|
7
|
+
require 'youlend/lead_generator'
|
8
|
+
|
9
|
+
require 'dotenv'
|
10
|
+
Dotenv.load
|
11
|
+
|
12
|
+
Youlend.configure do |config|
|
13
|
+
config.client_id = ENV['YOULEND_CLIENT_ID']
|
14
|
+
config.client_secret = ENV['YOULEND_CLIENT_SECRET']
|
15
|
+
config.debug = true
|
16
|
+
end
|
17
|
+
|
18
|
+
def generate_merchant
|
19
|
+
Youlend::MerchantGenerator.generate
|
20
|
+
end
|
21
|
+
|
22
|
+
def generate_lead
|
23
|
+
Youlend::LeadGenerator.generate
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'pry'
|
27
|
+
Pry.start
|
data/lib/youlend.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'youlend/version'
|
4
|
+
require 'youlend/auth'
|
5
|
+
require 'youlend/configuration'
|
6
|
+
require 'youlend/connection'
|
7
|
+
require 'youlend/quote'
|
8
|
+
require 'youlend/lead'
|
9
|
+
|
10
|
+
module Youlend
|
11
|
+
module_function
|
12
|
+
|
13
|
+
def configuration
|
14
|
+
@configuration ||= Configuration.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def connection
|
18
|
+
@connection ||= Connection.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def configure
|
22
|
+
yield(configuration)
|
23
|
+
end
|
24
|
+
end
|
data/lib/youlend/auth.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'multi_json'
|
4
|
+
require 'faraday'
|
5
|
+
require 'faraday_middleware'
|
6
|
+
require 'addressable'
|
7
|
+
|
8
|
+
module Youlend
|
9
|
+
class Auth
|
10
|
+
extend Forwardable
|
11
|
+
|
12
|
+
AUTH_URL = 'https://youlend-stag.eu.auth0.com'
|
13
|
+
|
14
|
+
AUDIENCES = %i[prequalification onboarding].freeze
|
15
|
+
DEFAULT_AUDIENCE = :prequalification
|
16
|
+
|
17
|
+
def_delegators :@configuration, :client_id, :client_secret
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@configuration = Youlend.configuration
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.request_token(audience = DEFAULT_AUDIENCE)
|
24
|
+
new.request_token(audience)
|
25
|
+
end
|
26
|
+
|
27
|
+
def request_token(audience = DEFAULT_AUDIENCE)
|
28
|
+
raise 'Invalid Audience' unless AUDIENCES.include?(audience.to_sym)
|
29
|
+
|
30
|
+
params = {
|
31
|
+
grant_type: 'client_credentials',
|
32
|
+
client_id: client_id,
|
33
|
+
client_secret: client_secret,
|
34
|
+
audience: "#{Youlend.configuration.api_domain}/#{audience}"
|
35
|
+
}
|
36
|
+
|
37
|
+
result = adapter.post('/oauth/token', params.to_json)
|
38
|
+
|
39
|
+
json = result.body
|
40
|
+
|
41
|
+
raise json[:error_description] if json[:error]
|
42
|
+
|
43
|
+
@configuration.tokens[audience] = json[:access_token] unless json[:error]
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def adapter
|
49
|
+
Faraday.new(url: AUTH_URL) do |conn|
|
50
|
+
conn.headers['Content-Type'] = 'application/json'
|
51
|
+
conn.headers['User-Agent'] = "ruby-youlend-#{VERSION}"
|
52
|
+
conn.use FaradayMiddleware::ParseJson
|
53
|
+
conn.response :json, parser_options: { symbolize_names: true }
|
54
|
+
conn.response :logger if Youlend.configuration.debug?
|
55
|
+
conn.adapter Faraday.default_adapter
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Youlend
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :tokens, :client_id, :client_secret, :env
|
6
|
+
attr_writer :debug
|
7
|
+
|
8
|
+
API_DOMAINS = {
|
9
|
+
production: '',
|
10
|
+
development: 'https://staging.youlendapi.com'
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@tokens = { onboarding: '', prequalification: '' }
|
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,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'faraday_middleware'
|
5
|
+
require 'rainbow'
|
6
|
+
require 'addressable'
|
7
|
+
|
8
|
+
require 'youlend/path_sanitizer'
|
9
|
+
require 'youlend/response'
|
10
|
+
|
11
|
+
module Youlend
|
12
|
+
class Connection
|
13
|
+
BASE_PATH = '/'
|
14
|
+
|
15
|
+
def with_token_refresh(audience)
|
16
|
+
http_response = yield
|
17
|
+
|
18
|
+
response = Response.new(http_response)
|
19
|
+
|
20
|
+
# Try to get a valid token if the token has expired. This will also update the gem config
|
21
|
+
# so we won't need to request the token again.
|
22
|
+
if response.token_expired? || response.unauthorized?
|
23
|
+
log "Refreshing outdated token... #{Youlend.configuration.tokens[audience]}"
|
24
|
+
|
25
|
+
Auth.request_token(audience)
|
26
|
+
|
27
|
+
http_response = yield
|
28
|
+
end
|
29
|
+
|
30
|
+
http_response
|
31
|
+
end
|
32
|
+
|
33
|
+
def post(path, audience, params = {})
|
34
|
+
log "POST: #{params.inspect}"
|
35
|
+
|
36
|
+
http_response = with_token_refresh(audience) do
|
37
|
+
adapter(audience).post(PathSanitizer.sanitize(path), params.to_json)
|
38
|
+
end
|
39
|
+
|
40
|
+
Response.new(http_response)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def log(text)
|
46
|
+
return unless Youlend.configuration.debug?
|
47
|
+
|
48
|
+
puts Rainbow("[Youlend] #{text}").magenta.bright
|
49
|
+
end
|
50
|
+
|
51
|
+
def base_url
|
52
|
+
Addressable::URI.join(Youlend.configuration.api_domain, BASE_PATH).to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
def adapter(audience)
|
56
|
+
token = Youlend.configuration.tokens[audience]
|
57
|
+
|
58
|
+
Faraday.new(url: base_url) do |conn|
|
59
|
+
conn.headers['Authorization'] = "Bearer #{token}" unless token.to_s.empty?
|
60
|
+
conn.headers['Content-Type'] = 'application/json'
|
61
|
+
conn.headers['User-Agent'] = "ruby-youlend-#{VERSION}"
|
62
|
+
conn.use FaradayMiddleware::ParseJson
|
63
|
+
conn.response :json, parser_options: { symbolize_names: true }
|
64
|
+
conn.response :logger if Youlend.configuration.debug?
|
65
|
+
conn.adapter Faraday.default_adapter
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/youlend/lead.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Following the API description here: https://staging.youlend.com/developer/main/onboardingdoc
|
4
|
+
module Youlend
|
5
|
+
class Lead
|
6
|
+
def initialize(params)
|
7
|
+
@id = nil
|
8
|
+
@params = params
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
Youlend.connection.post('/onboarding/Leads', :onboarding, @params)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.create(params)
|
16
|
+
new(params).create
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.details(lead_id)
|
20
|
+
Youlend.connection.get("/onboarding/Leads/#{lead_id}/details", :onboarding)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|