hal-client 3.4.2 → 3.5.1
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/README.md +1 -1
- data/lib/hal_client/representation.rb +27 -6
- data/lib/hal_client/version.rb +1 -1
- data/spec/hal_client/representation_spec.rb +61 -33
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48fecd22d2b1db80b08257e47f4eabc59241b66b
|
4
|
+
data.tar.gz: 1db19c11ab6e1b8916261b9092dcac95c09c6114
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1520012e60a501afe54d0b8d03d46f16286ee7d0f5478408b52ffce06b7a8c3b8ca7ac7f6d22814f0a106a9ddd70deadc290f77d2e0895791f54a9dced948114
|
7
|
+
data.tar.gz: 3ffd9b6ea7a6294f6edc12baaab6463a13ff1b439db55ac29c43efb4ead94789242ad2332a007c0ca5c6c7606083efefc1fe2b27a3e297ba5b34b83643792f18
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
](https://travis-ci.org/pezra/hal-client)
|
1
|
+
[](https://travis-ci.org/pezra/hal-client)
|
2
2
|
[](https://codeclimate.com/github/pezra/hal-client)
|
3
3
|
|
4
4
|
# HalClient
|
@@ -30,28 +30,37 @@ class HalClient
|
|
30
30
|
@raw && ! hashish?(@raw)
|
31
31
|
end
|
32
32
|
|
33
|
-
# Posts a `Representation` or `String` to this resource.
|
33
|
+
# Posts a `Representation` or `String` to this resource. Causes
|
34
|
+
# this representation to be reloaded the next time it is used.
|
34
35
|
#
|
35
36
|
# data - a `String` or an object that responds to `#to_hal`
|
36
37
|
# options - set of options to pass to `HalClient#post`
|
37
38
|
def post(data, options={})
|
38
|
-
@hal_client.post(href, data, options)
|
39
|
+
@hal_client.post(href, data, options).tap do
|
40
|
+
reset
|
41
|
+
end
|
39
42
|
end
|
40
43
|
|
41
|
-
# Puts a `Representation` or `String` to this resource.
|
44
|
+
# Puts a `Representation` or `String` to this resource. Causes
|
45
|
+
# this representation to be reloaded the next time it is used.
|
42
46
|
#
|
43
47
|
# data - a `String` or an object that responds to `#to_hal`
|
44
48
|
# options - set of options to pass to `HalClient#put`
|
45
49
|
def put(data, options={})
|
46
|
-
@hal_client.put(href, data, options)
|
50
|
+
@hal_client.put(href, data, options).tap do
|
51
|
+
reset
|
52
|
+
end
|
47
53
|
end
|
48
54
|
|
49
|
-
# Patchs a `Representation` or `String` to this resource.
|
55
|
+
# Patchs a `Representation` or `String` to this resource. Causes
|
56
|
+
# this representation to be reloaded the next time it is used.
|
50
57
|
#
|
51
58
|
# data - a `String` or an object that responds to `#to_hal`
|
52
59
|
# options - set of options to pass to `HalClient#patch`
|
53
60
|
def patch(data, options={})
|
54
|
-
@hal_client.patch(href, data, options)
|
61
|
+
@hal_client.patch(href, data, options).tap do
|
62
|
+
reset
|
63
|
+
end
|
55
64
|
end
|
56
65
|
|
57
66
|
# Returns true if this representation contains the specified
|
@@ -201,10 +210,22 @@ class HalClient
|
|
201
210
|
Array(linked) + Array(embedded).map(&:href)
|
202
211
|
end
|
203
212
|
|
213
|
+
# Returns an Enumerable of the items in this collection resource
|
214
|
+
# if this is an rfc 6573 collection.
|
215
|
+
#
|
216
|
+
# Raises HalClient::NotACollectionError if this is not a
|
217
|
+
# collection resource.
|
204
218
|
def as_enum
|
205
219
|
Collection.new(self)
|
206
220
|
end
|
207
221
|
|
222
|
+
# Resets this representation such that it will be requested from
|
223
|
+
# the upstream on it's next use.
|
224
|
+
def reset
|
225
|
+
@href = href # make sure we have the href
|
226
|
+
@raw = nil
|
227
|
+
end
|
228
|
+
|
208
229
|
# Returns a short human readable description of this
|
209
230
|
# representation.
|
210
231
|
def to_s
|
data/lib/hal_client/version.rb
CHANGED
@@ -24,51 +24,79 @@ HAL
|
|
24
24
|
parsed_json: MultiJson.load(raw_repr)) }
|
25
25
|
|
26
26
|
describe "#post" do
|
27
|
-
let!(:post_request) {
|
28
|
-
|
29
|
-
}
|
27
|
+
let!(:post_request) { stub_request(:post, repr.href).to_return(body: "{}") }
|
28
|
+
let!(:reload_request) { stub_request(:get, repr.href).to_return(body: raw_repr) }
|
30
29
|
|
31
|
-
|
32
|
-
repr.post("abc")
|
33
|
-
end
|
30
|
+
specify { expect(repr.post("abc")).to be_kind_of HalClient::Representation }
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
describe "after" do
|
33
|
+
before(:each) do
|
34
|
+
repr.post("abc")
|
35
|
+
end
|
36
|
+
|
37
|
+
it("makes request") do
|
38
|
+
expect(post_request.with(:body => "abc",
|
39
|
+
:headers => {
|
40
|
+
'Content-Type' => 'application/hal+json'
|
41
|
+
})
|
42
|
+
)
|
43
|
+
.to have_been_made
|
44
|
+
end
|
45
|
+
|
46
|
+
it("refetches repr afterwards") do
|
47
|
+
repr.property("prop1")
|
48
|
+
expect(reload_request).to have_been_made
|
49
|
+
end
|
50
|
+
end
|
40
51
|
end
|
41
52
|
|
42
53
|
describe "#put" do
|
43
|
-
let!(:put_request) {
|
44
|
-
|
45
|
-
}
|
54
|
+
let!(:put_request) { stub_request(:put, repr.href).to_return(body: "{}") }
|
55
|
+
let!(:reload_request) { stub_request(:get, repr.href).to_return(body: raw_repr) }
|
46
56
|
|
47
|
-
|
48
|
-
repr.put("abc")
|
49
|
-
end
|
57
|
+
specify { expect(repr.put("abc")).to be_kind_of HalClient::Representation }
|
50
58
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
59
|
+
describe "after" do
|
60
|
+
before(:each) do
|
61
|
+
repr.put("abc")
|
62
|
+
end
|
63
|
+
|
64
|
+
specify("makes request") do
|
65
|
+
expect(put_request.with(:body => "abc",
|
66
|
+
:headers => {'Content-Type' => 'application/hal+json'}))
|
67
|
+
.to have_been_made
|
68
|
+
end
|
69
|
+
|
70
|
+
it("refetches repr afterwards") do
|
71
|
+
repr.property("prop1")
|
72
|
+
expect(reload_request).to have_been_made
|
73
|
+
end
|
74
|
+
end
|
56
75
|
end
|
57
76
|
|
58
77
|
describe "#patch" do
|
59
|
-
let!(:patch_request) {
|
60
|
-
|
61
|
-
}
|
78
|
+
let!(:patch_request) { stub_request(:patch, repr.href).to_return(body: "{}") }
|
79
|
+
let!(:reload_request) { stub_request(:get, repr.href).to_return(body: raw_repr) }
|
62
80
|
|
63
|
-
before(:each) do
|
64
|
-
repr.patch("abc")
|
65
|
-
end
|
66
81
|
|
67
|
-
specify("
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
82
|
+
specify { expect(repr.patch("abc")).to be_kind_of HalClient::Representation }
|
83
|
+
|
84
|
+
describe "after" do
|
85
|
+
before(:each) do
|
86
|
+
repr.patch("abc")
|
87
|
+
end
|
88
|
+
|
89
|
+
specify("makes request") do
|
90
|
+
expect(patch_request.with(:body => "abc",
|
91
|
+
:headers => {'Content-Type' => 'application/hal+json'}))
|
92
|
+
.to have_been_made
|
93
|
+
end
|
94
|
+
|
95
|
+
it("refetches repr afterwards") do
|
96
|
+
repr.property("prop1")
|
97
|
+
expect(reload_request).to have_been_made
|
98
|
+
end
|
99
|
+
end
|
72
100
|
end
|
73
101
|
|
74
102
|
describe "#to_s" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hal-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|