checkr-official 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.travis.yml +16 -0
  4. data/Gemfile +8 -0
  5. data/History.txt +4 -0
  6. data/README.md +58 -0
  7. data/Rakefile +14 -0
  8. data/VERSION +1 -0
  9. data/bin/checkr-console +7 -0
  10. data/checkr-official.gemspec +28 -0
  11. data/gemfiles/default-with-activesupport.gemfile +10 -0
  12. data/gemfiles/json.gemfile +12 -0
  13. data/gemfiles/yajl.gemfile +12 -0
  14. data/lib/checkr.rb +241 -0
  15. data/lib/checkr/api_class.rb +395 -0
  16. data/lib/checkr/api_list.rb +78 -0
  17. data/lib/checkr/api_resource.rb +18 -0
  18. data/lib/checkr/api_singleton.rb +5 -0
  19. data/lib/checkr/candidate.rb +35 -0
  20. data/lib/checkr/county_criminal_search.rb +19 -0
  21. data/lib/checkr/document.rb +13 -0
  22. data/lib/checkr/document_list.rb +25 -0
  23. data/lib/checkr/errors/api_connection_error.rb +4 -0
  24. data/lib/checkr/errors/api_error.rb +10 -0
  25. data/lib/checkr/errors/authentication_error.rb +4 -0
  26. data/lib/checkr/errors/checkr_error.rb +20 -0
  27. data/lib/checkr/errors/invalid_request_error.rb +10 -0
  28. data/lib/checkr/geo.rb +19 -0
  29. data/lib/checkr/motor_vehicle_report.rb +31 -0
  30. data/lib/checkr/national_criminal_search.rb +17 -0
  31. data/lib/checkr/report.rb +43 -0
  32. data/lib/checkr/report_list.rb +27 -0
  33. data/lib/checkr/sex_offender_search.rb +18 -0
  34. data/lib/checkr/ssn_trace.rb +18 -0
  35. data/lib/checkr/subscription.rb +27 -0
  36. data/lib/checkr/terrorist_watchlist_search.rb +17 -0
  37. data/lib/checkr/util.rb +91 -0
  38. data/lib/checkr/version.rb +3 -0
  39. data/mclovin.jpg +0 -0
  40. data/tasks/api_test.rb +192 -0
  41. data/test/checkr/api_class_test.rb +426 -0
  42. data/test/checkr/api_list_test.rb +27 -0
  43. data/test/checkr/api_resource_test.rb +28 -0
  44. data/test/checkr/api_singleton_test.rb +12 -0
  45. data/test/checkr/authentication_test.rb +50 -0
  46. data/test/checkr/candidate_test.rb +164 -0
  47. data/test/checkr/county_criminal_search_test.rb +82 -0
  48. data/test/checkr/document_test.rb +90 -0
  49. data/test/checkr/geo_test.rb +73 -0
  50. data/test/checkr/motor_vehicle_report_test.rb +130 -0
  51. data/test/checkr/national_criminal_search_test.rb +74 -0
  52. data/test/checkr/report_test.rb +124 -0
  53. data/test/checkr/sex_offender_search_test.rb +75 -0
  54. data/test/checkr/ssn_trace_test.rb +78 -0
  55. data/test/checkr/status_codes_test.rb +63 -0
  56. data/test/checkr/subscription_test.rb +96 -0
  57. data/test/checkr/terrorist_watchlist_search_test.rb +74 -0
  58. data/test/checkr/util_test.rb +50 -0
  59. data/test/mock_resource.rb +88 -0
  60. data/test/test_data.rb +413 -0
  61. data/test/test_helper.rb +43 -0
  62. metadata +230 -0
@@ -0,0 +1,78 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Checkr
4
+ class SSNTraceTest < Test::Unit::TestCase
5
+ setup do
6
+ @ssn_trace_url = "#{Checkr.api_base}/v1/ssn_traces"
7
+ end
8
+
9
+ context 'SSNTrace class' do
10
+ should 'be retrieveable' do
11
+ id = "ssn_trace_id"
12
+ @mock.expects(:get).once.with("#{@ssn_trace_url}/#{id}", anything, anything).returns(test_response(test_ssn_trace))
13
+ ssn_trace = SSNTrace.retrieve(id)
14
+ assert(ssn_trace.is_a?(SSNTrace))
15
+ end
16
+ end
17
+
18
+ context 'SSNTrace instance' do
19
+ should 'be refreshable' do
20
+ @mock.expects(:get).once.with("#{@ssn_trace_url}/#{test_ssn_trace[:id]}", anything, anything).returns(test_response(test_ssn_trace))
21
+ ssn_trace = SSNTrace.new(test_ssn_trace[:id])
22
+ ssn_trace.refresh
23
+ assert_equal(test_ssn_trace[:status], ssn_trace.status)
24
+ end
25
+ end
26
+
27
+
28
+ context 'Retrieved SSNTrace instance' do
29
+ setup do
30
+ @mock.expects(:get).once.returns(test_response(test_ssn_trace))
31
+ @ssn_trace = SSNTrace.retrieve('ssn_trace_id')
32
+ end
33
+
34
+ should 'have the id attribute' do
35
+ assert_equal(test_ssn_trace[:id], @ssn_trace.id)
36
+ end
37
+
38
+ should 'have the object attribute' do
39
+ assert_equal(test_ssn_trace[:object], @ssn_trace.object)
40
+ end
41
+
42
+ should 'have the uri attribute' do
43
+ assert_equal(test_ssn_trace[:uri], @ssn_trace.uri)
44
+ end
45
+
46
+ should 'have the status attribute' do
47
+ assert_equal(test_ssn_trace[:status], @ssn_trace.status)
48
+ end
49
+
50
+ should 'have the created_at attribute' do
51
+ assert_equal(test_ssn_trace[:created_at], @ssn_trace.created_at)
52
+ end
53
+
54
+ should 'have the completed_at attribute' do
55
+ assert_equal(test_ssn_trace[:completed_at], @ssn_trace.completed_at)
56
+ end
57
+
58
+ should 'have the turnaround_time attribute' do
59
+ assert_equal(test_ssn_trace[:turnaround_time], @ssn_trace.turnaround_time)
60
+ end
61
+
62
+ should 'have the ssn attribute' do
63
+ assert_equal(test_ssn_trace[:ssn], @ssn_trace.ssn)
64
+ end
65
+
66
+ should 'have the addresses attribute' do
67
+ assert_equal(test_ssn_trace[:addresses], @ssn_trace.addresses)
68
+ end
69
+
70
+ end
71
+
72
+ should 'be registered' do
73
+ assert(APIClass.subclasses.include?(SSNTrace))
74
+ assert_equal(SSNTrace, APIClass.subclass_fetch("ssn_trace"))
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,63 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path('../../test_helper', __FILE__)
3
+
4
+ module Checkr
5
+ class StatusCodesTest < Test::Unit::TestCase
6
+
7
+ context 'InvalidRequestError' do
8
+ should 'be raised when HTTP status code is 400' do
9
+ response = test_response(test_missing_id_error, 400)
10
+ @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
11
+ begin
12
+ MockResource.retrieve('bad_id')
13
+ rescue InvalidRequestError => e
14
+ assert_equal(400, e.http_status)
15
+ assert(!!e.http_body)
16
+ assert(e.json_body.is_a?(Hash))
17
+ end
18
+ end
19
+
20
+ should 'be raised when HTTP status code is 404' do
21
+ response = test_response(test_missing_id_error, 404)
22
+ @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
23
+ assert_raises
24
+ begin
25
+ MockResource.retrieve('foo')
26
+ rescue InvalidRequestError => e
27
+ rescued = true
28
+ assert_equal(404, e.http_status)
29
+ assert_equal(true, !!e.http_body)
30
+ assert_equal(true, e.json_body.is_a?(Hash))
31
+ end
32
+ assert(rescued)
33
+ end
34
+ end
35
+
36
+ context 'APIError' do
37
+ should 'be raised when HTTP status code is 5XX' do
38
+ response = test_response(test_api_error, 500)
39
+ @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 500))
40
+
41
+ begin
42
+ MockResource.new('fake_id').refresh
43
+ rescue APIError => e
44
+ rescued = true
45
+ assert(e.is_a?(APIError))
46
+ end
47
+ assert(rescued)
48
+ end
49
+ end
50
+
51
+ context 'AuthenticationError' do
52
+ should 'be raised when HTTP status code is 401 (invalid credentials)' do
53
+ Checkr.api_key = 'invalid'
54
+ response = test_response(test_invalid_api_key_error, 401)
55
+ assert_raises(AuthenticationError) do
56
+ @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 401))
57
+ MockResource.retrieve('failing')
58
+ end
59
+ end
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,96 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Checkr
4
+ class SubscriptionTest < Test::Unit::TestCase
5
+ setup do
6
+ @subscription_url = "#{Checkr.api_base}/v1/subscriptions"
7
+ end
8
+
9
+ context 'Subscription class' do
10
+ should 'be retrieveable' do
11
+ id = "subscription_id"
12
+ @mock.expects(:get).once.with("#{@subscription_url}/#{id}", anything, anything).returns(test_response(test_subscription))
13
+ subscription = Subscription.retrieve(id)
14
+ assert(subscription.is_a?(Subscription))
15
+ end
16
+
17
+ should 'be createable' do
18
+ @mock.expects(:post).once.with(@subscription_url, anything, test_subscription).returns(test_response(test_subscription))
19
+ subscription = Subscription.create(test_subscription)
20
+ assert(subscription.is_a?(Subscription))
21
+ assert_equal(test_subscription[:id], subscription.id)
22
+ end
23
+ end
24
+
25
+ context 'Subscription instance' do
26
+ should 'be refreshable' do
27
+ @mock.expects(:get).once.with("#{@subscription_url}/#{test_subscription[:id]}", anything, anything).returns(test_response(test_subscription))
28
+ subscription = Subscription.new(test_subscription[:id])
29
+ subscription.refresh
30
+ assert_equal(test_subscription[:package], subscription.package)
31
+ end
32
+
33
+ should 'be cancelable' do
34
+ @mock.expects(:delete).once.with("#{@subscription_url}/#{test_subscription[:id]}", anything, anything).returns(test_response(test_subscription))
35
+ subscription = Subscription.new(test_subscription[:id])
36
+ subscription.cancel
37
+ end
38
+ end
39
+
40
+
41
+ context 'Retrieved Subscription instance' do
42
+ setup do
43
+ @mock.expects(:get).once.returns(test_response(test_subscription))
44
+ @subscription = Subscription.retrieve('subscription_id')
45
+ end
46
+
47
+ should 'have the id attribute' do
48
+ assert_equal(test_subscription[:id], @subscription.id)
49
+ end
50
+
51
+ should 'have the object attribute' do
52
+ assert_equal(test_subscription[:object], @subscription.object)
53
+ end
54
+
55
+ should 'have the uri attribute' do
56
+ assert_equal(test_subscription[:uri], @subscription.uri)
57
+ end
58
+
59
+ should 'have the status attribute' do
60
+ assert_equal(test_subscription[:status], @subscription.status)
61
+ end
62
+
63
+ should 'have the created_at attribute' do
64
+ assert_equal(test_subscription[:created_at], @subscription.created_at)
65
+ end
66
+
67
+ should 'have the canceled_at attribute' do
68
+ assert_equal(test_subscription[:canceled_at], @subscription.canceled_at)
69
+ end
70
+
71
+ should 'have the package attribute' do
72
+ assert_equal(test_subscription[:package], @subscription.package)
73
+ end
74
+
75
+ should 'have the interval_count attribute' do
76
+ assert_equal(test_subscription[:interval_count], @subscription.interval_count)
77
+ end
78
+
79
+ should 'have the start_date attribute' do
80
+ assert_equal(test_subscription[:start_date], @subscription.start_date)
81
+ end
82
+
83
+ should 'have the candidate attribute' do
84
+ assert_equal(test_subscription[:candidate_id], @subscription.candidate.id)
85
+ assert(@subscription.candidate.is_a?(Candidate))
86
+ end
87
+
88
+ end
89
+
90
+ should 'be registered' do
91
+ assert(APIClass.subclasses.include?(Subscription))
92
+ assert_equal(Subscription, APIClass.subclass_fetch("subscription"))
93
+ end
94
+
95
+ end
96
+ end
@@ -0,0 +1,74 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Checkr
4
+ class TerroristWatchlistSearchTest < Test::Unit::TestCase
5
+ setup do
6
+ @terrorist_watchlist_search_url = "#{Checkr.api_base}/v1/terrorist_watchlist_searches"
7
+ end
8
+
9
+ context 'TerroristWatchlistSearch class' do
10
+ should 'be retrieveable' do
11
+ id = "terrorist_watchlist_search_id"
12
+ @mock.expects(:get).once.with("#{@terrorist_watchlist_search_url}/#{id}", anything, anything).returns(test_response(test_terrorist_watchlist_search))
13
+ terrorist_watchlist_search = TerroristWatchlistSearch.retrieve(id)
14
+ assert(terrorist_watchlist_search.is_a?(TerroristWatchlistSearch))
15
+ end
16
+ end
17
+
18
+ context 'TerroristWatchlistSearch instance' do
19
+ should 'be refreshable' do
20
+ @mock.expects(:get).once.with("#{@terrorist_watchlist_search_url}/#{test_terrorist_watchlist_search[:id]}", anything, anything).returns(test_response(test_terrorist_watchlist_search))
21
+ terrorist_watchlist_search = TerroristWatchlistSearch.new(test_terrorist_watchlist_search[:id])
22
+ terrorist_watchlist_search.refresh
23
+ assert_equal(test_terrorist_watchlist_search[:status], terrorist_watchlist_search.status)
24
+ end
25
+ end
26
+
27
+
28
+ context 'Retrieved TerroristWatchlistSearch instance' do
29
+ setup do
30
+ @mock.expects(:get).once.returns(test_response(test_terrorist_watchlist_search))
31
+ @terrorist_watchlist_search = TerroristWatchlistSearch.retrieve('terrorist_watchlist_search_id')
32
+ end
33
+
34
+ should 'have the id attribute' do
35
+ assert_equal(test_terrorist_watchlist_search[:id], @terrorist_watchlist_search.id)
36
+ end
37
+
38
+ should 'have the object attribute' do
39
+ assert_equal(test_terrorist_watchlist_search[:object], @terrorist_watchlist_search.object)
40
+ end
41
+
42
+ should 'have the uri attribute' do
43
+ assert_equal(test_terrorist_watchlist_search[:uri], @terrorist_watchlist_search.uri)
44
+ end
45
+
46
+ should 'have the status attribute' do
47
+ assert_equal(test_terrorist_watchlist_search[:status], @terrorist_watchlist_search.status)
48
+ end
49
+
50
+ should 'have the created_at attribute' do
51
+ assert_equal(test_terrorist_watchlist_search[:created_at], @terrorist_watchlist_search.created_at)
52
+ end
53
+
54
+ should 'have the completed_at attribute' do
55
+ assert_equal(test_terrorist_watchlist_search[:completed_at], @terrorist_watchlist_search.completed_at)
56
+ end
57
+
58
+ should 'have the turnaround_time attribute' do
59
+ assert_equal(test_terrorist_watchlist_search[:turnaround_time], @terrorist_watchlist_search.turnaround_time)
60
+ end
61
+
62
+ should 'have the records attribute' do
63
+ assert_equal(test_terrorist_watchlist_search[:records], @terrorist_watchlist_search.records)
64
+ end
65
+
66
+ end
67
+
68
+ should 'be registered' do
69
+ assert(APIClass.subclasses.include?(TerroristWatchlistSearch))
70
+ assert_equal(TerroristWatchlistSearch, APIClass.subclass_fetch("terrorist_watchlist_search"))
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Checkr
4
+ class UtilTest < Test::Unit::TestCase
5
+ should "symbolize_keys should convert keys to symbols" do
6
+ start = {
7
+ 'foo' => 'bar',
8
+ 'array' => [{ 'foo' => 'bar' }],
9
+ 'nested' => {
10
+ 1 => 2,
11
+ :symbol => 9,
12
+ 'string' => nil
13
+ }
14
+ }
15
+ finish = {
16
+ :foo => 'bar',
17
+ :array => [{ :foo => 'bar' }],
18
+ :nested => {
19
+ 1 => 2,
20
+ :symbol => 9,
21
+ :string => nil
22
+ }
23
+ }
24
+
25
+ symbolized = Util.symbolize_keys(start)
26
+ assert_equal(finish, symbolized)
27
+ end
28
+
29
+ should 'query_array should convert { :a => "value" } to []' do
30
+ start = { :a => "value" }
31
+ finish = ["a=value"]
32
+
33
+ assert_equal(finish, Util.query_array(start))
34
+ end
35
+
36
+ should 'query_array should convert { :a => { :b => { :c => "cvalue" } } } to ["a[b][c]=cvalue"]' do
37
+ start = { :a => { :b => { :c => "cvalue" } } }
38
+ finish = ["a[b][c]=cvalue"]
39
+
40
+ assert_equal(finish, Util.query_array(start))
41
+ end
42
+
43
+ should 'query_array should convert { :a => [1, 2] } to ["a[]=1", "a[]=2"]' do
44
+ start = { :a => [1, 2] }
45
+ finish = ["a[]=1", "a[]=2"]
46
+
47
+ assert_equal(finish, Util.query_array(start))
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,88 @@
1
+ # Setup a fake resource for testing the APIResource
2
+
3
+ class NestedResource < Checkr::APIResource
4
+ attribute :price
5
+
6
+ def self.path
7
+ "/nested_resources"
8
+ end
9
+ end
10
+
11
+ class NestedWithParent < Checkr::APIResource
12
+ attribute :price
13
+ attr_accessor :parent
14
+
15
+ def self.construct(json, parent=nil)
16
+ instance = super(json)
17
+ instance.parent = parent if parent
18
+ instance.clear_changed_attributes
19
+ instance
20
+ end
21
+
22
+ def path
23
+ parent.path + "/nested_path"
24
+ end
25
+ end
26
+
27
+ class MockResource < Checkr::APIResource
28
+ attribute :name
29
+ attribute :tarray
30
+ attribute :thash
31
+ attribute :nested, NestedResource
32
+ attribute :nested_alt, :NestedResource
33
+ attribute_writer_alias :nested_alt_id, :nested_alt
34
+ attribute :nested_with, :NestedWithParent, :nested => true, :default => {}
35
+
36
+ api_class_method :retrieve, :get, ":path/:id", :arguments => [:id]
37
+ api_class_method :all, :get, :constructor => Checkr::APIList.constructor(MockResource)
38
+ api_class_method :create, :post
39
+ api_class_method :many_args_get, :get, ":path/:b/many", :arguments => [:a, :b, :c]
40
+ api_class_method :many_args_post, :post, ":path/:b/many", :arguments => [:a, :b, :c]
41
+ api_class_method :crazy_path, :get, ":crazy"
42
+
43
+ api_class_method :with_con_self, :get, :constructor => :self
44
+ api_class_method :with_con_class, :get, :constructor => MockResource
45
+ api_class_method :with_con_lambda, :get, :constructor => lambda{ |json| "lamdba result" }
46
+ api_class_method :with_con_default, :get
47
+
48
+ def self.default_lambda
49
+ lambda do |this|
50
+ self.default_values
51
+ end
52
+ end
53
+ api_class_method :with_lambda, :post, :default_params => self.default_lambda
54
+ api_class_method :with_symbol, :post, :default_params => :default_values
55
+ api_class_method :with_symbol_and_args, :post, :default_params => :default_values, :arguments => [:name]
56
+
57
+ api_instance_method :refresh, :get, :constructor => :self
58
+ api_instance_method :save, :put, :default_params => changed_lambda, :constructor => :self
59
+ api_instance_method :delete, :delete
60
+ api_instance_method :custom_path, :get, ":path", :arguments => [:path]
61
+ api_instance_method :name_path, :get, ":name"
62
+ api_instance_method :crazy_path, :get, ":crazy"
63
+
64
+ api_instance_method :with_con_self, :get, :constructor => :self
65
+ api_instance_method :with_con_class, :get, :constructor => MockResource
66
+ api_instance_method :with_con_lambda, :get, :constructor => lambda{ |json| "lamdba result" }
67
+ api_instance_method :with_con_default, :get
68
+
69
+ api_instance_method :with_lambda, :put, :default_params => changed_lambda
70
+ api_instance_method :with_symbol, :put, :default_params => :changed_attributes
71
+ api_instance_method :with_symbol_and_args, :put, :default_params => :changed_attributes, :arguments => [:name]
72
+
73
+ def self.path
74
+ "/mocks"
75
+ end
76
+
77
+ def self.crazy
78
+ "/crazy_path"
79
+ end
80
+
81
+ def self.default_values
82
+ {
83
+ :name => "default name",
84
+ :tarray => [1,2,3]
85
+ }
86
+ end
87
+
88
+ end