weimark 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0ce727d48d9d434f8bed7e4567371e40e7fa18c621c9e45f7a80540fccf9cc03
4
+ data.tar.gz: 0ae57e005882d4dbe3bc38eaaf9e617aaff19b3688fb2cc64db651da18abc0de
5
+ SHA512:
6
+ metadata.gz: 46a60ee69a4480a3bcf8be0de35f4b75a7400735585e524cd12dec7255d3c44cb5d58703b4d2e1e8fccb981704a5d321abc9659eef8b10dab848617ace5d15f7
7
+ data.tar.gz: 52ee2a3899fd4bccbd91e84b2f8edcb1ce942e7a49f1182e8e60f8a9b0d60d11c0e6a5e4f1416c30b61e7f43bac0c782f16df457a66c3bd7fd1aec7a0819c705
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 1.17.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in weimark.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 David Rozenberg
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,57 @@
1
+ # Weimark
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/weimark`. 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 'weimark'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install weimark
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ require 'weimark'
27
+
28
+ # Replace email, password, and agents_email (optional) with your own credentials
29
+ @client = Weimark::Client.new(email: 'david@example.com', password: '1234567890')
30
+
31
+ # Or default to ENV variables set in your application
32
+ ENV['WEIMARK_EMAIL'] = 'david@example.com'
33
+ ENV['WEIMARK_PASSWORD'] = '1234567890'
34
+ ENV['AGENTS_EMAIL'] = 'david@example.com'
35
+
36
+ @client = Weimark::Client.new
37
+
38
+ # Get an application by application ID
39
+ @client.get('987654321')
40
+
41
+ # Create a new application
42
+ @client.post({fname: 'JONATHAN', lname: 'CONSUMER', dob: '01/05/1987', gender: 'male', ssn: '485774859', streetnumber: '236', streetname: 'BIRCH', streettype: 'S', city: 'BURBANK', country: 'USA', suite: '1TEST', zip: '91502'})
43
+ ```
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
48
+
49
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/davidred/weimark.
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "weimark"
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(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ require "weimark/version"
2
+ require "weimark/client"
3
+
4
+ module Weimark
5
+ class Error < StandardError; end
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,131 @@
1
+ require 'nokogiri'
2
+ require 'httparty'
3
+ require 'active_support/core_ext/hash/conversions'
4
+
5
+ module Weimark
6
+ class Client
7
+ WEIMARK_URL = 'https://secure.weimark.com/api/post'.freeze
8
+
9
+ attr_reader :url, :email, :password, :agents_email
10
+
11
+ def initialize(options = {})
12
+ @url = options[:url] || WEIMARK_URL
13
+ @email = options[:email] || ENV['WEIMARK_EMAIL']
14
+ @password = options[:password] || ENV['WEIMARK_PASSWORD']
15
+ @agents_email = options[:agents_email] || ENV['AGENTS_EMAIL']
16
+ end
17
+
18
+ def get(application_id)
19
+ request(
20
+ http_method: :post,
21
+ endpoint: url,
22
+ body: {
23
+ request: xml_request(
24
+ action: "GetApplication",
25
+ agents_email: agents_email,
26
+ body: {
27
+ applicationid: application_id
28
+ }
29
+ )
30
+ }
31
+ )
32
+ end
33
+
34
+ # Sample application_attributes:
35
+ # {fname: 'JONATHAN', lname: 'CONSUMER', dob: '01/05/1987', gender: 'male', ssn: '485774859', streetnumber: '236', streetname: 'BIRCH', streettype: 'S', city: 'BURBANK', country: 'USA', suite: '1TEST', zip: '91502'}
36
+ def post(application_attributes = {})
37
+ request(
38
+ http_method: :post,
39
+ endpoint: url,
40
+ body: {
41
+ request: xml_request(
42
+ action: "NewApplication",
43
+ agents_email: agents_email,
44
+ body: {
45
+ applicant: application_attributes
46
+ }
47
+ )
48
+ }
49
+ )
50
+ end
51
+
52
+ private
53
+
54
+ def request(http_method:, endpoint:, body: {})
55
+ response = Weimark::Response.new(HTTParty.public_send(http_method, endpoint, body: body))
56
+ end
57
+
58
+ def xml_request(action:, agents_email:, body: {})
59
+ Nokogiri::XML::Builder.new do |xml|
60
+ xml.root {
61
+ xml.action action
62
+ xml.email email
63
+ xml.password password
64
+ xml.agents_email agents_email
65
+ xml.request {
66
+ body.each do |k, v|
67
+ if v.is_a?(Hash)
68
+ xml.send(k) {
69
+ v.each { |k, v| xml.send(k, v) }
70
+ }
71
+ else
72
+ xml.send(k, v)
73
+ end
74
+ end
75
+ }
76
+ }
77
+ end.to_xml.gsub("root", "xml")
78
+ end
79
+ end
80
+
81
+ class Response
82
+ attr_reader :response, :parsed_response, :status, :message, :application, :report
83
+
84
+ # {"application"=>{"id"=>"3x7gda8bz6drq5d4d79faee07x80y5i0", "timestamp"=>"08/21/2018 14:43:24", "link"=>"https://secure.weimark.com/applications/view/380854", "status"=>"COMPLETED"}, "report"=>{"decision"=>"Excellent", "ficoscores"=>{"applicants"=>{"applicant"=>{"name"=>"John Doe", "score"=>"850"}}}, "fullreport"=>""}}}
85
+ def initialize(response)
86
+ @response = response
87
+ @parsed_response = Hash.from_xml(response)['xml']
88
+ @status = parsed_response['status']
89
+
90
+ if successful?
91
+ result = @parsed_response['result']
92
+ application = result['application']
93
+ application.merge!('id' => result['applicationid']) if result['applicationid']
94
+ @application = Weimark::Application.new(application)
95
+ @report = Weimark::Report.new(result['report']) if result['report']
96
+ else
97
+ @message = parsed_response['message']
98
+ end
99
+ end
100
+
101
+ def successful?
102
+ status != 'ERROR'
103
+ end
104
+
105
+ def errors
106
+ successful? ? [] : [parsed_response['message']]
107
+ end
108
+ end
109
+
110
+ class Application
111
+ attr_reader :id, :timestamp, :link, :status
112
+
113
+ def initialize(application_attributes = {})
114
+ @id = application_attributes['id']
115
+ @timestamp = application_attributes['timestamp']
116
+ @link = application_attributes['link']
117
+ @status = application_attributes['status']
118
+ end
119
+ end
120
+
121
+ class Report
122
+ attr_reader :decision, :score, :name, :fullreport
123
+
124
+ def initialize(report_attributes = {})
125
+ @decision = report_attributes.try(:[], 'decision')
126
+ @fullreport = report_attributes.try(:[], 'fullreport')
127
+ @score = report_attributes.try(:[], 'ficoscores').try(:[], 'applicants').try(:[], 'applicant').try(:[], 'score')
128
+ @name = report_attributes.try(:[], 'ficoscores').try(:[], 'applicants').try(:[], 'applicant').try(:[], 'name')
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,3 @@
1
+ module Weimark
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,48 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "weimark/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "weimark"
8
+ spec.version = Weimark::VERSION
9
+ spec.authors = ["David Rozenberg"]
10
+ spec.email = ["daveroze@gmail.com"]
11
+
12
+ spec.summary = %q{Gem to wrap Weimark API}
13
+ spec.description = %q{Gem to wrap Weimark API}
14
+ spec.homepage = "https://roomeze.com"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "http://rubygems.org"
21
+
22
+ # spec.metadata["homepage_uri"] = spec.homepage
23
+ # spec.metadata["source_code_uri"] = "https://github.com/davidred/weimark"
24
+ # spec.metadata["changelog_uri"] = "https://github.com/davidred/weimark"
25
+ # else
26
+ # raise "RubyGems 2.0 or newer is required to protect against " \
27
+ # "public gem pushes."
28
+ # end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 2.0"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ spec.add_development_dependency "vcr", "~> 4.0"
43
+ spec.add_development_dependency "webmock", "~> 3.5"
44
+
45
+ spec.add_dependency "nokogiri", "~> 1.6"
46
+ spec.add_dependency "httparty", "~> 0.16"
47
+ spec.add_dependency "activesupport", ">= 1.2", "<= 5.2"
48
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weimark
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Rozenberg
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-19 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: nokogiri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.6'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: httparty
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.16'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.16'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activesupport
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '1.2'
118
+ - - "<="
119
+ - !ruby/object:Gem::Version
120
+ version: '5.2'
121
+ type: :runtime
122
+ prerelease: false
123
+ version_requirements: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '1.2'
128
+ - - "<="
129
+ - !ruby/object:Gem::Version
130
+ version: '5.2'
131
+ description: Gem to wrap Weimark API
132
+ email:
133
+ - daveroze@gmail.com
134
+ executables: []
135
+ extensions: []
136
+ extra_rdoc_files: []
137
+ files:
138
+ - ".gitignore"
139
+ - ".rspec"
140
+ - ".travis.yml"
141
+ - Gemfile
142
+ - LICENSE.txt
143
+ - README.md
144
+ - Rakefile
145
+ - bin/console
146
+ - bin/setup
147
+ - lib/weimark.rb
148
+ - lib/weimark/client.rb
149
+ - lib/weimark/version.rb
150
+ - weimark.gemspec
151
+ homepage: https://roomeze.com
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.7.8
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Gem to wrap Weimark API
175
+ test_files: []