greensky 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e6bc47112621a3a1879dbf82d30d6325ec3b0f4c
4
+ data.tar.gz: cb51fa6ce128bec702cf81202886c9a0ce46bf2f
5
+ SHA512:
6
+ metadata.gz: 0ab914bafa04edc0a9f3188a96204468c04cf9589ef67e7e830fdb8c874d1935ad7c0e5dae855f82c3ebe25c7d80da2cefae63a79fd31f93f72a8ea93e3586f8
7
+ data.tar.gz: 67ef847bc3248348f89b1b95cf8990261e2526bc6050faccce5ee380146c697fd8ad6aa2b5448f4221f9c731c081f7d79b1f78d70e92c48670210c72460ade47
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.lgtm ADDED
@@ -0,0 +1,2 @@
1
+ approvals = 1
2
+ pattern = "(?i):shipit:|:\\+1:|LGTM"
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in greensky.gemspec
4
+ gemspec
@@ -0,0 +1,12 @@
1
+ Wade Winningham <wwinningham@powerhrg.com> (@wadewinningham)
2
+ Ben Langfeld <benlangfeld@powerhrg.com> (@benlangfeld)
3
+ Ben Klang <bklang@powerhrg.com> (@bklang)
4
+ Gerald Abrencillo <gerald.abrencillo@powerhrg.com> (@gerald)
5
+ Jim Hughes <jim.hughes@powerhrg.com> (@jeem)
6
+ John Rose <john.rose@powerhrg.com> (@booty)
7
+ Jeremy Bower <jeremy.bower@powerhrg.com> (@jeremybower)
8
+ Neil Decapia <neil.decapia@powerhrg.com> (@neildecapia)
9
+ Rafael Garcia <rafael.garcia@powerhrg.com> (@rafbgarcia)
10
+ Harry Levine <harry.levine@powerhrg.com> (@hpjaj)
11
+ Diego Borges <diego.borges@powerhrg.com> (@drborges)
12
+ Carlos Palhares <carlos.palhares@powerhrg.com> (@xjunior)
@@ -0,0 +1,39 @@
1
+ # Greensky
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/greensky`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'greensky'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install greensky
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/greensky/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "greensky"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'greensky/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "greensky"
8
+ spec.version = Greensky::VERSION
9
+ spec.authors = ["Carlos Palhares"]
10
+ spec.email = ["carlos.palhares@powerhrg.com"]
11
+
12
+ spec.summary = %q{GreenSky RESTful API integration.}
13
+ spec.homepage = "https://github.com/powerhrg/greensky"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "rest-client", "~> 1.8.0"
21
+ spec.add_dependency "virtus", "~> 1.0.5"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.9"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.4.0"
26
+ end
@@ -0,0 +1,100 @@
1
+ require 'rest-client'
2
+ require 'ostruct'
3
+ require 'greensky/version'
4
+ require 'greensky/client'
5
+ require 'greensky/document_downloader'
6
+ require 'greensky/error'
7
+ require 'greensky/long_application'
8
+
9
+ module Greensky
10
+ def self.config
11
+ @@config ||= OpenStruct.new({role: 'merchant'})
12
+ end
13
+
14
+ def self.client
15
+ Client.new(config)
16
+ end
17
+
18
+ def self.download_document(application, &block)
19
+ DocumentDownloader.new(config, application).execute(&block)
20
+ end
21
+
22
+ def self.list
23
+ client.get 'list', {channel: config.channel}
24
+ end
25
+
26
+ def self.state(application)
27
+ data = {
28
+ channel: application.channel,
29
+ program: application.program,
30
+ product: application.product,
31
+ applicationId: application.applicationId
32
+ }
33
+ client.get 'state', data, {token: application.token}
34
+ end
35
+
36
+ def self.offers(application)
37
+ data = {
38
+ channel: application.channel,
39
+ program: application.program,
40
+ product: application.product,
41
+ applicationId: application.applicationId,
42
+ role: application.role
43
+ }
44
+ client.get 'offer', data, {token: application.token}
45
+ end
46
+
47
+ def self.agreement(application)
48
+ data = {
49
+ role: application.role,
50
+ channel: application.channel,
51
+ program: application.program,
52
+ product: application.product,
53
+ applicationId: application.applicationId
54
+ }
55
+ client.get 'loanagreement', data, {token: application.token}
56
+ end
57
+
58
+ def self.create(application, offer_id)
59
+ result = client.post('create', {
60
+ offerId: offer_id,
61
+ role: application.role,
62
+ channel: application.channel,
63
+ program: application.program,
64
+ product: application.product,
65
+ applicationId: application.applicationId
66
+ }, {token: application.token})
67
+ result.fetch('status')
68
+ end
69
+
70
+ def self.merchant_validation(application)
71
+ client.get 'merchantvalidation', {
72
+ dealer: application.merchantNumber,
73
+ role: application.role,
74
+ program: application.program,
75
+ product: application.product,
76
+ channel: application.channel,
77
+ plan: application.plan
78
+ }
79
+ end
80
+
81
+ def self.submit_async(application)
82
+ validation = merchant_validation(application)
83
+ token_header = {token: validation['token']}
84
+ data = application.attributes
85
+ client.post 'asynchronoussubmit', data, token_header
86
+ end
87
+
88
+ def self.recalculate_offer(application)
89
+ data = {
90
+ program: application.program,
91
+ product: application.product,
92
+ role: application.role,
93
+ applicationId: application.applicationId,
94
+ loanAmount: application.requestedLoanAmount,
95
+ plan: application.plan,
96
+ }
97
+
98
+ client.post 'recalculateoffer', data, token: application.token
99
+ end
100
+ end
@@ -0,0 +1,32 @@
1
+ module Greensky
2
+ class Client
3
+ def initialize(config)
4
+ @config = config
5
+ @resource = RestClient::Resource.new(config.endpoint, {
6
+ headers: {content_type: :json, accept: :json},
7
+ user: config.username, password: config.password
8
+ })
9
+ end
10
+
11
+ def get(path, data={}, headers={})
12
+ process_response services[path].get(headers.merge(params: data))
13
+ end
14
+
15
+ def post(path, data={}, headers={})
16
+ params = data.to_json
17
+ process_response services[path].post(params, headers)
18
+ end
19
+
20
+ private
21
+
22
+ def services
23
+ @resource['/services']
24
+ end
25
+
26
+ def process_response(body)
27
+ response = JSON.parse(body)
28
+ raise Error, response['error'] if response['error']
29
+ response
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ module Greensky
2
+ class DocumentDownloader < RestClient::Request
3
+ def initialize(config, application)
4
+ params = {
5
+ x: application.applicationId,
6
+ q: application.token,
7
+ clientip: config.outbound_ip,
8
+ channel: config.channel
9
+ }
10
+
11
+ super({
12
+ method: :post,
13
+ url: "#{config.endpoint}/ViewDoc",
14
+ payload: params,
15
+ user: config.username,
16
+ password: config.password
17
+ })
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ module Greensky
2
+ class Error < StandardError
3
+ def initialize(response={})
4
+ @response = response
5
+ super @response['message']
6
+ end
7
+
8
+ def code
9
+ @response['code']
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,126 @@
1
+ require 'virtus'
2
+
3
+ module Greensky
4
+ class ConfigurableDefault < Struct.new(:config_key)
5
+ def call(_, attribute)
6
+ Greensky.config[config_key || attribute.name]
7
+ end
8
+ end
9
+
10
+ class LongApplication
11
+ include Virtus.model
12
+
13
+ attribute :applicantFirstName, String
14
+ attribute :applicantMiddleInitial, String
15
+ attribute :applicantLastName, String
16
+ attribute :applicantDateOfBirth, Date
17
+ attribute :applicantMarried, Boolean
18
+ attribute :applicantPhoneNumber, String
19
+ attribute :applicantCellPhoneNumber, String
20
+ attribute :applicantEmailAddress, String
21
+ attribute :applicantStreetNumber, String
22
+ attribute :applicantStreetAddress, String
23
+ attribute :applicantCity, String
24
+ attribute :applicantState, String
25
+ attribute :applicantZipCode, String
26
+ attribute :applicantZipCode4, String
27
+ attribute :applicantOtherAddress, String
28
+ attribute :applicantEmployerName, String
29
+ attribute :applicantYearsOnJob, Integer
30
+ attribute :applicantEmployerPhoneNumber, String
31
+ attribute :applicantSSN, String
32
+ attribute :applicantGrossIncome, Float
33
+ attribute :applicantOtherIncome, Float
34
+ attribute :applicantIDNumber, String
35
+ attribute :applicantNameOnId, String
36
+ attribute :applicantIDExpiryDate, Date
37
+ attribute :applicantTypeOfID, String
38
+ attribute :applicantStateOnID, String
39
+
40
+ attribute :coApplicantFirstName, String
41
+ attribute :coApplicantMiddleInitial, String
42
+ attribute :coApplicantLastName, String
43
+ attribute :coApplicantDateOfBirth, Date
44
+ attribute :coApplicantSSN, String
45
+ attribute :coApplicantPhoneNumber, String
46
+ attribute :coApplicantCellPhoneNumber, String
47
+ attribute :coApplicantEmailAddress, String
48
+ attribute :coApplicantStreetNumber, String
49
+ attribute :coApplicantStreetAddress, String
50
+ attribute :coApplicantCity, String
51
+ attribute :coApplicantState, String
52
+ attribute :coApplicantZipCode, String
53
+ attribute :coApplicantZipCode4, String
54
+ attribute :coApplicantOtherAddress, String
55
+ attribute :coApplicantEmployerName, String
56
+ attribute :coApplicantYearsOnJob, String
57
+ attribute :coApplicantEmployerPhoneNumber, String
58
+ attribute :coApplicantGrossIncome, String
59
+ attribute :coApplicantStateOnID, String
60
+
61
+ attribute :channel, String, default: ConfigurableDefault.new
62
+ attribute :program, String, default: ConfigurableDefault.new
63
+ attribute :product, String, default: ConfigurableDefault.new
64
+ attribute :merchantNumber, String, default: ConfigurableDefault.new(:merchant_id)
65
+ attribute :role, String, default: ConfigurableDefault.new
66
+ attribute :plan, String
67
+ attribute :referral, String#, default: :default_referral
68
+ attribute :requestedLoanAmount, Float
69
+ attribute :contractLanguage, String
70
+ attribute :coApplicantIndicator, Boolean
71
+
72
+ attribute :applicationId, String
73
+ attribute :token, String
74
+
75
+ # Greensky::LongApplication # as_json
76
+ def as_json(*args)
77
+ attributes.merge({
78
+ applicantDateOfBirth: format_date_json(applicantDateOfBirth),
79
+ coApplicantDateOfBirth: format_date_json(coApplicantDateOfBirth)
80
+ })
81
+ end
82
+
83
+ def submit!
84
+ self.attributes = Greensky.submit_async(self)
85
+ end
86
+
87
+ def recalculate_offer
88
+ Greensky.recalculate_offer(self)
89
+ end
90
+
91
+ def offers
92
+ Greensky.offers(self)
93
+ end
94
+
95
+ def state
96
+ Greensky.state(self)
97
+ end
98
+
99
+ def agreement
100
+ Greensky.agreement(self)
101
+ end
102
+
103
+ def accept!(offer_id)
104
+ Greensky.create(self, offer_id)
105
+ end
106
+
107
+ def download_document(&block)
108
+ Greensky.download_document(self, &block)
109
+ end
110
+
111
+ def application_status
112
+ state['applicationStatus']
113
+ end
114
+
115
+ def referral
116
+ super || ('%s-%s' % [merchantNumber, plan])
117
+ end
118
+
119
+ private
120
+
121
+ def format_date_json(date)
122
+ return unless date
123
+ date.strftime('%m/%d/%Y')
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,3 @@
1
+ module Greensky
2
+ VERSION = "1.9.1"
3
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: greensky
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.9.1
5
+ platform: ruby
6
+ authors:
7
+ - Carlos Palhares
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: virtus
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.9'
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.4.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.4.0
83
+ description:
84
+ email:
85
+ - carlos.palhares@powerhrg.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".lgtm"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - MAINTAINERS
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - greensky.gemspec
101
+ - lib/greensky.rb
102
+ - lib/greensky/client.rb
103
+ - lib/greensky/document_downloader.rb
104
+ - lib/greensky/error.rb
105
+ - lib/greensky/long_application.rb
106
+ - lib/greensky/version.rb
107
+ homepage: https://github.com/powerhrg/greensky
108
+ licenses: []
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.8
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: GreenSky RESTful API integration.
130
+ test_files: []