blockscore 4.1.2 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Gemfile +0 -37
- data/README.md +2 -2
- data/blockscore.gemspec +1 -0
- data/circle.yml +3 -9
- data/circleci.sh +11 -0
- data/lib/blockscore.rb +4 -6
- data/lib/blockscore/actions/retrieve.rb +4 -2
- data/lib/blockscore/actions/update.rb +1 -1
- data/lib/blockscore/base.rb +30 -10
- data/lib/blockscore/collection.rb +228 -7
- data/lib/blockscore/collection/member.rb +100 -0
- data/lib/blockscore/connection.rb +2 -2
- data/lib/blockscore/errors/api_error.rb +3 -3
- data/lib/blockscore/errors/invalid_request_error.rb +3 -3
- data/lib/blockscore/person.rb +1 -1
- data/lib/blockscore/question_set.rb +1 -8
- data/lib/blockscore/util.rb +8 -8
- data/lib/blockscore/version.rb +2 -2
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31656e876ca18bd6ba1359ba1492353965581e9f
|
4
|
+
data.tar.gz: 0a9bdf94792ba330ec53704244cfa0ad422c3f60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a224c33dceda3aef587dc99c2aab9b88013e90bbd49cee3736642d057609030c9dcd61d0e28d1b7f9dc5caf29994100eeddb17888d7ac84d9850e0b727038da9
|
7
|
+
data.tar.gz: f520cb0f7700a006c914670b9146bfe7ed4c1b4dcff70576eaa78962c5c3498637675b4383e8736a400798374cf21d5da5b621a4b283c3bd46188e1c8af87843
|
data/.gitignore
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
# rcov generated
|
2
3
|
coverage
|
3
4
|
coverage.data
|
@@ -15,7 +16,7 @@ doc
|
|
15
16
|
# jeweler generated
|
16
17
|
pkg
|
17
18
|
|
18
|
-
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
19
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
19
20
|
#
|
20
21
|
# * Create a file at ~/.gitignore
|
21
22
|
# * Include files you want ignored
|
data/Gemfile
CHANGED
@@ -7,40 +7,3 @@ group :test do
|
|
7
7
|
gem 'devtools', github: 'mbj/devtools'
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
11
|
-
group :guard do
|
12
|
-
# Notifications for guard specs
|
13
|
-
gem 'growl', '~> 1.0.3'
|
14
|
-
|
15
|
-
# Filewatcher and runner
|
16
|
-
gem 'guard', '~> 2.12.4'
|
17
|
-
|
18
|
-
# Autorun documentation critic
|
19
|
-
gem 'guard-inch', '~> 0.1'
|
20
|
-
|
21
|
-
# Autogen docs
|
22
|
-
gem 'guard-yard', '~> 2.1'
|
23
|
-
|
24
|
-
# My fork of guard-yardstick which makes the keywords more prominent
|
25
|
-
gem 'guard-yardstick', github: 'backus/guard-yardstick', branch: 'color'
|
26
|
-
|
27
|
-
# Autorun style critic
|
28
|
-
gem 'guard-rubocop', '~> 1.2'
|
29
|
-
|
30
|
-
gem 'rubocop-rspec', '~> 1.3', github: 'nevir/rubocop-rspec'
|
31
|
-
|
32
|
-
# Autorun codesmell critic
|
33
|
-
gem 'guard-reek', '= 0.0.3', github: 'backus/guard-reek'
|
34
|
-
|
35
|
-
# Autorun similar code critic
|
36
|
-
gem 'guard-flay', '= 0.0.3', github: 'backus/guard-flay'
|
37
|
-
|
38
|
-
# Autorun painful code critic
|
39
|
-
gem 'guard-flog', '= 0.0.4', github: 'backus/guard-flog'
|
40
|
-
|
41
|
-
# Autorun specs
|
42
|
-
gem 'guard-rspec', '~> 4.6'
|
43
|
-
|
44
|
-
# rebundle
|
45
|
-
gem 'guard-bundler', '~> 2.1'
|
46
|
-
end
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ gem install blockscore
|
|
13
13
|
If you are using Rails, add the following to your `Gemfile`:
|
14
14
|
|
15
15
|
```ruby
|
16
|
-
gem 'blockscore', '~> 4.
|
16
|
+
gem 'blockscore', '~> 4.2.0'
|
17
17
|
```
|
18
18
|
|
19
19
|
## Getting Started
|
@@ -60,5 +60,5 @@ To see the list of calls you can make, please visit our [full Ruby API reference
|
|
60
60
|
The test suite uses a public BlockScore API key that was created specifically to ease the testing and contribution processes. **Please do not enter personal details for tests.** In order to run the test suite:
|
61
61
|
|
62
62
|
```shell
|
63
|
-
$
|
63
|
+
$ rspec spec
|
64
64
|
```
|
data/blockscore.gemspec
CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency 'bundler', '~> 1.0'
|
30
30
|
spec.add_development_dependency 'simplecov', '~> 0'
|
31
31
|
spec.add_development_dependency 'rspec', '~> 3'
|
32
|
+
spec.add_development_dependency 'rspec-its', '~> 1'
|
32
33
|
spec.add_development_dependency 'webmock', '~> 1.21'
|
33
34
|
spec.add_development_dependency 'faker', '~> 1.4'
|
34
35
|
spec.add_development_dependency 'factory_girl', '~> 4.5'
|
data/circle.yml
CHANGED
@@ -1,13 +1,7 @@
|
|
1
1
|
dependencies:
|
2
2
|
override:
|
3
|
-
-
|
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
|
-
|
3
|
+
- ./circleci.sh build
|
8
4
|
test:
|
9
5
|
override:
|
10
|
-
-
|
11
|
-
|
12
|
-
- "rvm-exec 2.1.5 bundle exec rspec"
|
13
|
-
- "rvm-exec 2.2.0 bundle exec rspec"
|
6
|
+
- ./circleci.sh spec:
|
7
|
+
parallel: true
|
data/circleci.sh
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
RUBY_VERSIONS=(1.9.3-p551 2.0.0-p598 2.1.5 2.2.3)
|
3
|
+
CIRCLE_NODE_RUBY_VERSION="${RUBY_VERSIONS[$CIRCLE_NODE_INDEX]}"
|
4
|
+
|
5
|
+
if [[ "$1" = "build" ]]
|
6
|
+
then
|
7
|
+
rvm-exec $CIRCLE_NODE_RUBY_VERSION bundle install;
|
8
|
+
elif [[ "$1" = "spec" ]]
|
9
|
+
then
|
10
|
+
rvm-exec $CIRCLE_NODE_RUBY_VERSION rspec;
|
11
|
+
fi
|
data/lib/blockscore.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'delegate'
|
1
2
|
require 'forwardable'
|
2
3
|
require 'httparty'
|
3
4
|
require 'json'
|
@@ -26,6 +27,7 @@ require 'blockscore/question_set'
|
|
26
27
|
require 'blockscore/watchlist_hit'
|
27
28
|
|
28
29
|
require 'blockscore/collection'
|
30
|
+
require 'blockscore/collection/member'
|
29
31
|
require 'blockscore/connection'
|
30
32
|
require 'blockscore/dispatch'
|
31
33
|
require 'blockscore/fingerprint'
|
@@ -34,11 +36,7 @@ require 'blockscore/util'
|
|
34
36
|
require 'blockscore/version'
|
35
37
|
|
36
38
|
module BlockScore
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.api_key
|
42
|
-
@api_key
|
39
|
+
class << self
|
40
|
+
attr_accessor :api_key
|
43
41
|
end
|
44
42
|
end
|
@@ -11,8 +11,10 @@ module BlockScore
|
|
11
11
|
# => #<BlockScore::Person:0x007fe39c424410>
|
12
12
|
module Retrieve
|
13
13
|
module ClassMethods
|
14
|
-
def retrieve(id)
|
15
|
-
|
14
|
+
def retrieve(id, options = {})
|
15
|
+
fail ArgumentError if id.empty?
|
16
|
+
req = ->() { get("#{endpoint}/#{id}", options) }
|
17
|
+
new(id: id, &req)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
data/lib/blockscore/base.rb
CHANGED
@@ -4,19 +4,37 @@ module BlockScore
|
|
4
4
|
class Base
|
5
5
|
extend Connection
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def initialize(options = {}, &block)
|
8
|
+
@loaded = !(block)
|
9
|
+
@proc = block
|
10
10
|
@attributes = options
|
11
11
|
end
|
12
12
|
|
13
|
+
def attributes
|
14
|
+
return @attributes if @loaded
|
15
|
+
force!
|
16
|
+
@attributes
|
17
|
+
end
|
18
|
+
|
19
|
+
def force!
|
20
|
+
res = @proc.call
|
21
|
+
@attributes = res.attributes.merge(@attributes)
|
22
|
+
@loaded = true
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def id
|
27
|
+
@attributes.fetch(:id, nil)
|
28
|
+
end
|
29
|
+
|
13
30
|
def inspect
|
14
|
-
|
31
|
+
str_attr = "JSON:#{JSON.pretty_generate(attributes)}"
|
32
|
+
"#<#{self.class}:0x#{object_id.to_s(16)} #{str_attr}>"
|
15
33
|
end
|
16
34
|
|
17
35
|
def refresh
|
18
|
-
|
19
|
-
@attributes =
|
36
|
+
res = self.class.retrieve(id)
|
37
|
+
@attributes = res.attributes
|
20
38
|
|
21
39
|
true
|
22
40
|
rescue Error
|
@@ -45,16 +63,18 @@ module BlockScore
|
|
45
63
|
end
|
46
64
|
|
47
65
|
def self.endpoint
|
48
|
-
|
49
|
-
fail NotImplementedError, 'Base is an abstract class, not an API resource'
|
50
|
-
end
|
66
|
+
fail NotImplementedError, 'Base is an abstract class, not an API resource' if equal?(Base)
|
51
67
|
|
52
68
|
"#{api_url}#{Util.to_plural(resource)}"
|
53
69
|
end
|
54
70
|
|
71
|
+
def persisted?
|
72
|
+
!id.nil?
|
73
|
+
end
|
74
|
+
|
55
75
|
protected
|
56
76
|
|
57
|
-
def add_accessor(symbol, *
|
77
|
+
def add_accessor(symbol, *_args)
|
58
78
|
singleton_class.instance_eval do
|
59
79
|
define_method(symbol) do
|
60
80
|
wrap_attribute(attributes[symbol])
|
@@ -1,18 +1,239 @@
|
|
1
1
|
module BlockScore
|
2
|
+
# Collection is a proxy between the parent and the asssociated members
|
3
|
+
# where parent is some instance of a resource
|
4
|
+
#
|
2
5
|
class Collection < Array
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
+
# @!attribute [r] parent
|
7
|
+
# resource which owns a collection of other resources
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# person.question_sets.parent # => person
|
11
|
+
#
|
12
|
+
# @return [BlockScore::Base] a resource
|
13
|
+
#
|
14
|
+
# @api private
|
15
|
+
attr_reader :parent
|
16
|
+
|
17
|
+
# Sets parent and member_class then registers embedded ids
|
18
|
+
#
|
19
|
+
# @param [BlockScore::Base] parent
|
20
|
+
# @param [Class] class of collection members
|
21
|
+
#
|
22
|
+
# @return [undefined]
|
23
|
+
#
|
24
|
+
# @api private
|
25
|
+
def initialize(parent, member_class)
|
26
|
+
@parent = parent
|
27
|
+
@member_class = member_class
|
28
|
+
register_parent_data
|
29
|
+
end
|
30
|
+
|
31
|
+
# Syntactic sugar method for returning collection
|
32
|
+
#
|
33
|
+
# @example
|
34
|
+
# all # returns collection
|
35
|
+
#
|
36
|
+
# @return [self]
|
37
|
+
#
|
38
|
+
# @api public
|
39
|
+
def all
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
# Initializes new {member_class} with `params`
|
44
|
+
#
|
45
|
+
# - Ensures a parent id is meged into `params` (see #default_params).
|
46
|
+
# - Defines method `#save` on new collection member
|
47
|
+
# - Adds new item to collection
|
48
|
+
#
|
49
|
+
# @example usage
|
50
|
+
#
|
51
|
+
# >> person = person = BlockScore::Person.retrieve('55de4af7643735000300000f')
|
52
|
+
# >> person.question_sets.new
|
53
|
+
# => #<BlockScore::QuestionSet:0x3fc67902f1b4 JSON:{
|
54
|
+
# "person_id": "55de4af7643735000300000f"
|
55
|
+
# }>
|
56
|
+
#
|
57
|
+
# @param params [Hash] initial params for member
|
58
|
+
#
|
59
|
+
# @return instance of {member_class}
|
60
|
+
#
|
61
|
+
# @api public
|
62
|
+
def new(params = {})
|
63
|
+
attributes = params.merge(default_params)
|
64
|
+
instance = member_class.new(attributes)
|
65
|
+
|
66
|
+
new_member(instance) do |member|
|
67
|
+
self << member
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Relaod the contents of the collection
|
72
|
+
#
|
73
|
+
# @example usage
|
74
|
+
# person.question_sets.refresh # => [#<BlockScore::QuestionSet...]
|
75
|
+
#
|
76
|
+
# @return [self]
|
77
|
+
#
|
78
|
+
# @api public
|
79
|
+
def refresh
|
80
|
+
clear
|
81
|
+
register_parent_data
|
82
|
+
self
|
6
83
|
end
|
7
84
|
|
8
|
-
|
9
|
-
|
85
|
+
# Name of parent resource
|
86
|
+
#
|
87
|
+
# @example
|
88
|
+
# self.parent_name # => 'person'
|
89
|
+
#
|
90
|
+
# @return [String]
|
91
|
+
#
|
92
|
+
# @api semipublic
|
93
|
+
def parent_name
|
94
|
+
parent.class.resource
|
95
|
+
end
|
96
|
+
|
97
|
+
# Initialize a collection member and save it
|
98
|
+
#
|
99
|
+
# @example
|
100
|
+
# >> person.question_sets.create
|
101
|
+
# => #<BlockScore::QuestionSet:0x3fc67a6007f4 JSON:{
|
102
|
+
# "object": "question_set",
|
103
|
+
# "id": "55ef5d5b62386200030001b3",
|
104
|
+
# "created_at": 1441750363,
|
105
|
+
# ...
|
106
|
+
# }
|
107
|
+
#
|
108
|
+
# @param params [Hash] params
|
109
|
+
#
|
110
|
+
# @return new saved instance of {member_class}
|
111
|
+
#
|
112
|
+
# @api public
|
113
|
+
def create(params = {})
|
114
|
+
fail Error, 'Create parent first' unless parent.id
|
115
|
+
assoc_params = default_params.merge(params)
|
116
|
+
instance = member_class.create(assoc_params)
|
117
|
+
|
118
|
+
new_member(instance) do |member|
|
119
|
+
register_to_parent(member)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Retrieve a collection member by its id
|
124
|
+
#
|
125
|
+
# @example usage
|
126
|
+
# person.question_sets.retrieve('55ef5b4e3532630003000178') # => instance of QuestionSet
|
127
|
+
#
|
128
|
+
# @param id [String] resource id
|
129
|
+
#
|
130
|
+
# @return instance of {member_class} if found
|
131
|
+
# @raise [BlockScore::NotFoundError] otherwise
|
132
|
+
#
|
133
|
+
# @api public
|
134
|
+
def retrieve(id)
|
135
|
+
each do |item|
|
136
|
+
next unless item.id == id
|
137
|
+
return item
|
138
|
+
end
|
139
|
+
|
140
|
+
instance = member_class.retrieve(id)
|
141
|
+
|
142
|
+
new_member(instance) do |member|
|
143
|
+
register_to_parent(member)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
protected
|
148
|
+
|
149
|
+
# @!attribute [r] member_class
|
150
|
+
# class which will be used for the embedded
|
151
|
+
# resources in the collection
|
152
|
+
#
|
153
|
+
# @return [Class]
|
154
|
+
#
|
155
|
+
# @api private
|
156
|
+
attr_reader :member_class
|
157
|
+
|
158
|
+
# Default params for making an instance of {member_class}
|
159
|
+
#
|
160
|
+
# @return [Hash]
|
161
|
+
#
|
162
|
+
# @api private
|
163
|
+
def default_params
|
164
|
+
{
|
165
|
+
foriegn_key => parent.id
|
166
|
+
}
|
10
167
|
end
|
11
168
|
|
12
169
|
private
|
13
170
|
|
14
|
-
|
15
|
-
|
171
|
+
# Generate foriegn key name for parent resource
|
172
|
+
#
|
173
|
+
# @return [Symbol] resource name as id
|
174
|
+
#
|
175
|
+
# @api private
|
176
|
+
def foriegn_key
|
177
|
+
:"#{parent_name}_id"
|
178
|
+
end
|
179
|
+
|
180
|
+
# Initialize a new collection member
|
181
|
+
#
|
182
|
+
# @param instance [BlockScore::Base] collection member instance
|
183
|
+
# @yield [Member] initialized member
|
184
|
+
#
|
185
|
+
# @return [Member] new member
|
186
|
+
#
|
187
|
+
# @api private
|
188
|
+
def new_member(instance, &blk)
|
189
|
+
Member.new(parent, instance).tap(&blk)
|
190
|
+
end
|
191
|
+
|
192
|
+
# Check if `parent_id` is defined on `item`
|
193
|
+
#
|
194
|
+
# @param item [BlockScore::Base] any resource
|
195
|
+
#
|
196
|
+
# @return [Boolean]
|
197
|
+
#
|
198
|
+
# @api private
|
199
|
+
def parent_id?(item)
|
200
|
+
parent.id && item.send(foriegn_key) == parent.id
|
201
|
+
end
|
202
|
+
|
203
|
+
# Register a resource in collection
|
204
|
+
#
|
205
|
+
# @param item [BlockScore::Base] a resource
|
206
|
+
#
|
207
|
+
# @raise [BlockScore::Error] if no `parent_id`
|
208
|
+
# @return [BlockScore::Base] otherwise
|
209
|
+
#
|
210
|
+
# @api private
|
211
|
+
def register_to_parent(item)
|
212
|
+
fail Error, 'None belonging' unless parent_id?(item)
|
213
|
+
ids << item.id
|
214
|
+
self << item
|
215
|
+
item
|
216
|
+
end
|
217
|
+
|
218
|
+
# Fetches embedded ids from parent and adds to self
|
219
|
+
#
|
220
|
+
# @return [undefined]
|
221
|
+
#
|
222
|
+
# @api private
|
223
|
+
def register_parent_data
|
224
|
+
ids.each do |id|
|
225
|
+
item = member_class.retrieve(id)
|
226
|
+
self << item
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
# ids that belong to the collection
|
231
|
+
#
|
232
|
+
# @return [Array<String>]
|
233
|
+
#
|
234
|
+
# @api private
|
235
|
+
def ids
|
236
|
+
parent.attributes.fetch(:"#{Util.to_plural(member_class.resource)}", [])
|
16
237
|
end
|
17
238
|
end
|
18
239
|
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module BlockScore
|
2
|
+
class Collection
|
3
|
+
# Member of a {Collection} class
|
4
|
+
class Member < SimpleDelegator
|
5
|
+
# Initialize a new member
|
6
|
+
#
|
7
|
+
# @param parent [BlockScore::Base] parent resource
|
8
|
+
# @param instance [BlockScore::Base] member instance
|
9
|
+
#
|
10
|
+
# @return [undefined]
|
11
|
+
#
|
12
|
+
# @api private
|
13
|
+
def initialize(parent, instance)
|
14
|
+
@instance = instance
|
15
|
+
@parent = parent
|
16
|
+
|
17
|
+
super(instance)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Save parent, set parent id, and save instance
|
21
|
+
#
|
22
|
+
# @example
|
23
|
+
# # saves both unsaved person and unsaved question_set
|
24
|
+
# person = Person.new(attributes)
|
25
|
+
# question_set = QuestionSet.new
|
26
|
+
# Member.new(person, question_set).save
|
27
|
+
#
|
28
|
+
# @return return value of instance `#save`
|
29
|
+
#
|
30
|
+
# @api public
|
31
|
+
def save
|
32
|
+
save_parent
|
33
|
+
send(:"#{parent_name}_id=", parent.id)
|
34
|
+
result = instance.save
|
35
|
+
ids.push(instance.id) unless ids.include?(instance.id)
|
36
|
+
result
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# Name of parent resource
|
42
|
+
#
|
43
|
+
# @example
|
44
|
+
# self.parent_name # => 'person'
|
45
|
+
#
|
46
|
+
# @return [String]
|
47
|
+
#
|
48
|
+
# @api private
|
49
|
+
def parent_name
|
50
|
+
parent.class.resource
|
51
|
+
end
|
52
|
+
|
53
|
+
# Save parent if it hasn't already been saved
|
54
|
+
#
|
55
|
+
# @return return of parent.save if previously unsaved
|
56
|
+
# @return nil otherwise
|
57
|
+
#
|
58
|
+
# @api private
|
59
|
+
def save_parent
|
60
|
+
parent.save unless parent_saved?
|
61
|
+
end
|
62
|
+
|
63
|
+
# Check if parent is saved
|
64
|
+
#
|
65
|
+
# @return [Boolean]
|
66
|
+
#
|
67
|
+
# @api private
|
68
|
+
def parent_saved?
|
69
|
+
parent.id
|
70
|
+
end
|
71
|
+
|
72
|
+
# @!attribute [r] instance
|
73
|
+
# member instance methods are delegated to
|
74
|
+
#
|
75
|
+
# @return [BlockScore::Base]
|
76
|
+
#
|
77
|
+
# @api private
|
78
|
+
attr_reader :instance
|
79
|
+
|
80
|
+
# @!attribute [r] parent
|
81
|
+
# collection parent the collectino conditionally updates
|
82
|
+
#
|
83
|
+
# @return [BlockScore::Base]
|
84
|
+
#
|
85
|
+
# @api private
|
86
|
+
attr_reader :parent
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
# ids that belong to associated parent resource
|
91
|
+
#
|
92
|
+
# @return [Array<String>]
|
93
|
+
#
|
94
|
+
# @api private
|
95
|
+
def ids
|
96
|
+
parent.attributes.fetch(:"#{Util.to_plural(instance.class.resource)}", [])
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -32,7 +32,7 @@ module BlockScore
|
|
32
32
|
begin
|
33
33
|
response = execute_request(method, path, params)
|
34
34
|
rescue SocketError, Errno::ECONNREFUSED => e
|
35
|
-
|
35
|
+
raise APIConnectionError, e.message
|
36
36
|
end
|
37
37
|
|
38
38
|
Response.handle_response(resource, response)
|
@@ -55,7 +55,7 @@ module BlockScore
|
|
55
55
|
|
56
56
|
def encode_path_params(path, params)
|
57
57
|
encoded = URI.encode_www_form(params)
|
58
|
-
[path, encoded].join(
|
58
|
+
[path, encoded].join('?')
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -15,7 +15,7 @@ module BlockScore
|
|
15
15
|
# APIError - Indicates an error on the server side (HTTP 5xx)
|
16
16
|
# AuthenticationError - Indicates an authentication error (HTTP 401)
|
17
17
|
def initialize(response)
|
18
|
-
body = JSON.parse(response.body, :
|
18
|
+
body = JSON.parse(response.body, symbolize_names: true)
|
19
19
|
|
20
20
|
@message = body[:error][:message]
|
21
21
|
@http_status = response.code
|
@@ -24,8 +24,8 @@ module BlockScore
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def to_s
|
27
|
-
status_string = @http_status ? "(Status: #{@http_status})" :
|
28
|
-
type_string = @error_type ? "(Type: #{@error_type})" :
|
27
|
+
status_string = @http_status ? "(Status: #{@http_status})" : ''
|
28
|
+
type_string = @error_type ? "(Type: #{@error_type})" : ''
|
29
29
|
|
30
30
|
"#{type_string} #{@message} #{status_string}"
|
31
31
|
end
|
@@ -19,9 +19,9 @@ module BlockScore
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def to_s
|
22
|
-
status_string = @http_status ? "(Status: #{@http_status})" :
|
23
|
-
type_string = @error_type ? "(Type: #{@error_type})" :
|
24
|
-
param_string = @param ? "(#{@param})" :
|
22
|
+
status_string = @http_status ? "(Status: #{@http_status})" : ''
|
23
|
+
type_string = @error_type ? "(Type: #{@error_type})" : ''
|
24
|
+
param_string = @param ? "(#{@param})" : ''
|
25
25
|
|
26
26
|
"#{type_string} #{@message} #{param_string} #{status_string}"
|
27
27
|
end
|
data/lib/blockscore/person.rb
CHANGED
@@ -6,14 +6,7 @@ module BlockScore
|
|
6
6
|
include BlockScore::Actions::Retrieve
|
7
7
|
include BlockScore::Actions::All
|
8
8
|
|
9
|
-
def_delegators 'self.class', :
|
10
|
-
|
11
|
-
def create
|
12
|
-
result = self.class.create(person_id: person.id)
|
13
|
-
person.question_sets << result.id
|
14
|
-
|
15
|
-
result
|
16
|
-
end
|
9
|
+
def_delegators 'self.class', :post, :endpoint
|
17
10
|
|
18
11
|
def score(answers = nil)
|
19
12
|
if answers.nil? && attributes
|
data/lib/blockscore/util.rb
CHANGED
@@ -11,13 +11,13 @@ module BlockScore
|
|
11
11
|
}
|
12
12
|
|
13
13
|
def parse_json!(json_obj)
|
14
|
-
JSON.parse(json_obj, :
|
14
|
+
JSON.parse(json_obj, symbolize_names: true)
|
15
15
|
end
|
16
16
|
|
17
17
|
def parse_json(json_obj)
|
18
18
|
parse_json! json_obj
|
19
19
|
rescue JSON::ParserError
|
20
|
-
|
20
|
+
raise Error, 'An error has occurred. If this problem persists, please message support@blockscore.com.'
|
21
21
|
end
|
22
22
|
|
23
23
|
def create_object(resource, options = {})
|
@@ -65,16 +65,16 @@ module BlockScore
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def to_camelcase(str)
|
68
|
-
str.split('_').map
|
68
|
+
str.split('_').map(&:capitalize).join('')
|
69
69
|
end
|
70
70
|
|
71
71
|
# Taken from Rulers: http://git.io/vkWqf
|
72
72
|
def to_underscore(str)
|
73
|
-
str.gsub(/::/, '/')
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
str.gsub(/::/, '/')
|
74
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
75
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
76
|
+
.tr('-', '_')
|
77
|
+
.downcase
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
data/lib/blockscore/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module BlockScore
|
2
|
-
VERSION = '4.
|
3
|
-
end
|
2
|
+
VERSION = '4.2.0'.freeze
|
3
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blockscore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alain Meier
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-09-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: httparty
|
@@ -96,6 +96,20 @@ dependencies:
|
|
96
96
|
- - "~>"
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '3'
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: rspec-its
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '1'
|
106
|
+
type: :development
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - "~>"
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '1'
|
99
113
|
- !ruby/object:Gem::Dependency
|
100
114
|
name: webmock
|
101
115
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,6 +171,7 @@ files:
|
|
157
171
|
- Rakefile
|
158
172
|
- blockscore.gemspec
|
159
173
|
- circle.yml
|
174
|
+
- circleci.sh
|
160
175
|
- lib/blockscore.rb
|
161
176
|
- lib/blockscore/actions/all.rb
|
162
177
|
- lib/blockscore/actions/create.rb
|
@@ -166,6 +181,7 @@ files:
|
|
166
181
|
- lib/blockscore/base.rb
|
167
182
|
- lib/blockscore/candidate.rb
|
168
183
|
- lib/blockscore/collection.rb
|
184
|
+
- lib/blockscore/collection/member.rb
|
169
185
|
- lib/blockscore/company.rb
|
170
186
|
- lib/blockscore/connection.rb
|
171
187
|
- lib/blockscore/dispatch.rb
|