Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monami/feature/find candidated by email #10

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions checkr.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'checkr'
require 'checkr/version'

Gem::Specification.new do |spec|
spec.name = "checkr-rb"
Expand All @@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
#spec.require_paths = Dir["README.md","Gemfile","Rakefile", "test/*", "lib/**/*"]
spec.require_paths = %w(lib)

spec.add_dependency "httparty"
spec.add_runtime_dependency "httparty"

spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "bundler", "~> 2.0"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "vcr"
spec.add_development_dependency "webmock"
Expand Down
53 changes: 53 additions & 0 deletions lib/checkr/candidate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@
module Checkr
class Candidate < Checkr::Base

ArgumentError = Class.new RuntimeError

###
# Implements https://docs.checkr.com/#operation/createCandidate
# Accepted keys:
# * first_name (required)
# * middle_name
# * no_middle_name (Default: false)
# * last_name (required)
# * mother_maiden_name
# * email (required)
# * phone
# * zipcode
# * dob
# * ssn
# * driver_license_number
# * driver_license_state
# * previous_driver_license_number
# * previous_driver_license_state
# * copy_requested (Default: false)
# * geo_ids
###
def self.create(params={})
if valid?(params)
uri = "/subaccounts/#{params[:subaccount_id]}" unless params[:subaccount_id].nil?
Expand Down Expand Up @@ -29,6 +51,37 @@ def self.construct(params)
return candidate
end

PERMITTED_KEYS = %w(email full_name adjudication custom_id created_after created_before geo_id program_id)
###
# Implements https://docs.checkr.com/#operation/listOfCandidates
# Accepted keys:
# * email
# * full_name
# * adjudication
# * custom_id
# * created_after
# * created_before
# * geo_id
# * program_id
###
def self.where(params)
if params.is_a?(Hash)
unsupported_keys = params.stringify_keys.keys - PERMITTED_KEYS
if unsupported_keys.any?
raise ArgumentError, "Unsupported parameter(s) #{unsupported_keys.inspect}"
end
else
raise ArgumentError, 'Arguments must be a hash'
end

response = self.get("/candidates?#{params.to_query}", basic_auth: { username: Checkr.api_key } )
handle_response(response).data.map { |candidate| self.new candidate }
end

def self.find_by(params)
where(params).first
end

protected

def self.valid?(params)
Expand Down
2 changes: 1 addition & 1 deletion lib/checkr/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Checkr
VERSION = "0.0.3a"
VERSION = "0.0.4"
end