blockscore 1.0.1 → 2.0.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.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/Gemfile.lock +3 -3
- data/README.md +16 -77
- data/VERSION +1 -1
- data/blockscore.gemspec +18 -8
- data/lib/blockscore/client.rb +25 -24
- data/lib/blockscore/error/authorization_error.rb +12 -0
- data/lib/blockscore/error/blockscore_error.rb +25 -0
- data/lib/blockscore/error/error_handler.rb +141 -0
- data/lib/blockscore/error/internal_server_error.rb +18 -0
- data/lib/blockscore/error/not_found_error.rb +11 -0
- data/lib/blockscore/error/parameter_error.rb +12 -0
- data/lib/blockscore/error/validation_error.rb +27 -0
- data/lib/blockscore/errors.rb +3 -0
- data/lib/blockscore/question_set.rb +57 -0
- data/lib/blockscore/verification.rb +46 -0
- data/test/test_blockscore.rb +57 -23
- metadata +30 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4f61e8c610b55b1f1ddcceaee471a43ff801f5b6
|
|
4
|
+
data.tar.gz: 1bf303c4c529a8b938c6585f57f2270d83cae4a7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 35faf5f2d4491efe6bb94fa84403302be778fc31725744a6b8b190dcfb66c807462f41368ea10f1316c7694e3dd3a6076d92568f0b937a6f417154c95c93a84b
|
|
7
|
+
data.tar.gz: 7d80af18289d119a535c85756486fbfddeba67e0a9ef8ad8a1c8f11c6312686d90f3c0106bdd2e7d8c6218c73a318f33de602c1ba887eaa26c0e296b641e54eb
|
data/Gemfile
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
source "
|
|
1
|
+
source "https://rubygems.org"
|
|
2
2
|
# Add dependencies required to use your gem here.
|
|
3
3
|
# Example:
|
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
|
5
5
|
|
|
6
|
-
gem
|
|
6
|
+
gem 'httparty', '~> 0.13.1'
|
|
7
7
|
|
|
8
8
|
# Add dependencies to develop your gem here.
|
|
9
9
|
# Include everything needed to run rake, tests, features, etc.
|
data/Gemfile.lock
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
GEM
|
|
2
|
-
remote:
|
|
2
|
+
remote: https://rubygems.org/
|
|
3
3
|
specs:
|
|
4
4
|
activesupport (4.0.3)
|
|
5
5
|
i18n (~> 0.6, >= 0.6.4)
|
|
@@ -25,7 +25,7 @@ GEM
|
|
|
25
25
|
oauth2
|
|
26
26
|
hashie (2.0.5)
|
|
27
27
|
highline (1.6.20)
|
|
28
|
-
httparty (0.13.
|
|
28
|
+
httparty (0.13.1)
|
|
29
29
|
json (~> 1.8)
|
|
30
30
|
multi_xml (>= 0.5.2)
|
|
31
31
|
i18n (0.6.9)
|
|
@@ -78,7 +78,7 @@ PLATFORMS
|
|
|
78
78
|
|
|
79
79
|
DEPENDENCIES
|
|
80
80
|
bundler (~> 1.0)
|
|
81
|
-
httparty (~> 0.13.
|
|
81
|
+
httparty (~> 0.13.1)
|
|
82
82
|
jeweler (~> 2.0.1)
|
|
83
83
|
rdoc (~> 3.12)
|
|
84
84
|
shoulda
|
data/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Via rubygems.org:
|
|
|
10
10
|
gem install blockscore
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
If you are using
|
|
13
|
+
If you are using Rails, add the following to your `Gemfile`:
|
|
14
14
|
|
|
15
15
|
```ruby
|
|
16
16
|
gem 'blockscore', '~> 1.0.1'
|
|
@@ -18,91 +18,30 @@ gem 'blockscore', '~> 1.0.1'
|
|
|
18
18
|
|
|
19
19
|
## Getting Started
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
To get started, you can initialize the library with one line:
|
|
22
22
|
|
|
23
23
|
```ruby
|
|
24
|
-
|
|
24
|
+
client = BlockScore::Client.new('your-api-key', version = 2)
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
### List all verifications
|
|
27
|
+
To see the list of calls you can make, please visit out [full Ruby API reference](http://docs.blockscore.com/ruby).
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
@blockscore.verifications
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### View a verification by ID
|
|
36
|
-
|
|
37
|
-
```ruby
|
|
38
|
-
@blockscore.verification("526781407e7b0ace47000001")
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### Create a new verification
|
|
42
|
-
|
|
43
|
-
```ruby
|
|
44
|
-
@blockscore.create_verification({
|
|
45
|
-
type: "us_citizen",
|
|
46
|
-
date_of_birth: "1993-08-23",
|
|
47
|
-
identification: {
|
|
48
|
-
ssn: "0000"
|
|
49
|
-
},
|
|
50
|
-
name: {
|
|
51
|
-
first: "Alain",
|
|
52
|
-
middle: nil,
|
|
53
|
-
last: "Meier"
|
|
54
|
-
},
|
|
55
|
-
address: {
|
|
56
|
-
street1: "1 Infinite Loop",
|
|
57
|
-
street2: nil,
|
|
58
|
-
city: "Cupertino",
|
|
59
|
-
state: "CA",
|
|
60
|
-
postal_code: "95014",
|
|
61
|
-
country: "US"
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
```
|
|
29
|
+
## Exceptions and Errors
|
|
65
30
|
|
|
66
|
-
|
|
31
|
+
### Error Description
|
|
67
32
|
|
|
68
|
-
|
|
33
|
+
* The generic error class is BlockscoreError. All other types of errors are derived from BlockscoreError.
|
|
34
|
+
* Errors contain information such as the HTTP response code, a short message describing the error, the type of error, and if applicable, the parameter and error code at issue.
|
|
35
|
+
* Also available in the error object is the full JSON text representation of the data.
|
|
69
36
|
|
|
70
|
-
|
|
71
|
-
@blockscore.create_question_set({
|
|
72
|
-
verification_id: "53099a636274639ebb0e0000"
|
|
73
|
-
})
|
|
74
|
-
```
|
|
37
|
+
### Error Types
|
|
75
38
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
answers: [
|
|
83
|
-
{
|
|
84
|
-
question_id: 1,
|
|
85
|
-
answer_id: 1
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
question_id: 2,
|
|
89
|
-
answer_id: 1
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
question_id: 3,
|
|
93
|
-
answer_id: 1
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
question_id: 4,
|
|
97
|
-
answer_id: 1
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
question_id: 5,
|
|
101
|
-
answer_id: 1
|
|
102
|
-
}
|
|
103
|
-
]
|
|
104
|
-
})
|
|
105
|
-
```
|
|
39
|
+
* BlockscoreError (Generic error, base class)
|
|
40
|
+
* AuthenticationError (401 : Invalid API Key)
|
|
41
|
+
* ValidationError (400 : Input could not be validated)
|
|
42
|
+
* ParameterError (400 : Missing parameter)
|
|
43
|
+
* NotFoundError (404 : Attempting to reference nonexistent endpoint)
|
|
44
|
+
* InternalServerError (500 : Error on the Blockscore API)
|
|
106
45
|
|
|
107
46
|
## Contributing to BlockScore
|
|
108
47
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
2.0.0
|
data/blockscore.gemspec
CHANGED
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
|
-
# stub: blockscore
|
|
5
|
+
# stub: blockscore 2.0.0 ruby lib
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |s|
|
|
8
8
|
s.name = "blockscore"
|
|
9
|
-
s.version = "
|
|
9
|
+
s.version = "2.0.0"
|
|
10
10
|
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
12
|
+
s.require_paths = ["lib"]
|
|
12
13
|
s.authors = ["Alain Meier"]
|
|
13
|
-
s.date = "2014-
|
|
14
|
+
s.date = "2014-06-15"
|
|
14
15
|
s.description = "A ruby client library for the BlockScore API."
|
|
15
16
|
s.email = "alain@blockscore.com"
|
|
16
17
|
s.extra_rdoc_files = [
|
|
@@ -30,27 +31,36 @@ Gem::Specification.new do |s|
|
|
|
30
31
|
"lib/blockscore-cert.crt",
|
|
31
32
|
"lib/blockscore.rb",
|
|
32
33
|
"lib/blockscore/client.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/question_set.rb",
|
|
43
|
+
"lib/blockscore/verification.rb",
|
|
33
44
|
"test/helper.rb",
|
|
34
45
|
"test/test_blockscore.rb"
|
|
35
46
|
]
|
|
36
47
|
s.homepage = "http://github.com/blockscore/blockscore-ruby"
|
|
37
48
|
s.licenses = ["MIT"]
|
|
38
|
-
s.
|
|
39
|
-
s.rubygems_version = "2.1.11"
|
|
49
|
+
s.rubygems_version = "2.2.2"
|
|
40
50
|
s.summary = "A ruby client library for the BlockScore API."
|
|
41
51
|
|
|
42
52
|
if s.respond_to? :specification_version then
|
|
43
53
|
s.specification_version = 4
|
|
44
54
|
|
|
45
55
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
46
|
-
s.add_runtime_dependency(%q<httparty>, ["~> 0.13.
|
|
56
|
+
s.add_runtime_dependency(%q<httparty>, ["~> 0.13.1"])
|
|
47
57
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
|
48
58
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
|
49
59
|
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
|
50
60
|
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
|
51
61
|
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
|
52
62
|
else
|
|
53
|
-
s.add_dependency(%q<httparty>, ["~> 0.13.
|
|
63
|
+
s.add_dependency(%q<httparty>, ["~> 0.13.1"])
|
|
54
64
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
|
55
65
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
|
56
66
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
|
@@ -58,7 +68,7 @@ Gem::Specification.new do |s|
|
|
|
58
68
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
|
59
69
|
end
|
|
60
70
|
else
|
|
61
|
-
s.add_dependency(%q<httparty>, ["~> 0.13.
|
|
71
|
+
s.add_dependency(%q<httparty>, ["~> 0.13.1"])
|
|
62
72
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
|
63
73
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
|
64
74
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
data/lib/blockscore/client.rb
CHANGED
|
@@ -5,9 +5,16 @@ module BlockScore
|
|
|
5
5
|
@ssl_path = File.expand_path(File.join(File.dirname(__FILE__), '../blockscore-cert.crt'))
|
|
6
6
|
ssl_ca_file @ssl_path
|
|
7
7
|
|
|
8
|
+
attr_reader :verification
|
|
9
|
+
attr_reader :question_set
|
|
10
|
+
|
|
8
11
|
def initialize(api_key, version, options = {})
|
|
12
|
+
|
|
9
13
|
@api_key = api_key
|
|
10
14
|
@auth = { username: @api_key, password: "" }
|
|
15
|
+
@verification = BlockScore::Verification.new(self)
|
|
16
|
+
@question_set = BlockScore::QuestionSet.new(self)
|
|
17
|
+
@error_handler = BlockScore::ErrorHandler.new
|
|
11
18
|
|
|
12
19
|
options[:base_uri] ||= "https://api.blockscore.com"
|
|
13
20
|
options[:headers] = { 'Accept' => 'application/vnd.blockscore+json;version=' + version.to_s }
|
|
@@ -17,39 +24,33 @@ module BlockScore
|
|
|
17
24
|
end
|
|
18
25
|
end
|
|
19
26
|
|
|
20
|
-
def
|
|
21
|
-
self.get '/verifications'
|
|
22
|
-
end
|
|
27
|
+
def get(path, options = {})
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
self.get '/verifications/' + id.to_s
|
|
26
|
-
end
|
|
29
|
+
options = { body: options, basic_auth: @auth }
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
self.post '/verifications/', options
|
|
30
|
-
end
|
|
31
|
+
response = self.class.get(path, options)
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
begin
|
|
34
|
+
result = @error_handler.check_error(response)
|
|
35
|
+
rescue BlockScore::BlockscoreError => e
|
|
36
|
+
raise
|
|
37
|
+
end
|
|
35
38
|
|
|
36
|
-
def create_question_set(options = {})
|
|
37
|
-
self.post '/questions/', options
|
|
38
39
|
end
|
|
39
40
|
|
|
40
|
-
def
|
|
41
|
-
self.post '/questions/score', options
|
|
42
|
-
end
|
|
41
|
+
def post(path, options = {})
|
|
43
42
|
|
|
44
|
-
def get(path, options = {})
|
|
45
43
|
options = { body: options, basic_auth: @auth }
|
|
46
|
-
puts options
|
|
47
|
-
self.class.get(path, options)
|
|
48
|
-
end
|
|
49
44
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
response = self.class.post(path, options)
|
|
46
|
+
|
|
47
|
+
begin
|
|
48
|
+
result = @error_handler.check_error(response)
|
|
49
|
+
rescue BlockScore::BlockscoreError => e
|
|
50
|
+
raise
|
|
51
|
+
end
|
|
52
|
+
|
|
53
53
|
end
|
|
54
|
+
|
|
54
55
|
end
|
|
55
56
|
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require_relative './blockscore_error'
|
|
2
|
+
module BlockScore
|
|
3
|
+
class AuthorizationError < BlockscoreError
|
|
4
|
+
|
|
5
|
+
@@http_status = 401
|
|
6
|
+
|
|
7
|
+
def initialize(message=nil, json_body=nil, error_type=nil)
|
|
8
|
+
|
|
9
|
+
super(message, json_body, @@http_status, error_type)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module BlockScore
|
|
2
|
+
class BlockscoreError < StandardError
|
|
3
|
+
|
|
4
|
+
attr_reader :message
|
|
5
|
+
attr_reader :error_type
|
|
6
|
+
attr_reader :http_status
|
|
7
|
+
attr_reader :json_body
|
|
8
|
+
|
|
9
|
+
def initialize(message=nil, json_body=nil, http_status="400",
|
|
10
|
+
error_type="invalid_request_error")
|
|
11
|
+
super(message)
|
|
12
|
+
|
|
13
|
+
@message = message
|
|
14
|
+
@error_type = error_type
|
|
15
|
+
@http_status = http_status
|
|
16
|
+
@json_body = json_body
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def to_s
|
|
21
|
+
"Status: #{@http_status}. Type: #{@error_type}, Message: #{@message}"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
module BlockScore
|
|
3
|
+
class ErrorHandler
|
|
4
|
+
|
|
5
|
+
def initialize()
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Function:
|
|
9
|
+
# check_error()
|
|
10
|
+
#
|
|
11
|
+
# response -
|
|
12
|
+
#
|
|
13
|
+
def check_error(response)
|
|
14
|
+
|
|
15
|
+
@code = response.code
|
|
16
|
+
@type = response.headers['content-type']
|
|
17
|
+
|
|
18
|
+
if (200 <= @code and @code < 300)
|
|
19
|
+
return response
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
@body = get_body(response)
|
|
23
|
+
@message = get_message(@body)
|
|
24
|
+
@error_type = @error_code = @param = nil
|
|
25
|
+
|
|
26
|
+
# Internal API Error
|
|
27
|
+
if @code == 500
|
|
28
|
+
raise BlockScore::InternalServerError.new(@message, @body, @error_type)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
if @body.include? 'error'
|
|
32
|
+
@error = @body['error']
|
|
33
|
+
@error_type = get_value(@error, 'type')
|
|
34
|
+
@error_code = get_value(@error, 'code')
|
|
35
|
+
@param = get_value(@error, 'param')
|
|
36
|
+
end # body.include? 'error'
|
|
37
|
+
|
|
38
|
+
process_code(@code)
|
|
39
|
+
|
|
40
|
+
end # check_error
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# Function:
|
|
44
|
+
# process_code()
|
|
45
|
+
#
|
|
46
|
+
# Tries to determine which error to raise.
|
|
47
|
+
#
|
|
48
|
+
# code -
|
|
49
|
+
#
|
|
50
|
+
def process_code(code)
|
|
51
|
+
|
|
52
|
+
# Input data error
|
|
53
|
+
if code == 400
|
|
54
|
+
# Could not be validated.
|
|
55
|
+
# Which type of input error?
|
|
56
|
+
if @param
|
|
57
|
+
raise BlockScore::ValidationError.new(@message, @body, @error_type, @param, @error_code)
|
|
58
|
+
|
|
59
|
+
# Required parameter is missing
|
|
60
|
+
else
|
|
61
|
+
raise BlockScore::ParameterError.new(@message, @body, @error_type)
|
|
62
|
+
end # if param
|
|
63
|
+
|
|
64
|
+
# Error with an API Key
|
|
65
|
+
elsif code == 401
|
|
66
|
+
raise BlockScore::AuthorizationError.new(@message, @body, @error_type)
|
|
67
|
+
|
|
68
|
+
# Trying to access nonexistent endpoint
|
|
69
|
+
elsif code == 404
|
|
70
|
+
raise BlockScore::NotFoundError.new(@message, @body, @error_type)
|
|
71
|
+
|
|
72
|
+
# Generic BlockscoreError (fallback)
|
|
73
|
+
else
|
|
74
|
+
raise BlockScore::BlockscoreError.new(@message, @body)
|
|
75
|
+
|
|
76
|
+
end # end code checking
|
|
77
|
+
|
|
78
|
+
end # process code
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
# Function:
|
|
83
|
+
# get_body()
|
|
84
|
+
#
|
|
85
|
+
# response -
|
|
86
|
+
#
|
|
87
|
+
def get_body(response)
|
|
88
|
+
type = response.headers['content-type']
|
|
89
|
+
body = response.body
|
|
90
|
+
|
|
91
|
+
# If response body is in JSON
|
|
92
|
+
if type.include? 'json'
|
|
93
|
+
body = JSON.parse(body)
|
|
94
|
+
end # type.include?
|
|
95
|
+
|
|
96
|
+
body
|
|
97
|
+
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# Function:
|
|
102
|
+
# get_message()
|
|
103
|
+
#
|
|
104
|
+
# body -
|
|
105
|
+
#
|
|
106
|
+
def get_message(body)
|
|
107
|
+
message = ''
|
|
108
|
+
if body.is_a? String
|
|
109
|
+
message = body
|
|
110
|
+
|
|
111
|
+
elsif body.is_a? Hash
|
|
112
|
+
if body.include? 'error'
|
|
113
|
+
message = body['error']['message']
|
|
114
|
+
else
|
|
115
|
+
message = 'Unable to select error message from json returned by request responsible for error'
|
|
116
|
+
end # if body.include?
|
|
117
|
+
else
|
|
118
|
+
message = 'Unable to understand the content type of response returned by request responsible for error'
|
|
119
|
+
end # if body.is_a? String
|
|
120
|
+
|
|
121
|
+
message
|
|
122
|
+
end # def get_message
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
# Function:
|
|
126
|
+
# get_value()
|
|
127
|
+
#
|
|
128
|
+
# obj -
|
|
129
|
+
# key -
|
|
130
|
+
#
|
|
131
|
+
def get_value(obj, key)
|
|
132
|
+
|
|
133
|
+
if obj.include? key
|
|
134
|
+
return obj[key]
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
nil
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
end # class ErrorHandler
|
|
141
|
+
end # module BlockScore
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require_relative './blockscore_error'
|
|
2
|
+
module BlockScore
|
|
3
|
+
class InternalServerError < BlockscoreError
|
|
4
|
+
|
|
5
|
+
@@http_status = 500
|
|
6
|
+
|
|
7
|
+
def initialize(message=nil, json_body=nil, error_type=nil)
|
|
8
|
+
|
|
9
|
+
super(message, json_body, @@http_status, error_type)
|
|
10
|
+
|
|
11
|
+
@message = message
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def to_s
|
|
15
|
+
"Status: #{@@http_status}, Message: #{@message}"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require_relative './blockscore_error'
|
|
2
|
+
module BlockScore
|
|
3
|
+
class NotFoundError < BlockscoreError
|
|
4
|
+
|
|
5
|
+
@@http_status = 404
|
|
6
|
+
|
|
7
|
+
def initialize(message=nil, json_body=nil, error_type=nil)
|
|
8
|
+
super(message, json_body, @@http_status, error_type)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require_relative './blockscore_error'
|
|
2
|
+
module BlockScore
|
|
3
|
+
class ParameterError < BlockscoreError
|
|
4
|
+
|
|
5
|
+
@@http_status = 400
|
|
6
|
+
|
|
7
|
+
def initialize(message=nil, json_body=nil, error_type=nil)
|
|
8
|
+
|
|
9
|
+
super(message, json_body, @@http_status, error_type)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require_relative './blockscore_error'
|
|
2
|
+
module BlockScore
|
|
3
|
+
class ValidationError < BlockscoreError
|
|
4
|
+
|
|
5
|
+
attr_reader :http_status
|
|
6
|
+
attr_reader :error_code
|
|
7
|
+
attr_reader :param
|
|
8
|
+
|
|
9
|
+
@@http_status = 400
|
|
10
|
+
|
|
11
|
+
def initialize(message=nil, json_body=nil,
|
|
12
|
+
error_type=nil, param=nil, error_code=nil)
|
|
13
|
+
|
|
14
|
+
super(message, json_body, @@http_status, error_type)
|
|
15
|
+
|
|
16
|
+
@error_code = error_code
|
|
17
|
+
@param = param
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def to_s
|
|
22
|
+
s = "Status: #{@@http_status}, Type: #{@error_type}, Param: #{@param}, "
|
|
23
|
+
s += "Code: #{@error_code}, Message: #{@message}"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
module BlockScore
|
|
2
|
+
class QuestionSet
|
|
3
|
+
|
|
4
|
+
def initialize(client)
|
|
5
|
+
@client = client
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def create(verification_id, options = {})
|
|
9
|
+
body = (options.include? :body) ? options[:body] : {}
|
|
10
|
+
body[:verification_id] = verification_id
|
|
11
|
+
|
|
12
|
+
response = @client.post '/questions', body
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
#
|
|
16
|
+
# '/questions/score' POST
|
|
17
|
+
#
|
|
18
|
+
# verification_id -
|
|
19
|
+
# question_set_id -
|
|
20
|
+
# answers -
|
|
21
|
+
def score(verification_id, question_set_id, answers)
|
|
22
|
+
|
|
23
|
+
body = {
|
|
24
|
+
verification_id: verification_id,
|
|
25
|
+
question_set_id: question_set_id,
|
|
26
|
+
answers: answers
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
response = @client.post "/questions/score", body
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
#
|
|
33
|
+
# /questions/:id POST
|
|
34
|
+
#
|
|
35
|
+
# question_set_id -
|
|
36
|
+
# verification_id -
|
|
37
|
+
def retrieve(question_set_id, verification_id)
|
|
38
|
+
body = Hash.new
|
|
39
|
+
body[:verification_id] = verification_id
|
|
40
|
+
|
|
41
|
+
response = @client.post "/questions/#{question_set_id.to_s}", body
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
#
|
|
45
|
+
# '/questions' GET
|
|
46
|
+
#
|
|
47
|
+
def all(count = nil, offset = nil, options = {})
|
|
48
|
+
|
|
49
|
+
body = (options.include? :body) ? options[:body] : {}
|
|
50
|
+
|
|
51
|
+
body[:count] = count
|
|
52
|
+
body[:offset] = offset
|
|
53
|
+
|
|
54
|
+
@client.get '/questions', body
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module BlockScore
|
|
2
|
+
class Verification
|
|
3
|
+
|
|
4
|
+
def initialize(client)
|
|
5
|
+
|
|
6
|
+
@client = client
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
#
|
|
10
|
+
# /verifications POST
|
|
11
|
+
#
|
|
12
|
+
# type -
|
|
13
|
+
# date_of_birth -
|
|
14
|
+
# identification -
|
|
15
|
+
# name -
|
|
16
|
+
# address -
|
|
17
|
+
def create(options = {})
|
|
18
|
+
response = @client.post '/verifications', options
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# /verifications/:id GET
|
|
23
|
+
#
|
|
24
|
+
# id -
|
|
25
|
+
def retrieve(id, options = {})
|
|
26
|
+
|
|
27
|
+
body = (options.include? :query) ? options[:body] : {}
|
|
28
|
+
body[:verification_id] = id
|
|
29
|
+
|
|
30
|
+
response = @client.get "/verifications/#{id.to_s}", body
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
#
|
|
34
|
+
# '/verifications' GET
|
|
35
|
+
#
|
|
36
|
+
def all(count = nil, offset = nil, options = {})
|
|
37
|
+
|
|
38
|
+
body = (options.include? :body) ? options[:body] : {}
|
|
39
|
+
|
|
40
|
+
body[:count] = count
|
|
41
|
+
body[:offset] = offset
|
|
42
|
+
|
|
43
|
+
@client.get '/verifications', body
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
data/test/test_blockscore.rb
CHANGED
|
@@ -1,30 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative './helper'
|
|
2
2
|
|
|
3
3
|
class TestBlockScore < Test::Unit::TestCase
|
|
4
4
|
context "a verification" do
|
|
5
5
|
setup do
|
|
6
|
-
|
|
6
|
+
# If you'd like to run the test suite, fill in your API key,
|
|
7
|
+
# a verification ID and a question set ID below.
|
|
8
|
+
@client = BlockScore::Client.new("Your API key", version = 2)
|
|
9
|
+
|
|
10
|
+
@verification_id = "Your verification ID"
|
|
11
|
+
@question_set_id = "Your question set ID"
|
|
7
12
|
end
|
|
8
13
|
|
|
9
14
|
should "return a list of verifications" do
|
|
10
|
-
|
|
15
|
+
response = @client.verification.all
|
|
16
|
+
assert_equal 200, response.code
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
should "return count = 2 verifications" do
|
|
20
|
+
response = @client.verification.all(count = 2)
|
|
21
|
+
assert_equal 200, response.code
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
should "return count=2 offset=2 verifications" do
|
|
25
|
+
response = @client.verification.all(count = 2, offset = 2)
|
|
26
|
+
assert_equal 200, response.code
|
|
11
27
|
end
|
|
12
28
|
|
|
13
29
|
should "return a single verification" do
|
|
14
|
-
|
|
30
|
+
response = @client.verification.retrieve(@verification_id)
|
|
31
|
+
assert_equal 200, response.code
|
|
15
32
|
end
|
|
16
33
|
|
|
17
34
|
should "return create a verification" do
|
|
18
|
-
|
|
35
|
+
verification_params = {
|
|
19
36
|
type: "us_citizen",
|
|
20
|
-
date_of_birth: "
|
|
37
|
+
date_of_birth: "1975-01-01",
|
|
21
38
|
identification: {
|
|
22
39
|
ssn: "0000"
|
|
23
40
|
},
|
|
24
41
|
name: {
|
|
25
|
-
first: "
|
|
26
|
-
middle:
|
|
27
|
-
last: "
|
|
42
|
+
first: "John",
|
|
43
|
+
middle: "P",
|
|
44
|
+
last: "Doe"
|
|
28
45
|
},
|
|
29
46
|
address: {
|
|
30
47
|
street1: "1 Infinite Loop",
|
|
@@ -36,26 +53,38 @@ class TestBlockScore < Test::Unit::TestCase
|
|
|
36
53
|
}
|
|
37
54
|
}
|
|
38
55
|
|
|
39
|
-
|
|
56
|
+
response = @client.verification.create(verification_params)
|
|
57
|
+
|
|
58
|
+
assert_equal 201, response.code
|
|
40
59
|
end
|
|
41
60
|
|
|
42
61
|
should "return create a question set" do
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
62
|
+
response = @client.question_set.create(@verification_id)
|
|
63
|
+
assert_equal 201, response.code
|
|
64
|
+
end
|
|
46
65
|
|
|
47
|
-
|
|
66
|
+
should "return a single question set" do
|
|
67
|
+
response = @client.question_set.retrieve(@question_set_id, @verification_id)
|
|
68
|
+
assert_equal 201, response.code
|
|
48
69
|
end
|
|
49
70
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
71
|
+
should "return a list of question sets" do
|
|
72
|
+
response = @client.question_set.all
|
|
73
|
+
assert_equal 200, response.code
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
should "return count = 2 question sets" do
|
|
77
|
+
response = @client.question_set.all(count = 2)
|
|
78
|
+
assert_equal 200, response.code
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
should "return count = 2 offset = 2 question sets" do
|
|
82
|
+
response = @client.question_set.all(count = 2, offset = 2)
|
|
83
|
+
assert_equal 200, response.code
|
|
84
|
+
end
|
|
53
85
|
|
|
54
86
|
should "return a score for the question set" do
|
|
55
|
-
@
|
|
56
|
-
verification_id: "53099a636274639ebb0e0000",
|
|
57
|
-
question_set_id: "53099c5f6274639ebb7e0000",
|
|
58
|
-
answers: [
|
|
87
|
+
@answers = [
|
|
59
88
|
{
|
|
60
89
|
question_id: 1,
|
|
61
90
|
answer_id: 1
|
|
@@ -77,9 +106,14 @@ class TestBlockScore < Test::Unit::TestCase
|
|
|
77
106
|
answer_id: 1
|
|
78
107
|
}
|
|
79
108
|
]
|
|
80
|
-
}
|
|
81
109
|
|
|
82
|
-
|
|
110
|
+
response = @client.question_set.score(
|
|
111
|
+
@verification_id,
|
|
112
|
+
@question_set_id,
|
|
113
|
+
@answers
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
assert_equal 201, response.code
|
|
83
117
|
end
|
|
84
118
|
end
|
|
85
119
|
end
|
metadata
CHANGED
|
@@ -1,97 +1,97 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: blockscore
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alain Meier
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-06-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httparty
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - ~>
|
|
17
|
+
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 0.13.
|
|
19
|
+
version: 0.13.1
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - ~>
|
|
24
|
+
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 0.13.
|
|
26
|
+
version: 0.13.1
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: shoulda
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- -
|
|
31
|
+
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: '0'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- -
|
|
38
|
+
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: rdoc
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- - ~>
|
|
45
|
+
- - "~>"
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
47
|
version: '3.12'
|
|
48
48
|
type: :development
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- - ~>
|
|
52
|
+
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '3.12'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: bundler
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
|
-
- - ~>
|
|
59
|
+
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
61
|
version: '1.0'
|
|
62
62
|
type: :development
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
|
-
- - ~>
|
|
66
|
+
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '1.0'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: jeweler
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements:
|
|
73
|
-
- - ~>
|
|
73
|
+
- - "~>"
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
75
|
version: 2.0.1
|
|
76
76
|
type: :development
|
|
77
77
|
prerelease: false
|
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
79
|
requirements:
|
|
80
|
-
- - ~>
|
|
80
|
+
- - "~>"
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: 2.0.1
|
|
83
83
|
- !ruby/object:Gem::Dependency
|
|
84
84
|
name: simplecov
|
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements:
|
|
87
|
-
- -
|
|
87
|
+
- - ">="
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
89
|
version: '0'
|
|
90
90
|
type: :development
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
|
-
- -
|
|
94
|
+
- - ">="
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
96
|
version: '0'
|
|
97
97
|
description: A ruby client library for the BlockScore API.
|
|
@@ -102,7 +102,7 @@ extra_rdoc_files:
|
|
|
102
102
|
- LICENSE.txt
|
|
103
103
|
- README.md
|
|
104
104
|
files:
|
|
105
|
-
- .document
|
|
105
|
+
- ".document"
|
|
106
106
|
- Gemfile
|
|
107
107
|
- Gemfile.lock
|
|
108
108
|
- LICENSE.txt
|
|
@@ -114,6 +114,16 @@ files:
|
|
|
114
114
|
- lib/blockscore-cert.crt
|
|
115
115
|
- lib/blockscore.rb
|
|
116
116
|
- lib/blockscore/client.rb
|
|
117
|
+
- lib/blockscore/error/authorization_error.rb
|
|
118
|
+
- lib/blockscore/error/blockscore_error.rb
|
|
119
|
+
- lib/blockscore/error/error_handler.rb
|
|
120
|
+
- lib/blockscore/error/internal_server_error.rb
|
|
121
|
+
- lib/blockscore/error/not_found_error.rb
|
|
122
|
+
- lib/blockscore/error/parameter_error.rb
|
|
123
|
+
- lib/blockscore/error/validation_error.rb
|
|
124
|
+
- lib/blockscore/errors.rb
|
|
125
|
+
- lib/blockscore/question_set.rb
|
|
126
|
+
- lib/blockscore/verification.rb
|
|
117
127
|
- test/helper.rb
|
|
118
128
|
- test/test_blockscore.rb
|
|
119
129
|
homepage: http://github.com/blockscore/blockscore-ruby
|
|
@@ -126,17 +136,17 @@ require_paths:
|
|
|
126
136
|
- lib
|
|
127
137
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
138
|
requirements:
|
|
129
|
-
- -
|
|
139
|
+
- - ">="
|
|
130
140
|
- !ruby/object:Gem::Version
|
|
131
141
|
version: '0'
|
|
132
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
143
|
requirements:
|
|
134
|
-
- -
|
|
144
|
+
- - ">="
|
|
135
145
|
- !ruby/object:Gem::Version
|
|
136
146
|
version: '0'
|
|
137
147
|
requirements: []
|
|
138
148
|
rubyforge_project:
|
|
139
|
-
rubygems_version: 2.
|
|
149
|
+
rubygems_version: 2.2.2
|
|
140
150
|
signing_key:
|
|
141
151
|
specification_version: 4
|
|
142
152
|
summary: A ruby client library for the BlockScore API.
|