hyperclient 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +2 -0
- data/.rubocop_todo.yml +55 -0
- data/.travis.yml +2 -0
- data/CHANGELOG.md +33 -10
- data/CONTRIBUTING.md +117 -0
- data/Gemfile +2 -1
- data/Guardfile +6 -6
- data/LICENSE +2 -2
- data/README.md +138 -0
- data/Rakefile +5 -3
- data/UPGRADING.md +37 -0
- data/examples/splines_api.rb +22 -0
- data/features/steps/api_navigation.rb +8 -8
- data/features/steps/default_config.rb +6 -6
- data/features/support/api.rb +4 -4
- data/features/support/fixtures.rb +1 -1
- data/hyperclient.gemspec +9 -8
- data/lib/faraday/connection.rb +2 -2
- data/lib/hyperclient.rb +1 -1
- data/lib/hyperclient/attributes.rb +1 -1
- data/lib/hyperclient/collection.rb +3 -3
- data/lib/hyperclient/curie.rb +49 -0
- data/lib/hyperclient/entry_point.rb +6 -4
- data/lib/hyperclient/link.rb +70 -58
- data/lib/hyperclient/link_collection.rb +36 -11
- data/lib/hyperclient/resource.rb +49 -18
- data/lib/hyperclient/resource_collection.rb +2 -1
- data/lib/hyperclient/version.rb +1 -1
- data/test/fixtures/element.json +12 -1
- data/test/hyperclient/attributes_test.rb +2 -2
- data/test/hyperclient/collection_test.rb +6 -7
- data/test/hyperclient/curie_test.rb +34 -0
- data/test/hyperclient/entry_point_test.rb +3 -2
- data/test/hyperclient/link_collection_test.rb +26 -5
- data/test/hyperclient/link_test.rb +111 -86
- data/test/hyperclient/resource_collection_test.rb +2 -2
- data/test/hyperclient/resource_test.rb +67 -30
- data/test/test_helper.rb +2 -2
- metadata +54 -39
- data/Gemfile.lock +0 -112
- data/MIT-LICENSE +0 -20
- data/Readme.md +0 -180
- data/examples/cyberscore.rb +0 -76
- data/examples/hal_shop.rb +0 -53
- data/lib/faraday/request/digest_authentication.rb +0 -85
- data/test/faraday/digest_authentication_test.rb +0 -41
@@ -3,10 +3,10 @@ require 'hyperclient/resource_collection'
|
|
3
3
|
|
4
4
|
module Hyperclient
|
5
5
|
describe ResourceCollection do
|
6
|
-
let(:entry_point) { stub('Entry point', config: {base_uri: '/'}) }
|
6
|
+
let(:entry_point) { stub('Entry point', config: { base_uri: '/' }) }
|
7
7
|
|
8
8
|
let(:representation) do
|
9
|
-
JSON.parse(
|
9
|
+
JSON.parse(File.read('test/fixtures/element.json'))
|
10
10
|
end
|
11
11
|
|
12
12
|
let(:resources) do
|
@@ -7,40 +7,48 @@ module Hyperclient
|
|
7
7
|
|
8
8
|
describe 'initialize' do
|
9
9
|
it 'initializes its links' do
|
10
|
-
LinkCollection.expects(:new).with({
|
10
|
+
LinkCollection.expects(:new).with({ 'self' => { 'href' => '/orders/523' } }, nil, entry_point)
|
11
11
|
|
12
|
-
Resource.new({'_links' => {
|
12
|
+
Resource.new({ '_links' => { 'self' => { 'href' => '/orders/523' } } }, entry_point)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'initializes its attributes' do
|
16
|
-
Attributes.expects(:new).with(
|
16
|
+
Attributes.expects(:new).with(foo: :bar)
|
17
17
|
|
18
|
-
Resource.new({foo: :bar}, entry_point)
|
18
|
+
Resource.new({ foo: :bar }, entry_point)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'initializes links' do
|
22
|
-
ResourceCollection.expects(:new).with({
|
22
|
+
ResourceCollection.expects(:new).with({ 'orders' => [] }, entry_point)
|
23
23
|
|
24
|
-
Resource.new({'_embedded' => {
|
24
|
+
Resource.new({ '_embedded' => { 'orders' => [] } }, entry_point)
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it 'initializes the response' do
|
28
28
|
mock_response = mock(body: {})
|
29
29
|
|
30
30
|
resource = Resource.new(mock_response.body, entry_point, mock_response)
|
31
31
|
|
32
|
-
resource.
|
32
|
+
resource._response.must_equal mock_response
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it 'does not mutate the response.body' do
|
36
36
|
body = { 'foo' => 'bar', '_links' => {}, '_embedded' => {} }
|
37
37
|
mock_response = stub(body: body.dup)
|
38
38
|
|
39
39
|
resource = Resource.new(mock_response.body, entry_point, mock_response)
|
40
40
|
|
41
|
-
resource.
|
41
|
+
resource._response.body.must_equal body
|
42
42
|
end
|
43
|
+
end
|
43
44
|
|
45
|
+
describe '_links' do
|
46
|
+
it '_expand' do
|
47
|
+
resource = Resource.new({ '_links' => { 'orders' => { 'href' => '/orders/{id}', 'templated' => true } } }, entry_point)
|
48
|
+
resource._links.orders._expand(id: 1)._url.must_equal '/orders/1'
|
49
|
+
resource.orders._expand(id: 1)._url.must_equal '/orders/1'
|
50
|
+
resource.orders(id: 1)._url.must_equal '/orders/1'
|
51
|
+
end
|
44
52
|
end
|
45
53
|
|
46
54
|
describe 'accessors' do
|
@@ -50,35 +58,64 @@ module Hyperclient
|
|
50
58
|
|
51
59
|
describe 'links' do
|
52
60
|
it 'returns a LinkCollection' do
|
53
|
-
resource.
|
61
|
+
resource._links.must_be_kind_of LinkCollection
|
54
62
|
end
|
55
63
|
end
|
56
64
|
|
57
65
|
describe 'attributes' do
|
58
66
|
it 'returns a Attributes' do
|
59
|
-
resource.
|
67
|
+
resource._attributes.must_be_kind_of Attributes
|
60
68
|
end
|
61
69
|
end
|
62
70
|
|
63
71
|
describe 'embedded' do
|
64
72
|
it 'returns a ResourceCollection' do
|
65
|
-
resource.
|
73
|
+
resource._embedded.must_be_kind_of ResourceCollection
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe 'method_missing' do
|
78
|
+
it 'delegates to attributes' do
|
79
|
+
resource._attributes.expects(:foo).returns('bar')
|
80
|
+
resource.foo.must_equal 'bar'
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'delegates to links' do
|
84
|
+
resource._links.expects(:foo).returns('bar')
|
85
|
+
resource.foo.must_equal 'bar'
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'delegates to embedded' do
|
89
|
+
resource._embedded.expects(:foo).returns('bar')
|
90
|
+
resource.foo.must_equal 'bar'
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'delegates to attributes, links, embedded' do
|
94
|
+
resource._attributes.expects('respond_to?').with('foo').returns(false)
|
95
|
+
resource._links.expects('respond_to?').with('foo').returns(false)
|
96
|
+
resource._embedded.expects('respond_to?').with('foo').returns(false)
|
97
|
+
lambda { resource.foo }.must_raise NoMethodError
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'delegates []' do
|
101
|
+
resource._attributes.expects(:foo).returns('bar')
|
102
|
+
resource['foo'].must_equal 'bar'
|
66
103
|
end
|
67
104
|
end
|
68
105
|
end
|
69
106
|
|
70
107
|
it 'uses its self Link to handle HTTP connections' do
|
71
108
|
self_link = mock('Self Link')
|
72
|
-
self_link.expects(:
|
109
|
+
self_link.expects(:_get)
|
73
110
|
|
74
|
-
LinkCollection.expects(:new).returns(
|
111
|
+
LinkCollection.expects(:new).returns('self' => self_link)
|
75
112
|
resource = Resource.new({}, entry_point)
|
76
113
|
|
77
|
-
resource.
|
114
|
+
resource._get
|
78
115
|
end
|
79
116
|
|
80
|
-
describe
|
81
|
-
describe
|
117
|
+
describe '._success?' do
|
118
|
+
describe 'with a response object' do
|
82
119
|
let(:resource) do
|
83
120
|
Resource.new({}, entry_point, mock_response)
|
84
121
|
end
|
@@ -87,24 +124,24 @@ module Hyperclient
|
|
87
124
|
mock(success?: true)
|
88
125
|
end
|
89
126
|
|
90
|
-
it
|
91
|
-
resource.
|
127
|
+
it 'proxies to the response object' do
|
128
|
+
resource._success?.must_equal true
|
92
129
|
end
|
93
130
|
end
|
94
131
|
|
95
|
-
describe
|
132
|
+
describe 'without a response object' do
|
96
133
|
let(:resource) do
|
97
134
|
Resource.new({}, entry_point)
|
98
135
|
end
|
99
136
|
|
100
|
-
it
|
101
|
-
resource.
|
137
|
+
it 'returns nil' do
|
138
|
+
resource._success?.must_be_nil
|
102
139
|
end
|
103
140
|
end
|
104
141
|
end
|
105
142
|
|
106
|
-
describe
|
107
|
-
describe
|
143
|
+
describe '._status' do
|
144
|
+
describe 'with a response object' do
|
108
145
|
let(:resource) do
|
109
146
|
Resource.new({}, entry_point, mock_response)
|
110
147
|
end
|
@@ -113,18 +150,18 @@ module Hyperclient
|
|
113
150
|
mock(status: 200)
|
114
151
|
end
|
115
152
|
|
116
|
-
it
|
117
|
-
resource.
|
153
|
+
it 'proxies to the response object' do
|
154
|
+
resource._status.must_equal 200
|
118
155
|
end
|
119
156
|
end
|
120
157
|
|
121
|
-
describe
|
158
|
+
describe 'without a response object' do
|
122
159
|
let(:resource) do
|
123
160
|
Resource.new({}, entry_point)
|
124
161
|
end
|
125
162
|
|
126
|
-
it
|
127
|
-
resource.
|
163
|
+
it 'returns nil' do
|
164
|
+
resource._status.must_be_nil
|
128
165
|
end
|
129
166
|
end
|
130
167
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,167 +1,181 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hyperclient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oriol Gual
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0.8'
|
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
26
|
version: '0.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: futuroscope
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.0.10
|
34
34
|
type: :runtime
|
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.0.10
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: faraday_middleware
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0.9'
|
48
48
|
type: :runtime
|
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: '0.9'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: uri_template
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0.5'
|
62
62
|
type: :runtime
|
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: '0.5'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: net-http-digest_auth
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '1.2'
|
76
76
|
type: :runtime
|
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: '1.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday-digestauth
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.2'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.2'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: minitest
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
|
-
- -
|
101
|
+
- - ~>
|
88
102
|
- !ruby/object:Gem::Version
|
89
103
|
version: 3.4.0
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
|
-
- -
|
108
|
+
- - ~>
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: 3.4.0
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: turn
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
|
-
- -
|
115
|
+
- - ~>
|
102
116
|
- !ruby/object:Gem::Version
|
103
117
|
version: '0.9'
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
|
-
- -
|
122
|
+
- - ~>
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0.9'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: webmock
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
|
-
- -
|
129
|
+
- - ~>
|
116
130
|
- !ruby/object:Gem::Version
|
117
131
|
version: '1.8'
|
118
132
|
type: :development
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
|
-
- -
|
136
|
+
- - ~>
|
123
137
|
- !ruby/object:Gem::Version
|
124
138
|
version: '1.8'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: mocha
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
128
142
|
requirements:
|
129
|
-
- -
|
143
|
+
- - ~>
|
130
144
|
- !ruby/object:Gem::Version
|
131
145
|
version: '0.13'
|
132
146
|
type: :development
|
133
147
|
prerelease: false
|
134
148
|
version_requirements: !ruby/object:Gem::Requirement
|
135
149
|
requirements:
|
136
|
-
- -
|
150
|
+
- - ~>
|
137
151
|
- !ruby/object:Gem::Version
|
138
152
|
version: '0.13'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: rack-test
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
142
156
|
requirements:
|
143
|
-
- -
|
157
|
+
- - ~>
|
144
158
|
- !ruby/object:Gem::Version
|
145
159
|
version: '0.6'
|
146
160
|
type: :development
|
147
161
|
prerelease: false
|
148
162
|
version_requirements: !ruby/object:Gem::Requirement
|
149
163
|
requirements:
|
150
|
-
- -
|
164
|
+
- - ~>
|
151
165
|
- !ruby/object:Gem::Version
|
152
166
|
version: '0.6'
|
153
167
|
- !ruby/object:Gem::Dependency
|
154
168
|
name: spinach
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|
156
170
|
requirements:
|
157
|
-
- -
|
171
|
+
- - '>='
|
158
172
|
- !ruby/object:Gem::Version
|
159
173
|
version: '0'
|
160
174
|
type: :development
|
161
175
|
prerelease: false
|
162
176
|
version_requirements: !ruby/object:Gem::Requirement
|
163
177
|
requirements:
|
164
|
-
- -
|
178
|
+
- - '>='
|
165
179
|
- !ruby/object:Gem::Version
|
166
180
|
version: '0'
|
167
181
|
description: HyperClient is a Ruby Hypermedia API client.
|
@@ -171,20 +185,21 @@ executables: []
|
|
171
185
|
extensions: []
|
172
186
|
extra_rdoc_files: []
|
173
187
|
files:
|
174
|
-
-
|
175
|
-
-
|
176
|
-
-
|
177
|
-
-
|
188
|
+
- .gitignore
|
189
|
+
- .rubocop.yml
|
190
|
+
- .rubocop_todo.yml
|
191
|
+
- .rvmrc
|
192
|
+
- .travis.yml
|
193
|
+
- .yardopts
|
178
194
|
- CHANGELOG.md
|
195
|
+
- CONTRIBUTING.md
|
179
196
|
- Gemfile
|
180
|
-
- Gemfile.lock
|
181
197
|
- Guardfile
|
182
198
|
- LICENSE
|
183
|
-
-
|
199
|
+
- README.md
|
184
200
|
- Rakefile
|
185
|
-
-
|
186
|
-
- examples/
|
187
|
-
- examples/hal_shop.rb
|
201
|
+
- UPGRADING.md
|
202
|
+
- examples/splines_api.rb
|
188
203
|
- features/api_navigation.feature
|
189
204
|
- features/default_config.feature
|
190
205
|
- features/steps/api_navigation.rb
|
@@ -194,10 +209,10 @@ files:
|
|
194
209
|
- features/support/fixtures.rb
|
195
210
|
- hyperclient.gemspec
|
196
211
|
- lib/faraday/connection.rb
|
197
|
-
- lib/faraday/request/digest_authentication.rb
|
198
212
|
- lib/hyperclient.rb
|
199
213
|
- lib/hyperclient/attributes.rb
|
200
214
|
- lib/hyperclient/collection.rb
|
215
|
+
- lib/hyperclient/curie.rb
|
201
216
|
- lib/hyperclient/entry_point.rb
|
202
217
|
- lib/hyperclient/link.rb
|
203
218
|
- lib/hyperclient/link_collection.rb
|
@@ -205,12 +220,12 @@ files:
|
|
205
220
|
- lib/hyperclient/resource_collection.rb
|
206
221
|
- lib/hyperclient/version.rb
|
207
222
|
- test/faraday/connection_test.rb
|
208
|
-
- test/faraday/digest_authentication_test.rb
|
209
223
|
- test/fixtures/collection.json
|
210
224
|
- test/fixtures/element.json
|
211
225
|
- test/fixtures/root.json
|
212
226
|
- test/hyperclient/attributes_test.rb
|
213
227
|
- test/hyperclient/collection_test.rb
|
228
|
+
- test/hyperclient/curie_test.rb
|
214
229
|
- test/hyperclient/entry_point_test.rb
|
215
230
|
- test/hyperclient/link_collection_test.rb
|
216
231
|
- test/hyperclient/link_test.rb
|
@@ -227,17 +242,17 @@ require_paths:
|
|
227
242
|
- lib
|
228
243
|
required_ruby_version: !ruby/object:Gem::Requirement
|
229
244
|
requirements:
|
230
|
-
- -
|
245
|
+
- - '>='
|
231
246
|
- !ruby/object:Gem::Version
|
232
247
|
version: '0'
|
233
248
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
234
249
|
requirements:
|
235
|
-
- -
|
250
|
+
- - '>='
|
236
251
|
- !ruby/object:Gem::Version
|
237
252
|
version: '0'
|
238
253
|
requirements: []
|
239
254
|
rubyforge_project:
|
240
|
-
rubygems_version: 2.
|
255
|
+
rubygems_version: 2.1.11
|
241
256
|
signing_key:
|
242
257
|
specification_version: 4
|
243
258
|
summary: ''
|
@@ -250,12 +265,12 @@ test_files:
|
|
250
265
|
- features/support/env.rb
|
251
266
|
- features/support/fixtures.rb
|
252
267
|
- test/faraday/connection_test.rb
|
253
|
-
- test/faraday/digest_authentication_test.rb
|
254
268
|
- test/fixtures/collection.json
|
255
269
|
- test/fixtures/element.json
|
256
270
|
- test/fixtures/root.json
|
257
271
|
- test/hyperclient/attributes_test.rb
|
258
272
|
- test/hyperclient/collection_test.rb
|
273
|
+
- test/hyperclient/curie_test.rb
|
259
274
|
- test/hyperclient/entry_point_test.rb
|
260
275
|
- test/hyperclient/link_collection_test.rb
|
261
276
|
- test/hyperclient/link_test.rb
|