checkr-rb 0.0.3a
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +110 -0
- data/Rakefile +10 -0
- data/checkr.gemspec +29 -0
- data/lib/checkr.rb +37 -0
- data/lib/checkr/base.rb +24 -0
- data/lib/checkr/candidate.rb +39 -0
- data/lib/checkr/core_ext.rb +57 -0
- data/lib/checkr/county_criminal_search.rb +5 -0
- data/lib/checkr/motor_vehicle_report.rb +25 -0
- data/lib/checkr/national_criminal_search.rb +5 -0
- data/lib/checkr/report.rb +35 -0
- data/lib/checkr/report_charge.rb +6 -0
- data/lib/checkr/report_record.rb +17 -0
- data/lib/checkr/sex_offender search.rb +5 -0
- data/lib/checkr/ssn_trace.rb +5 -0
- data/lib/checkr/subaccount.rb +19 -0
- data/lib/checkr/terrorist_watchlist_search.rb +6 -0
- data/lib/checkr/version.rb +3 -0
- data/test/cassettes/test_0001_should_create_candidate.yml +41 -0
- data/test/cassettes/test_0001_should_create_candidate_for_the_subaccount.yml +41 -0
- data/test/cassettes/test_0001_should_create_report.yml +41 -0
- data/test/cassettes/test_0001_should_create_subaccount.yml +44 -0
- data/test/cassettes/test_0001_should_return_candidate_object.yml +41 -0
- data/test/cassettes/test_0001_should_return_motor_vehicle_report_object.yml +41 -0
- data/test/cassettes/test_0001_should_return_report_object.yml +41 -0
- data/test/cassettes/test_0002_returns_candidate_object_with_checkr_parameters.yml +41 -0
- data/test/cassettes/test_0002_returns_motor_vehicle_report_object_with_parameters.yml +41 -0
- data/test/cassettes/test_0002_returns_report_object_with_parameters.yml +41 -0
- data/test/cassettes/test_0002_should_respond_to_candidate_parameters_belongs_to_subaccount.yml +41 -0
- data/test/cassettes/test_0002_should_respond_to_parameters.yml +41 -0
- data/test/cassettes/test_0002_should_respond_to_report_parameters.yml +41 -0
- data/test/cassettes/test_0002_should_respond_to_subaccount_parameters.yml +44 -0
- data/test/checkr_test.rb +18 -0
- data/test/lib/checkr/candidate_test.rb +66 -0
- data/test/lib/checkr/motor_vehicle_report_test.rb +23 -0
- data/test/lib/checkr/report_test.rb +39 -0
- data/test/lib/checkr/subaccount_test.rb +24 -0
- data/test/test_helper.rb +15 -0
- metadata +189 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a88aefc4b7d7f510d441047184fec40dc96dc12c
|
4
|
+
data.tar.gz: 29356d03792024cc24ee67e38457397281537897
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e725c4b0d369c9fefbbdbc419023842a2efc3c6aa86bd02c5f2ddb4f5bd2115950b5033a43fdd0f2f02eb5f9920a7f2a8c5f47fb7c286b7fdc7cdc603e92dab
|
7
|
+
data.tar.gz: 5ac48fb5c4d0cb60a2edb2383eddf774eb2d9168e6f7430ee50670f0c9aa806d02af97c9f1524d4ef3f34bb8a7cfa6644b3c8d45a3dd333d3054d05bac76a887
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
# Checkr
|
2
|
+
|
3
|
+
Ruby wrapper for checkr.io API (https://checkr.io/docs)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'checkr-rb'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install checkr-rb
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
**Configure authentication keys**
|
24
|
+
|
25
|
+
```Ruby
|
26
|
+
Checkr.configure do |c|
|
27
|
+
c.api_key = "83ebeabdec09f6670863766f792ead24d61fe3f9" #Test token from checkr api document
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
**Create subaccount**
|
32
|
+
|
33
|
+
```Ruby
|
34
|
+
subaccount = Checkr::Subaccount.create(:name => 'Checkr', :entity_name => 'My Company', :tax_id => 'XXXXX', :representative_title => 'CEO', :representative_name => 'John Smith', :representative_email => 'john.smith@company.org', :phone => '3101111111',
|
35
|
+
:incorporation_date => '2010-02-02', :incorporation_type => 'llc', :incorporation_state => 'DE', 'address[street]' => '3230 3rd street', 'address[city]' => 'San Francisco',
|
36
|
+
'address[state]' => 'CA', 'address[zipcode]'=> '94110')
|
37
|
+
|
38
|
+
#Subaccount attributes
|
39
|
+
subaccount_id = subaccount.id
|
40
|
+
```
|
41
|
+
|
42
|
+
**Create candidate for subaccount**
|
43
|
+
|
44
|
+
```Ruby
|
45
|
+
candidate = Checkr::Candidate.create(:subaccount_id => '8168372aac5a952b90eb9acb', :first_name => 'John', :last_name => 'Smith', :dob => '1970-01-22', :ssn => '111-11-2000', :phone => '5555555555', :email => 'john@smith.org')
|
46
|
+
|
47
|
+
#candidate attributes
|
48
|
+
candidate_id = candidate.id
|
49
|
+
```
|
50
|
+
|
51
|
+
**Create candidate**
|
52
|
+
|
53
|
+
```Ruby
|
54
|
+
candidate = Checkr::Candidate.create(:first_name => 'John', :last_name => 'Smith', :dob => '1970-01-22', :ssn => '111-11-2000', :phone => '5555555555', :email => 'john@smith.org')
|
55
|
+
|
56
|
+
#candidate attributes
|
57
|
+
candidate_id = candidate.id
|
58
|
+
```
|
59
|
+
|
60
|
+
**Find candidate**
|
61
|
+
|
62
|
+
```Ruby
|
63
|
+
candidate = Checkr::Candidate.find('e44aa283528e6fde7d542194')
|
64
|
+
candidate.id #Returns checkr id of the candidate
|
65
|
+
candidate.first_name #Returns first_name of the candidate
|
66
|
+
```
|
67
|
+
|
68
|
+
**Get all reports belongs to candidate, if exists**
|
69
|
+
|
70
|
+
```Ruby
|
71
|
+
candidate = Checkr::Subaccount.find('e44aa283528e6fde7d542194')
|
72
|
+
candidate.reports #Returns array of Checkr::Report objects
|
73
|
+
```
|
74
|
+
**Create report**
|
75
|
+
|
76
|
+
```Ruby
|
77
|
+
report = Checkr::Report.create(:package => 'driver_plus', :candidate_id => 'e44aa283528e6fde7d542194')
|
78
|
+
report.id #Returns the checkr id of the created report
|
79
|
+
```
|
80
|
+
|
81
|
+
**Find report**
|
82
|
+
|
83
|
+
```Ruby
|
84
|
+
report = Checkr::Report.find("5878551b3ee1eacae5a2c558")
|
85
|
+
report.id #Returns the checkr id of the created report
|
86
|
+
report.status #Returns the status of the report
|
87
|
+
```
|
88
|
+
**Find individual reports**
|
89
|
+
|
90
|
+
```Ruby
|
91
|
+
report = Checkr::MotorVehicleReport.find("5878551b3ee1eacae5a2c558")
|
92
|
+
report = Checkr::CountryCriminalSearch.find("5878551b3ee1eacae5a2c558")
|
93
|
+
report = Checkr::NationalCriminalSearch.find("5878551b3ee1eacae5a2c558")
|
94
|
+
report = Checkr::SexOffenderSearch.find("5878551b3ee1eacae5a2c558")
|
95
|
+
report = Checkr::SsnTrace.find("5878551b3ee1eacae5a2c558")
|
96
|
+
report = Checkr::TerroristWatchlistSearch.find("5878551b3ee1eacae5a2c558")
|
97
|
+
|
98
|
+
report.status #Returns the status of the report
|
99
|
+
report.records #Returns array of ReportRecord objects, if report has records
|
100
|
+
report.records.first.charges #Returns array of ReportCharge objects, if report has charges
|
101
|
+
report.accidents #In case of motor vehicle report
|
102
|
+
report.voilations #In case of motor vehicle report
|
103
|
+
```
|
104
|
+
## Contributing
|
105
|
+
|
106
|
+
1. Fork it ( https://github.com/[my-github-username]/checkr/fork )
|
107
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
108
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
109
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
110
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/checkr.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'checkr'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "checkr-rb"
|
8
|
+
spec.version = Checkr::VERSION
|
9
|
+
spec.authors = ["Vijendra Rao"]
|
10
|
+
spec.email = ["vijendrakarkala@gmail.com"]
|
11
|
+
spec.summary = %q{checkr API Ruby wrapper}
|
12
|
+
spec.description = %q{checkr.io API wrapper: Automated background screenings and driving records}
|
13
|
+
spec.homepage = "https://github.com/vijendra/checkr"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
#spec.require_paths = Dir["README.md","Gemfile","Rakefile", "test/*", "lib/**/*"]
|
20
|
+
spec.require_paths = %w(lib)
|
21
|
+
|
22
|
+
spec.add_dependency "httparty"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "vcr"
|
27
|
+
spec.add_development_dependency "webmock"
|
28
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
29
|
+
end
|
data/lib/checkr.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require "checkr/base"
|
2
|
+
require "checkr/version"
|
3
|
+
require "checkr/core_ext"
|
4
|
+
require "checkr/candidate"
|
5
|
+
require "checkr/subaccount"
|
6
|
+
require "checkr/report"
|
7
|
+
require "checkr/motor_vehicle_report"
|
8
|
+
require "checkr/sex_offender search"
|
9
|
+
require "checkr/ssn_trace"
|
10
|
+
require "checkr/terrorist_watchlist_search"
|
11
|
+
require "checkr/national_criminal_search"
|
12
|
+
require "checkr/county_criminal_search"
|
13
|
+
require "checkr/report_charge"
|
14
|
+
require "checkr/report_record"
|
15
|
+
|
16
|
+
module Checkr
|
17
|
+
class << self
|
18
|
+
attr_accessor :api_key, :api_version
|
19
|
+
|
20
|
+
def configure
|
21
|
+
yield self
|
22
|
+
api_version = 'v1' if api_version.nil? || api_version.empty?
|
23
|
+
raise Checkr::Error.new(':api_key cannot be blank') if api_key.nil? || api_key.empty?
|
24
|
+
end
|
25
|
+
|
26
|
+
alias :config :configure
|
27
|
+
|
28
|
+
def auth
|
29
|
+
{:username => Checkr.api_key }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Error < RuntimeError; end
|
34
|
+
class AuthenticationError < StandardError; end
|
35
|
+
class UnexpectedError < StandardError; end
|
36
|
+
class ParamsError < StandardError; end
|
37
|
+
end
|
data/lib/checkr/base.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module Checkr
|
5
|
+
class Base < OpenStruct
|
6
|
+
include HTTParty
|
7
|
+
base_uri "https://api.checkr.io/v1"
|
8
|
+
|
9
|
+
def self.construct(params)
|
10
|
+
new(params)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def self.handle_response(response)
|
16
|
+
case response.code.to_i
|
17
|
+
when 200...300 then self.construct(response.parsed_response)
|
18
|
+
when 401 then raise Checkr::AuthenticationError, "#{response.body}: Verify your api token."
|
19
|
+
else
|
20
|
+
raise Checkr::UnexpectedError, response.body
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
module Checkr
|
3
|
+
class Candidate < Checkr::Base
|
4
|
+
|
5
|
+
def self.create(params={})
|
6
|
+
if valid?(params)
|
7
|
+
uri = "/subaccounts/#{params[:subaccount_id]}" unless params[:subaccount_id].nil?
|
8
|
+
uri = "#{uri}/candidates"
|
9
|
+
response = self.post(uri, :body => params, :basic_auth => Checkr.auth )
|
10
|
+
handle_response(response)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.find(id)
|
15
|
+
response = self.get("/candidates/#{id}?include=reports", :basic_auth => {:username => Checkr.api_key } )
|
16
|
+
handle_response(response)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.construct(params)
|
20
|
+
reports = params["reports"]
|
21
|
+
candidate = self.new(params.except_key('reports'))
|
22
|
+
candidate.reports = []
|
23
|
+
unless reports.nil? || reports.empty?
|
24
|
+
reports.each do |report_attributes|
|
25
|
+
candidate.reports << Checkr::Report.new(report_attributes)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
return candidate
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
|
34
|
+
def self.valid?(params)
|
35
|
+
return true #TODO implement validation
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module ExtendCore
|
2
|
+
def extend_if_nonexistant *methods
|
3
|
+
methods.each do |method_name|
|
4
|
+
if !self.method_defined? method_name
|
5
|
+
alias_method method_name, "checkr__#{method_name}".to_sym
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Hash
|
12
|
+
extend ExtendCore
|
13
|
+
|
14
|
+
def checkr__except_key(which)
|
15
|
+
self.tap{ |h| h.delete(which) }
|
16
|
+
end
|
17
|
+
|
18
|
+
extend_if_nonexistant :except_key
|
19
|
+
end
|
20
|
+
|
21
|
+
class Object
|
22
|
+
extend ExtendCore
|
23
|
+
|
24
|
+
#From rails/Object/try
|
25
|
+
def checkr__try(*a, &b)
|
26
|
+
if a.empty? && block_given?
|
27
|
+
yield self
|
28
|
+
else
|
29
|
+
public_send(*a, &b) if respond_to?(a.first)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
extend_if_nonexistant :try
|
34
|
+
end
|
35
|
+
|
36
|
+
class String
|
37
|
+
extend ExtendCore
|
38
|
+
|
39
|
+
def checkr__underscored_class_name
|
40
|
+
self.split("::")[1].
|
41
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
42
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
43
|
+
tr("-", "_").
|
44
|
+
downcase
|
45
|
+
end
|
46
|
+
|
47
|
+
def checkr__pluralize
|
48
|
+
#TODO this is wrong. But works for now
|
49
|
+
"#{self}s"
|
50
|
+
end
|
51
|
+
|
52
|
+
def checkr__tablelize
|
53
|
+
self.underscored_class_name.pluralize
|
54
|
+
end
|
55
|
+
|
56
|
+
extend_if_nonexistant :pluralize, :tablelize, :underscored_class_name
|
57
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Checkr
|
2
|
+
class MotorVehicleReport < Checkr::Report
|
3
|
+
def self.construct(params)
|
4
|
+
accidents = params["accidents"]
|
5
|
+
violations = params["violations"]
|
6
|
+
report = self.new(params.except_key('accidents').except_key('violations'))
|
7
|
+
|
8
|
+
report.accidents = []
|
9
|
+
unless accidents.nil? || accidents.empty?
|
10
|
+
accidents.each do |accident_attributes|
|
11
|
+
report.accidents << Checkr::ReportRecord.construct(accident_attributes)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
report.violations = []
|
16
|
+
unless violations.nil? || violations.empty?
|
17
|
+
violations.each do |violation_attributes|
|
18
|
+
report.violations << Checkr::ReportRecord.construct(violation_attributes)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
return report
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
module Checkr
|
3
|
+
class Report < Checkr::Base
|
4
|
+
def self.create(params={})
|
5
|
+
if valid?(params)
|
6
|
+
response = self.post("/#{self.to_s.tablelize}", :body => params, :basic_auth => Checkr.auth )
|
7
|
+
handle_response(response)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.find(id)
|
12
|
+
response = self.get("/#{self.to_s.tablelize}/#{id}", :basic_auth => Checkr.auth )
|
13
|
+
handle_response(response)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.construct(params)
|
17
|
+
records = params["records"]
|
18
|
+
report = self.new(params.except_key('records'))
|
19
|
+
report.records = []
|
20
|
+
unless records.nil? || records.empty?
|
21
|
+
records.each do |record_attributes|
|
22
|
+
report.records << Checkr::ReportRecord.construct(record_attributes)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
return report
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def self.valid?(params)
|
32
|
+
return true #TODO implement validation
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|