lenddo 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 +2 -0
- data/.travis.yml +13 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +9 -0
- data/README.md +137 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cacert.pem +4066 -0
- data/lenddo.gemspec +28 -0
- data/lib/lenddo.rb +21 -0
- data/lib/lenddo/authentication.rb +53 -0
- data/lib/lenddo/configuration.rb +12 -0
- data/lib/lenddo/exception.rb +7 -0
- data/lib/lenddo/service_client.rb +33 -0
- data/lib/lenddo/service_client/score_service.rb +35 -0
- data/lib/lenddo/version.rb +5 -0
- data/lib/lenddo/white_label_client.rb +62 -0
- data/lib/lenddo/white_label_client/network_service.rb +37 -0
- metadata +133 -0
data/lenddo.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lenddo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lenddo"
|
8
|
+
spec.version = Lenddo.version
|
9
|
+
spec.authors = ["arjay salvadora"]
|
10
|
+
spec.email = ["arjay@lenddo.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Lenddo's REST based services}
|
13
|
+
spec.homepage = "https://www.lenddo.com"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
24
|
+
spec.add_development_dependency "curb", "~> 0.9"
|
25
|
+
spec.add_development_dependency "json", "~> 1.8"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
end
|
data/lib/lenddo.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "lenddo/configuration"
|
2
|
+
require "lenddo/exception"
|
3
|
+
require "lenddo/version"
|
4
|
+
|
5
|
+
module Lenddo
|
6
|
+
class << self
|
7
|
+
attr_accessor :configuration
|
8
|
+
|
9
|
+
def configuration
|
10
|
+
@configuration ||= Configuration.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def reset
|
14
|
+
@configuration = Configuration.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def configure
|
18
|
+
yield(configuration) if block_given?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'curb'
|
3
|
+
require 'json'
|
4
|
+
require 'openssl'
|
5
|
+
|
6
|
+
module Lenddo
|
7
|
+
module Authentication
|
8
|
+
def signed_request(method, host, path, params={})
|
9
|
+
uri = URI.parse(host + path)
|
10
|
+
|
11
|
+
method = method.downcase
|
12
|
+
if (method == 'post' || method == 'put')
|
13
|
+
body = params
|
14
|
+
else
|
15
|
+
body = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
Curl.send(method.to_s, uri.to_s, params) do |http|
|
19
|
+
headers = sign(method.upcase, path, body)
|
20
|
+
headers.each do |key, value|
|
21
|
+
http.headers[key] = value.chomp
|
22
|
+
end
|
23
|
+
|
24
|
+
http.use_ssl = 3
|
25
|
+
http.ssl_verify_host = OpenSSL::SSL::VERIFY_PEER
|
26
|
+
http.cacert = File.absolute_path("./cacert.pem") if RbConfig::CONFIG['host_os'] == 'mingw32'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def sign(verb, path, body, ts = nil)
|
32
|
+
date_format = "%a %b %d %H:%M:%S %Z %Y"
|
33
|
+
digest = body.empty? ? "" : Digest::MD5.hexdigest(URI.encode_www_form(body))
|
34
|
+
timestamp = ts.nil? ? Time.now : Time.parse(ts, date_format)
|
35
|
+
date = timestamp.strftime(date_format)
|
36
|
+
text = [verb, digest, date, path].join("\n")
|
37
|
+
{
|
38
|
+
'Authorization' => auth_string(text),
|
39
|
+
'Content-Type' => 'application/json',
|
40
|
+
'Date' => date
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def auth_string(text)
|
45
|
+
hash = Base64.encode64(sha1_hmac(Lenddo.configuration.secret_key, text))
|
46
|
+
"LENDDO #{Lenddo.configuration.access_key}:#{hash}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def sha1_hmac(key, value)
|
50
|
+
OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), key, value)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Lenddo
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :access_key, :secret_key, :score_service, :network_service
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@access_key = nil
|
7
|
+
@secret_key = nil
|
8
|
+
@score_service = "https://scoreservice.lenddo.com"
|
9
|
+
@network_service = "https://networkservice.lenddo.com"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "lenddo/authentication"
|
2
|
+
require "lenddo/service_client/score_service"
|
3
|
+
|
4
|
+
include Lenddo::Authentication
|
5
|
+
|
6
|
+
module Lenddo
|
7
|
+
module ServiceClient
|
8
|
+
class << self
|
9
|
+
attr_accessor :score_service
|
10
|
+
# Calls the Lenddo Service with the provided application_id to return a application score result.
|
11
|
+
# @param string application_id
|
12
|
+
# @param string partner_script_id
|
13
|
+
def application_score(application_id, partnerscript_id)
|
14
|
+
@score_service ||= ScoreService.new
|
15
|
+
@score_service.application_score(application_id, partnerscript_id)
|
16
|
+
end
|
17
|
+
# Calls the Lenddo Service with the provided application id to return a application verification result.
|
18
|
+
# @param string application_id
|
19
|
+
# @param string partner_script_id
|
20
|
+
def application_verification(application_id, partnerscript_id)
|
21
|
+
@score_service ||= ScoreService.new
|
22
|
+
@score_service.application_verification(application_id, partnerscript_id)
|
23
|
+
end
|
24
|
+
# Calls the Lenddo Service with the provided application id to return a application decision result.
|
25
|
+
# @param string application_id
|
26
|
+
# @param string partner_script_id
|
27
|
+
def application_decision(application_id, partnerscript_id)
|
28
|
+
@score_service ||= ScoreService.new
|
29
|
+
@score_service.application_decision(application_id, partnerscript_id)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Lenddo
|
2
|
+
module ServiceClient
|
3
|
+
class ScoreService
|
4
|
+
def application_score(application_id, partnerscript_id)
|
5
|
+
response = signed_request(
|
6
|
+
"GET",
|
7
|
+
Lenddo.configuration.score_service,
|
8
|
+
"/ClientScore/#{application_id}",
|
9
|
+
{ "partner_script_id" => partnerscript_id }
|
10
|
+
)
|
11
|
+
JSON.parse(response.body)
|
12
|
+
end
|
13
|
+
|
14
|
+
def application_verification(application_id, partnerscript_id)
|
15
|
+
response = signed_request(
|
16
|
+
"GET",
|
17
|
+
Lenddo.configuration.score_service,
|
18
|
+
"/ClientVerification/#{application_id}",
|
19
|
+
{ "partner_script_id" => partnerscript_id }
|
20
|
+
)
|
21
|
+
JSON.parse(response.body)
|
22
|
+
end
|
23
|
+
|
24
|
+
def application_decision(application_id, partnerscript_id)
|
25
|
+
response = signed_request(
|
26
|
+
"GET",
|
27
|
+
Lenddo.configuration.score_service,
|
28
|
+
"/ApplicationDecision/#{application_id}",
|
29
|
+
{ "partner_script_id" => partnerscript_id}
|
30
|
+
)
|
31
|
+
JSON.parse(response.body)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "lenddo/authentication"
|
2
|
+
require "lenddo/white_label_client/network_service"
|
3
|
+
|
4
|
+
include Lenddo::Authentication
|
5
|
+
|
6
|
+
module Lenddo
|
7
|
+
module WhiteLabelClient
|
8
|
+
class << self
|
9
|
+
attr_accessor :network_service
|
10
|
+
# Submit additional data about an application to Lenddo.
|
11
|
+
# @param string application_id
|
12
|
+
# @param string partner_script_id
|
13
|
+
# @param array extra_data
|
14
|
+
def extra_application_data(application_id, partnerscript_id, extra_data = {})
|
15
|
+
@network_service ||= NetworkService.new
|
16
|
+
|
17
|
+
if extra_data.class != Hash
|
18
|
+
raise ArgumentError.new("@extra_data must be a Hash.")
|
19
|
+
else
|
20
|
+
@network_service.extra_application_data(application_id, partnerscript_id, extra_data)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
# Posting network tokens, if successful, returns a "Profile ID" which is used when submitting a client for scoring.
|
24
|
+
# @param string application_id
|
25
|
+
# @param string provider
|
26
|
+
# @param hash token_data
|
27
|
+
# @param string oauth_key
|
28
|
+
# @param string oauth_secret (optional)
|
29
|
+
def partner_token(application_id, provider, token_data, oauth_key, oauth_secret = nil)
|
30
|
+
@network_service ||= NetworkService.new
|
31
|
+
|
32
|
+
if !valid_token_providers.include?(provider)
|
33
|
+
raise ArgumentError.new("@provider must be one of the following: #{valid_token_providers.join(", ")}")
|
34
|
+
else
|
35
|
+
@network_service.partner_token(application_id, provider, token_data, oauth_key, oauth_secret)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
# Submit an application with profile ids for scoring to Lenddo.
|
39
|
+
# To perform this step you must have an array of at least one profile id obtained from the PartnerToken call.
|
40
|
+
# @param string partner_script_id
|
41
|
+
# @param string application_id
|
42
|
+
# @param array profile_ids
|
43
|
+
# @param verification - Optional
|
44
|
+
def commit_partner_job(partnerscript_id, application_id, profile_ids, verification = nil)
|
45
|
+
@network_service ||= NetworkService.new
|
46
|
+
|
47
|
+
if profile_ids.empty?
|
48
|
+
raise ArgumentError.new("@profile_ids must contain at least one entry.")
|
49
|
+
elsif profile_ids.class != Array
|
50
|
+
raise ArgumentError.new("@profile_ids must be an array.")
|
51
|
+
else
|
52
|
+
@network_service.commit_partner_job(partnerscript_id, application_id, profile_ids, verification)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
def valid_token_providers
|
58
|
+
['Facebook', 'LinkedIn', 'Yahoo', 'WindowsLive', 'Google']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Lenddo
|
2
|
+
module WhiteLabelClient
|
3
|
+
class NetworkService
|
4
|
+
def extra_application_data(application_id, partnerscript_id, extra_data)
|
5
|
+
response = signed_request(
|
6
|
+
"POST",
|
7
|
+
Lenddo.configuration.network_service,
|
8
|
+
"/ExtraApplicationData",
|
9
|
+
{ "application_id" => application_id, "partner_script_id" => partnerscript_id, "extra_data" => extra_data }
|
10
|
+
)
|
11
|
+
JSON.parse(response.body)
|
12
|
+
end
|
13
|
+
|
14
|
+
def partner_token(application_id, provider, token_data, oauth_key, oauth_secret)
|
15
|
+
body = { "token_data" => { "key" => oauth_key, "secret" => oauth_secret }, "provider" => provider, "client_id" => application_id }
|
16
|
+
body['token_data'].merge!(token_data)
|
17
|
+
response = signed_request(
|
18
|
+
"POST",
|
19
|
+
Lenddo.configuration.network_service,
|
20
|
+
"/PartnerToken",
|
21
|
+
body
|
22
|
+
)
|
23
|
+
JSON.parse(response.body)
|
24
|
+
end
|
25
|
+
|
26
|
+
def commit_partner_job(partnerscript_id, application_id, profile_ids, verification)
|
27
|
+
response = signed_request(
|
28
|
+
"POST",
|
29
|
+
Lenddo.configuration.network_service,
|
30
|
+
"/CommitPartnerJob",
|
31
|
+
{ "client_id" => application_id, "profile_ids" => profile_ids, "partner_script_id" => partnerscript_id, "verification_data" => verification}
|
32
|
+
)
|
33
|
+
JSON.parse(response.body)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lenddo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- arjay salvadora
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: curb
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- arjay@lenddo.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- cacert.pem
|
100
|
+
- lenddo.gemspec
|
101
|
+
- lib/lenddo.rb
|
102
|
+
- lib/lenddo/authentication.rb
|
103
|
+
- lib/lenddo/configuration.rb
|
104
|
+
- lib/lenddo/exception.rb
|
105
|
+
- lib/lenddo/service_client.rb
|
106
|
+
- lib/lenddo/service_client/score_service.rb
|
107
|
+
- lib/lenddo/version.rb
|
108
|
+
- lib/lenddo/white_label_client.rb
|
109
|
+
- lib/lenddo/white_label_client/network_service.rb
|
110
|
+
homepage: https://www.lenddo.com
|
111
|
+
licenses: []
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.6.7
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Lenddo's REST based services
|
133
|
+
test_files: []
|