blockscore 4.0.0 → 4.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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +58 -0
  3. data/.hound.yml +217 -0
  4. data/Gemfile +19 -7
  5. data/LICENSE +21 -0
  6. data/README.md +37 -33
  7. data/Rakefile +1 -15
  8. data/blockscore.gemspec +30 -81
  9. data/circle.yml +13 -0
  10. data/lib/blockscore.rb +43 -4
  11. data/lib/blockscore/actions/all.rb +27 -0
  12. data/lib/blockscore/actions/create.rb +34 -0
  13. data/lib/blockscore/actions/delete.rb +31 -0
  14. data/lib/blockscore/actions/retrieve.rb +24 -0
  15. data/lib/blockscore/actions/update.rb +46 -0
  16. data/lib/blockscore/base.rb +117 -0
  17. data/lib/blockscore/candidate.rb +32 -0
  18. data/lib/blockscore/collection.rb +12 -0
  19. data/lib/blockscore/company.rb +7 -0
  20. data/lib/blockscore/connection.rb +65 -0
  21. data/lib/blockscore/dispatch.rb +26 -0
  22. data/lib/blockscore/errors/api_connection_error.rb +6 -0
  23. data/lib/blockscore/errors/api_error.rb +33 -0
  24. data/lib/blockscore/errors/authentication_error.rb +4 -0
  25. data/lib/blockscore/errors/error.rb +4 -0
  26. data/lib/blockscore/errors/invalid_request_error.rb +29 -0
  27. data/lib/blockscore/errors/no_api_key_error.rb +4 -0
  28. data/lib/blockscore/errors/not_found_error.rb +4 -0
  29. data/lib/blockscore/fingerprint.rb +46 -0
  30. data/lib/blockscore/person.rb +14 -0
  31. data/lib/blockscore/question_set.rb +26 -0
  32. data/lib/blockscore/response.rb +29 -0
  33. data/lib/blockscore/util.rb +80 -0
  34. data/lib/blockscore/version.rb +3 -0
  35. data/lib/blockscore/watchlist_hit.rb +4 -0
  36. metadata +82 -48
  37. data/LICENSE.txt +0 -20
  38. data/VERSION +0 -1
  39. data/blockscore-ruby.sublime-project +0 -21
  40. data/lib/blockscore/candidates.rb +0 -49
  41. data/lib/blockscore/client.rb +0 -81
  42. data/lib/blockscore/companies.rb +0 -36
  43. data/lib/blockscore/error/authorization_error.rb +0 -13
  44. data/lib/blockscore/error/blockscore_error.rb +0 -26
  45. data/lib/blockscore/error/error_handler.rb +0 -141
  46. data/lib/blockscore/error/internal_server_error.rb +0 -19
  47. data/lib/blockscore/error/not_found_error.rb +0 -12
  48. data/lib/blockscore/error/parameter_error.rb +0 -12
  49. data/lib/blockscore/error/validation_error.rb +0 -28
  50. data/lib/blockscore/errors.rb +0 -3
  51. data/lib/blockscore/people.rb +0 -37
  52. data/lib/blockscore/question_sets.rb +0 -49
  53. data/lib/blockscore/watchlists.rb +0 -18
  54. data/test/helper.rb +0 -37
  55. data/test/test_blockscore.rb +0 -226
@@ -1,86 +1,35 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
- # stub: blockscore 4.0.0 ruby lib
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
4
 
7
- Gem::Specification.new do |s|
8
- s.name = "blockscore"
9
- s.version = "4.0.0"
5
+ require 'blockscore/version'
10
6
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
- s.authors = ["Alain Meier"]
14
- s.date = "2014-11-17"
15
- s.description = "A ruby client library for the BlockScore API."
16
- s.email = "alain@blockscore.com"
17
- s.extra_rdoc_files = [
18
- "LICENSE.txt",
19
- "README.md"
20
- ]
21
- s.files = [
22
- ".document",
23
- "Gemfile",
24
- "LICENSE.txt",
25
- "README.md",
26
- "Rakefile",
27
- "VERSION",
28
- "blockscore-ruby.sublime-project",
29
- "blockscore.gemspec",
30
- "lib/blockscore.rb",
31
- "lib/blockscore/candidates.rb",
32
- "lib/blockscore/client.rb",
33
- "lib/blockscore/companies.rb",
34
- "lib/blockscore/error/authorization_error.rb",
35
- "lib/blockscore/error/blockscore_error.rb",
36
- "lib/blockscore/error/error_handler.rb",
37
- "lib/blockscore/error/internal_server_error.rb",
38
- "lib/blockscore/error/not_found_error.rb",
39
- "lib/blockscore/error/parameter_error.rb",
40
- "lib/blockscore/error/validation_error.rb",
41
- "lib/blockscore/errors.rb",
42
- "lib/blockscore/people.rb",
43
- "lib/blockscore/question_sets.rb",
44
- "lib/blockscore/watchlists.rb",
45
- "test/helper.rb",
46
- "test/test_blockscore.rb"
47
- ]
48
- s.homepage = "http://github.com/blockscore/blockscore-ruby"
49
- s.licenses = ["MIT"]
50
- s.rubygems_version = "2.2.2"
51
- s.summary = "A ruby client library for the BlockScore API."
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'blockscore'
9
+ spec.version = BlockScore::VERSION
10
+ spec.authors = ['Alain Meier', 'John Backus', 'Connor Jacobsen']
11
+ spec.email = ['alain@blockscore.com', 'john@blockscore.com']
52
12
 
53
- if s.respond_to? :specification_version then
54
- s.specification_version = 4
13
+ spec.summary = 'A ruby client library for the BlockScore API.'
14
+ spec.description = 'BlockScore makes ID verification easier and faster. See https://blockscore.com for more.'
15
+ spec.homepage = 'https://blockscore.com'
16
+ spec.license = 'MIT'
55
17
 
56
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
- s.add_runtime_dependency(%q<httparty>, ["~> 0.11"])
58
- s.add_development_dependency(%q<shoulda>, ["~> 3.5.0"])
59
- s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
60
- s.add_development_dependency(%q<bundler>, ["~> 1.0"])
61
- s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
62
- s.add_development_dependency(%q<simplecov>, [">= 0"])
63
- s.add_development_dependency(%q<minitest>, ["~> 4.0"])
64
- s.add_development_dependency(%q<shoulda-context>, ["~> 1.2"])
65
- else
66
- s.add_dependency(%q<httparty>, ["~> 0.11"])
67
- s.add_dependency(%q<shoulda>, ["~> 3.5.0"])
68
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
69
- s.add_dependency(%q<bundler>, ["~> 1.0"])
70
- s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
71
- s.add_dependency(%q<simplecov>, [">= 0"])
72
- s.add_dependency(%q<minitest>, ["~> 4.0"])
73
- s.add_dependency(%q<shoulda-context>, ["~> 1.2"])
74
- end
75
- else
76
- s.add_dependency(%q<httparty>, ["~> 0.11"])
77
- s.add_dependency(%q<shoulda>, ["~> 3.5.0"])
78
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
79
- s.add_dependency(%q<bundler>, ["~> 1.0"])
80
- s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
81
- s.add_dependency(%q<simplecov>, [">= 0"])
82
- s.add_dependency(%q<minitest>, ["~> 4.0"])
83
- s.add_dependency(%q<shoulda-context>, ["~> 1.2"])
84
- end
85
- end
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.required_ruby_version = '>= 1.9.3'
86
24
 
25
+ spec.add_dependency('httparty', '~> 0.11')
26
+
27
+ spec.add_development_dependency('shoulda', '~> 3.5', '>= 3.5.0')
28
+ spec.add_development_dependency('rdoc', '~> 3.12')
29
+ spec.add_development_dependency('bundler', '~> 1.0')
30
+ spec.add_development_dependency('simplecov', '~> 0')
31
+ spec.add_development_dependency('minitest', '~> 5.5')
32
+ spec.add_development_dependency('webmock', '1.21')
33
+ spec.add_development_dependency('faker', '1.4.3')
34
+ spec.add_development_dependency('factory_girl', '4.1.0')
35
+ end
@@ -0,0 +1,13 @@
1
+ dependencies:
2
+ override:
3
+ - "rvm-exec 1.9.3-p551 bundle install"
4
+ - "rvm-exec 2.0.0-p598 bundle install"
5
+ - "rvm-exec 2.1.5 bundle install"
6
+ - "rvm-exec 2.2.0 bundle install"
7
+
8
+ test:
9
+ override:
10
+ - "rvm-exec 1.9.3-p551 bundle exec rake"
11
+ - "rvm-exec 2.0.0-p598 bundle exec rake"
12
+ - "rvm-exec 2.1.5 bundle exec rake"
13
+ - "rvm-exec 2.2.0 bundle exec rake"
@@ -1,5 +1,44 @@
1
- require "httparty"
1
+ require 'forwardable'
2
+ require 'httparty'
3
+ require 'json'
4
+ require 'ostruct'
5
+ require 'uri'
2
6
 
3
- Dir[File.dirname(__FILE__) + '/blockscore/*.rb'].each do |file|
4
- require file
5
- end
7
+ require 'blockscore/actions/all'
8
+ require 'blockscore/actions/create'
9
+ require 'blockscore/actions/delete'
10
+ require 'blockscore/actions/retrieve'
11
+ require 'blockscore/actions/update'
12
+
13
+ require 'blockscore/errors/api_connection_error'
14
+ require 'blockscore/errors/api_error'
15
+ require 'blockscore/errors/authentication_error'
16
+ require 'blockscore/errors/error'
17
+ require 'blockscore/errors/invalid_request_error'
18
+ require 'blockscore/errors/no_api_key_error'
19
+ require 'blockscore/errors/not_found_error'
20
+
21
+ require 'blockscore/base'
22
+ require 'blockscore/candidate'
23
+ require 'blockscore/company'
24
+ require 'blockscore/person'
25
+ require 'blockscore/question_set'
26
+ require 'blockscore/watchlist_hit'
27
+
28
+ require 'blockscore/collection'
29
+ require 'blockscore/connection'
30
+ require 'blockscore/dispatch'
31
+ require 'blockscore/fingerprint'
32
+ require 'blockscore/response'
33
+ require 'blockscore/util'
34
+ require 'blockscore/version'
35
+
36
+ module BlockScore
37
+ def self.api_key=(api_key)
38
+ @api_key = api_key
39
+ end
40
+
41
+ def self.api_key
42
+ @api_key
43
+ end
44
+ end
@@ -0,0 +1,27 @@
1
+ module BlockScore
2
+ module Actions
3
+ # Public: Provides an :all action to including Classes.
4
+ #
5
+ # The :all method returns up to 25 items from the BlockScore API for
6
+ # the given class.
7
+ #
8
+ # :all accepts an options hash, which responds to the following options:
9
+ #
10
+ # count - Fixnum number of items to return per page.
11
+ # offset - Fixnum number of items to skip before returning @count items.
12
+ #
13
+ # If no count is provided, 25 items are returned, or all items if the total
14
+ # number of items is 25 of fewer.
15
+ module All
16
+ module ClassMethods
17
+ def all(options = {})
18
+ get(endpoint, options)
19
+ end
20
+ end
21
+
22
+ def self.included(base)
23
+ base.extend(ClassMethods)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ module BlockScore
2
+ module Actions
3
+ # Public: Provides a :create class method which creates a new instance
4
+ # of the desired class using the BlockScore API.
5
+ #
6
+ # Examples
7
+ #
8
+ # candidate = BlockScore::Candidate.create(
9
+ # note: "12341234",
10
+ # ssn: "0001",
11
+ # date_of_birth: "1940-08-11",
12
+ # name_first: "John",
13
+ # name_middle: "",
14
+ # name_last: "Bredenkamp",
15
+ # address_street1: "1 Infinite Loop",
16
+ # address_city: "Cupertino",
17
+ # address_country_code: "US"
18
+ # )
19
+ # => <BlockScore::Candidate:0x007fe39c424410>
20
+ #
21
+ # Returns an instance of the desired class.
22
+ module Create
23
+ module ClassMethods
24
+ def create(params = {})
25
+ post(endpoint, params)
26
+ end
27
+ end
28
+
29
+ def self.included(base)
30
+ base.extend(ClassMethods)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,31 @@
1
+ require 'forwardable'
2
+
3
+ module BlockScore
4
+ module Actions
5
+ # Provides a :delete instance method to including classes.
6
+ #
7
+ # Returns the updated object with deleted == true.
8
+ #
9
+ # Examples
10
+ #
11
+ # candidate.delete
12
+ # => #<BlockScore::Candidate:0x007fe39c424410>
13
+ module Delete
14
+ extend Forwardable
15
+
16
+ def_delegators 'self.class', :endpoint
17
+
18
+ def delete
19
+ delete!
20
+ rescue Error
21
+ false
22
+ end
23
+
24
+ def delete!
25
+ self.class.delete("#{endpoint}/#{id}", {})
26
+ attributes[:deleted] = true
27
+ true
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ module BlockScore
2
+ module Actions
3
+ # Public: Provides a :retrieve class method to including classes.
4
+ #
5
+ # Returns a instance of the desired class on success, raises an
6
+ # appropriate error otherwise.
7
+ #
8
+ # Examples
9
+ #
10
+ # person = BlockScore::Person.retrieve('abc123def456')
11
+ # => #<BlockScore::Person:0x007fe39c424410>
12
+ module Retrieve
13
+ module ClassMethods
14
+ def retrieve(id)
15
+ get("#{endpoint}/#{id}", {})
16
+ end
17
+ end
18
+
19
+ def self.included(base)
20
+ base.extend(ClassMethods)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,46 @@
1
+ module BlockScore
2
+ module Actions
3
+ # Public: Contains the :save instance method, which updates the
4
+ # object with the BlockScore API to persist the changes.
5
+ #
6
+ # Examples
7
+ #
8
+ # class Foo
9
+ # include BlockScore::Actions::Update
10
+ # end
11
+ #
12
+ # foo = Foo.new
13
+ # foo.name_first = 'John'
14
+ # foo.save
15
+ # # => true
16
+ module Update
17
+ extend Forwardable
18
+
19
+ # Attributes which will not change once the object is created.
20
+ PERSISTENT_ATTRIBUTES = [
21
+ :id,
22
+ :object,
23
+ :created_at,
24
+ :updated_at,
25
+ :livemode
26
+ ]
27
+
28
+ def_delegators 'self.class', :endpoint, :patch
29
+
30
+ def save!
31
+ if respond_to? :id
32
+ patch("#{endpoint}/#{id}", filter_params)
33
+ true
34
+ else
35
+ super
36
+ end
37
+ end
38
+
39
+ # Filters out the non-updateable params.
40
+ def filter_params
41
+ # Cannot %i syntax, not introduced until Ruby 2.0.0
42
+ attributes.reject { |key, _| PERSISTENT_ATTRIBUTES.include?(key) }
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,117 @@
1
+ require 'blockscore/connection'
2
+
3
+ module BlockScore
4
+ class Base
5
+ extend Connection
6
+
7
+ attr_reader :attributes
8
+
9
+ def initialize(options = {})
10
+ @attributes = options
11
+ end
12
+
13
+ def inspect
14
+ "#<#{self.class}:0x#{object_id.to_s(16)} JSON: " + JSON.pretty_generate(attributes)
15
+ end
16
+
17
+ def refresh
18
+ r = self.class.retrieve(id)
19
+ @attributes = r.attributes
20
+
21
+ true
22
+ rescue Error
23
+ false
24
+ end
25
+
26
+ def save
27
+ save!
28
+ rescue
29
+ false
30
+ end
31
+
32
+ def save!
33
+ response = self.class.post(self.class.endpoint, attributes)
34
+ @attributes[:id] = response.id
35
+
36
+ refresh
37
+ end
38
+
39
+ def self.resource
40
+ @resource ||= Util.to_underscore(to_s.split('::').last)
41
+ end
42
+
43
+ def self.api_url
44
+ 'https://api.blockscore.com/'
45
+ end
46
+
47
+ def self.endpoint
48
+ if self == Base
49
+ fail NotImplementedError, 'Base is an abstract class, not an API resource'
50
+ end
51
+
52
+ "#{api_url}#{Util.to_plural(resource)}"
53
+ end
54
+
55
+ protected
56
+
57
+ def add_accessor(symbol, *args)
58
+ singleton_class.instance_eval do
59
+ define_method(symbol) do
60
+ wrap_attribute(attributes[symbol])
61
+ end
62
+ end
63
+ end
64
+
65
+ def add_setter(symbol, *_args)
66
+ singleton_class.instance_eval do
67
+ define_method(symbol) do |value|
68
+ attributes[symbol.to_s.chop.to_sym] = value
69
+ end
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ def method_missing(method, *args, &block)
76
+ if respond_to_missing?(method)
77
+ if setter?(method)
78
+ add_setter(method, args)
79
+ else
80
+ add_accessor(method, args)
81
+ end
82
+ send(method, *args)
83
+ else
84
+ super
85
+ end
86
+ end
87
+
88
+ def respond_to_missing?(symbol, include_private = false)
89
+ setter?(symbol) || attributes && attributes.key?(symbol) || super
90
+ end
91
+
92
+ def setter?(symbol)
93
+ symbol.to_s.end_with?('=')
94
+ end
95
+
96
+ def wrap_attribute(attribute)
97
+ case attribute
98
+ when Array
99
+ wrap_array(attribute)
100
+ when Hash
101
+ wrap_hash(attribute)
102
+ else
103
+ attribute
104
+ end
105
+ end
106
+
107
+ def wrap_array(arr)
108
+ arr.map { |item| wrap_attribute(item) }
109
+ end
110
+
111
+ def wrap_hash(hsh)
112
+ hsh.each { |key, value| hsh[key] = wrap_attribute(value) }
113
+
114
+ OpenStruct.new(hsh)
115
+ end
116
+ end
117
+ end