checkr-canada 0.1.0

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: 7a0f958343edf3ee08da068b738327fac6b89b61
4
+ data.tar.gz: f8b8f3addf39dadd1333fa793c59a1312f45523f
5
+ SHA512:
6
+ metadata.gz: 994a7ed50ae4c915be1175ce3123f3571cef20226f03eff96ae6cbe77fd18098e3b794de5da482b7186cebb256fab2d6e7ab2c3475564e9f3bdc554772c2547b
7
+ data.tar.gz: d6c200d385c955e416ff9027b561faffe34c5d0198edbca8130d66fb67ec1572b4843624702864fb8bf922a7e43d568798b9cac028cb5c6c45a2a4b0e5c9c177
@@ -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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,76 @@
1
+ AllCops:
2
+ Include:
3
+ - 'lib/**/*.rb'
4
+ - 'lib/**/*.rake'
5
+ - 'spec/**/*.rb'
6
+ Exclude:
7
+ - 'bin/**/*'
8
+ - 'spec/dummy/**/*'
9
+ - 'tmp/**/*'
10
+ - 'Rakefile'
11
+ - 'Gemfile'
12
+ - '*.gemspec'
13
+ DisplayCopNames: true
14
+ StyleGuideCopsOnly: false
15
+ TargetRubyVersion: 2.4
16
+
17
+ Rails:
18
+ Enabled: false
19
+
20
+ Style/AccessorMethodName:
21
+ Enabled: false
22
+
23
+ Style/TrivialAccessors:
24
+ Enabled: false
25
+
26
+ Style/Documentation:
27
+ Exclude:
28
+ - 'spec/**/*.rb'
29
+ - 'lib/checkr/canada/entities/**/*.rb'
30
+
31
+ Style/StringLiterals:
32
+ Enabled: false
33
+
34
+ Style/RegexpLiteral:
35
+ Enabled: false
36
+
37
+ Style/SpaceInsideStringInterpolation:
38
+ EnforcedStyle: no_space
39
+
40
+ Style/ClassAndModuleChildren:
41
+ Enabled: false
42
+
43
+ Style/BlockDelimiters:
44
+ Exclude:
45
+ - 'spec/**/*.rb'
46
+
47
+ Lint/AmbiguousRegexpLiteral:
48
+ Enabled: false
49
+
50
+ Lint/NestedMethodDefinition:
51
+ Exclude:
52
+ - 'lib/checkr/canada/entities/**/*.rb'
53
+
54
+ Metrics/MethodLength:
55
+ Exclude:
56
+ - 'spec/**/*.rb'
57
+ - 'lib/checkr/canada/entities/**/*.rb'
58
+
59
+ Metrics/AbcSize:
60
+ Exclude:
61
+ - 'lib/checkr/canada/entities/**/*.rb'
62
+
63
+ Metrics/LineLength:
64
+ Max: 100
65
+ Exclude:
66
+ - 'spec/**/*.rb'
67
+
68
+ Metrics/BlockLength:
69
+ Exclude:
70
+ - 'spec/**/*.rb'
71
+
72
+ Rails/Date:
73
+ Enabled: false
74
+
75
+ Rails/TimeZone:
76
+ Enabled: false
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'pry-byebug'
4
+ # Specify your gem's dependencies in checkr-canada.gemspec
5
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 palkan
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,140 @@
1
+ # Checkr Canada API Client
2
+
3
+ [Checkr Canada](https://checkr-canada.api-docs.io/v1/overview) API client.
4
+
5
+ Built on top of [evil-client](https://github.com/evilmartians/evil-client).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'checkr-canada'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install checkr-canada
22
+
23
+ ## Usage
24
+
25
+
26
+ First, you should initialize a client using your API key:
27
+
28
+ ```ruby
29
+ require 'checkr-canada'
30
+
31
+ client = Checkr::Canada::Client.new('my-checkr-api-key')
32
+ ```
33
+
34
+ Then you can make API requests:
35
+
36
+
37
+ ```ruby
38
+ # ==== Candidates ==== #
39
+
40
+ # Create a candidate
41
+ client.candidates.create(
42
+ first_name: "Test",
43
+ last_name: "Candidate",
44
+ email: "testonboard@test.com",
45
+ phone: "000-000-0002",
46
+ birth_place: "Toronto",
47
+ dob: Date.new(2017, 3, 23), # accepts Data, Time and String objects
48
+ gender: "F"
49
+ )
50
+
51
+ #=> <Checkr::Canada::Entities::Candidate ...>
52
+
53
+
54
+ # Get a candidate
55
+ client.candidates.get("123123123")
56
+
57
+ #=> <Checkr::Canada::Entities::Candidate ...>
58
+
59
+ # List candidates
60
+ result = client.candidates.all(page: 1, per_page: 10)
61
+ result.count = 42
62
+ result.data #=> [<Checkr::Canada::Entities::Candidate ...>, ...]
63
+
64
+
65
+ # ==== Documents ==== #
66
+
67
+ # Upload a document
68
+ client.documents.upload(candidate_id: "123", url: "https://example.com/image.png", type: "identification")
69
+
70
+ #=> <Checkr::Canada::Entities::Document ...>
71
+
72
+
73
+ # ==== Addresses ==== #
74
+
75
+ # Create an address for a candidate
76
+ client.addresses.create(
77
+ candidate_id: "123",
78
+ street1: "Mission st",
79
+ street2: "4-2",
80
+ region: "BC",
81
+ city: "San Francisco",
82
+ postal_code: "BC341",
83
+ start_date: "2017-01-02"
84
+ )
85
+
86
+ #=> <Checkr::Canada::Entities::Address ...>
87
+
88
+
89
+ # ==== Reports ==== #
90
+
91
+ # Create a report
92
+ client.reports.create(candidate_id: "123", package: "mvr")
93
+
94
+ #=> <Checkr::Canada::Entities::Report ...>
95
+
96
+ # Get a report
97
+ client.report.get("123123123")
98
+
99
+ #=> <Checkr::Canada::Entities::Report ...>
100
+
101
+ # List reports
102
+ result = client.reports.all(page: 1, per_page: 10)
103
+ result.count = 42
104
+ result.data #=> [<Checkr::Canada::Entities::Report ...>, ...]
105
+
106
+ # ==== Criminal Records ==== #
107
+
108
+ # Create a record
109
+ client.criminal_records.create(candidate_id: 'ca1b9ca32fc52fd902a57487', offence: 'Killing Teddy Bear', sentence_date: Date.today, location: 'Moscow')
110
+
111
+ #=> <Checkr::Canada::Entities::CriminalRecord ...>
112
+ ```
113
+
114
+ ### Exceptions
115
+
116
+ Client uses `dry-types` and `evil-client` gems to validate params and response format. There can be the following exceptions:
117
+
118
+ - `Dry::Types::ConstraintError` when provided data is invalid
119
+
120
+ - `ArgumentError` when required params are missing
121
+
122
+ - `Evil::Client::Operation::ResponseError` when API-level error occurs (e.g. authentication failure, resource not found, etc)
123
+
124
+ - `Evil::Client::Operation::UnexpectedResponseError` when we fail to parse response.
125
+
126
+ ## Development
127
+
128
+ 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.
129
+
130
+ 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).
131
+
132
+ ## Contributing
133
+
134
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/checkr-canada.
135
+
136
+
137
+ ## License
138
+
139
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
140
+
@@ -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,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "checkr-canada"
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
+ begin
11
+ require "pry"
12
+ Pry.start
13
+ rescue LoadError
14
+ require "irb"
15
+ IRB.start
16
+ end
@@ -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,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'checkr/canada/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "checkr-canada"
8
+ spec.version = Checkr::Canada::VERSION
9
+ spec.authors = ["palkan"]
10
+ spec.email = ["dementiev.vm@gmail.com"]
11
+
12
+ spec.summary = "Checkr Canada API client"
13
+ spec.description = "Checkr Canda API client (https://checkr-canada.api-docs.io/v1/overview)"
14
+ spec.homepage = "http://github.com/onboardiq/checkr-canada"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "dry-types", "~> 0.10.3"
21
+ spec.add_runtime_dependency "evil-client", "~> 0.3.2"
22
+
23
+ spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec", "~> 3.5"
26
+ spec.add_development_dependency "webmock", "~> 2.1"
27
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "checkr/canada"
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "checkr/canada/version"
4
+ require "checkr/canada/client"
5
+
6
+ module Checkr
7
+ module Canada # :nodoc:
8
+ end
9
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "evil-client"
4
+ require "base64"
5
+
6
+ require_relative "types"
7
+ require_relative "ext/stringify_json_patch"
8
+
9
+ module Checkr
10
+ module Canada
11
+ # Checkr Canada API client
12
+ class Client
13
+ extend Evil::Client::DSL
14
+
15
+ path = File.expand_path("../entities/*.rb", __FILE__)
16
+ Dir[path].each { |file| require(file) }
17
+
18
+ settings do
19
+ param :api_key, Types::Strict::String
20
+ option :version, Types::Coercible::Int, default: proc { 1 }
21
+ end
22
+
23
+ base_url do |settings|
24
+ "https://api.checkr.com/ca/v#{settings.version}/"
25
+ end
26
+
27
+ operation do |settings|
28
+ security { basic_auth settings.api_key, '' }
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ Evil::Client::Middleware::StringifyJson.prepend StringifyJsonPatch
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Checkr
4
+ module Canada
5
+ module Entities
6
+ class AddressForm < Evil::Struct
7
+ attribute :street1, Types::Strict::String
8
+ attribute :street2, Types::String, optional: true
9
+ attribute :region, Types::Province
10
+ attribute :city, Types::Strict::String
11
+ attribute :postal_code, Types::Strict::String
12
+ attribute :country, Types::Strict::String, default: proc { "CA" }
13
+ attribute :start_date, Types::Date
14
+ end
15
+
16
+ class Address < AddressForm
17
+ attribute :id, Types::Strict::String
18
+ attribute :object, Types::String, optional: true
19
+ attribute :uri, Types::Strict::String
20
+ attribute :created_at, Types::Json::DateTime
21
+ attribute :updated_at, Types::Json::DateTime, optional: true
22
+ end
23
+ end
24
+
25
+ class Client
26
+ operation :create_address do |_settings|
27
+ http_method :post
28
+
29
+ path { |candidate_id:, **| "candidates/#{candidate_id}/addresses" }
30
+
31
+ body format: "json", model: Entities::AddressForm
32
+
33
+ response :success, 201, format: :json, model: Entities::Address
34
+
35
+ response :not_authorized, 401, format: :json, raise: true do
36
+ attribute :error
37
+ end
38
+
39
+ response :invalid, 400, format: :json, raise: true do
40
+ attribute :error
41
+ end
42
+ end
43
+
44
+ scope :addresses do
45
+ def create(data)
46
+ operations[:create_address].call(data)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Checkr
4
+ module Canada
5
+ module Entities
6
+ class CandidateForm < Evil::Struct
7
+ attribute :first_name, Types::Strict::String
8
+ attribute :middle_name, Types::String, optional: true
9
+ attribute :last_name, Types::Strict::String
10
+ attribute :mother_maiden_name, Types::String, optional: true
11
+
12
+ attribute :email, Types::Email
13
+ attribute :dob, Types::Date
14
+ attribute :phone, Types::Strict::String
15
+ attribute :gender, Types::Gender, optional: true
16
+
17
+ attribute :birth_place, Types::String, optional: true
18
+ attribute :birth_country, Types::Strict::String, default: proc { 'CA' }
19
+
20
+ attribute :driver_license_province, Types::String, optional: true
21
+ attribute :driver_license_number, Types::String, optional: true
22
+
23
+ attribute :nationality, Types::String, optional: true
24
+ attribute :entry_date, Types::String, optional: true
25
+
26
+ attribute :custom_id, Types::String, optional: true
27
+ end
28
+
29
+ class Candidate < CandidateForm
30
+ attribute :id, Types::Strict::String
31
+ attribute :object, Types::Strict::String
32
+ attribute :uri, Types::Strict::String
33
+ attribute :created_at, Types::Json::DateTime
34
+ attribute :updated_at, Types::Json::DateTime, optional: true
35
+
36
+ attribute :address_ids, Types::Strict::Array.member(Types::Strict::String)
37
+ end
38
+ end
39
+
40
+ class Client
41
+ operation :list_candidates do |_settings|
42
+ http_method :get
43
+ path { "candidates" }
44
+
45
+ query do
46
+ attributes optional: true do
47
+ attribute :page
48
+ attribute :per_page
49
+ end
50
+ end
51
+
52
+ response :success, 200, format: :json do
53
+ attribute :object, Types::Strict::String
54
+ attribute :next_href, Types::String, optional: true
55
+ attribute :previous_href, Types::String, optional: true
56
+ attribute :count, Types::Strict::Int
57
+ attribute :data, Types::Coercible::Array.member(Entities::Candidate)
58
+ end
59
+
60
+ response :not_authorized, 401, format: :json, raise: true do
61
+ attribute :error
62
+ end
63
+
64
+ response :not_found, 404, format: :json, raise: true do
65
+ attribute :error
66
+ end
67
+ end
68
+
69
+ operation :get_candidate do |_settings|
70
+ http_method :get
71
+ path { |id:, **| "candidates/#{id}" }
72
+
73
+ response :success, 200, format: :json, model: Entities::Candidate
74
+
75
+ response :not_authorized, 401, format: :json, raise: true do
76
+ attribute :error
77
+ end
78
+
79
+ response :not_found, 404, format: :json, raise: true do
80
+ attribute :message, as: :error
81
+ end
82
+ end
83
+
84
+ operation :create_candidate do |_settings|
85
+ http_method :post
86
+
87
+ path { "candidates" }
88
+
89
+ body format: "json", model: Entities::CandidateForm
90
+
91
+ response :success, 201, format: :json, model: Entities::Candidate
92
+
93
+ response :not_authorized, 401, format: :json, raise: true do
94
+ attribute :error
95
+ end
96
+ end
97
+
98
+ scope :candidates do
99
+ def all(**data)
100
+ operations[:list_candidates].call(**data)
101
+ end
102
+
103
+ def get(id, data = {})
104
+ operations[:get_candidate].call(data.merge(id: id))
105
+ end
106
+
107
+ def create(data)
108
+ operations[:create_candidate].call(data)
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end