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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74de1dba1a4d7fcb4b836da48535915b9694219b
4
- data.tar.gz: 5e3ebfbb756110e9adaefff3e339e34532fdd982
3
+ metadata.gz: 48fecd22d2b1db80b08257e47f4eabc59241b66b
4
+ data.tar.gz: 1db19c11ab6e1b8916261b9092dcac95c09c6114
5
5
  SHA512:
6
- metadata.gz: c30ea673a86d148156f8783afbdb05e663e5445910a30aedbcf67edd2775e66d9bb7fa46d4770e165f13607cdeb29b3db6c517d8cb27679aa97a3a4bd92d0f7f
7
- data.tar.gz: 223ce6546a7d0adcc61ed5d1e0306fb5087b99ad15c1d9a8c6ceca5dfca5e91600f02027db42198f76240b238de9b06812311441b71c82731da1c2fa9deec526
6
+ metadata.gz: 1520012e60a501afe54d0b8d03d46f16286ee7d0f5478408b52ffce06b7a8c3b8ca7ac7f6d22814f0a106a9ddd70deadc290f77d2e0895791f54a9dced948114
7
+ data.tar.gz: 3ffd9b6ea7a6294f6edc12baaab6463a13ff1b439db55ac29c43efb4ead94789242ad2332a007c0ca5c6c7606083efefc1fe2b27a3e297ba5b34b83643792f18
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ![Build Status](https://travis-ci.org/pezra/hal-client.png?branch=master)](https://travis-ci.org/pezra/hal-client)
1
+ [![Build Status](https://travis-ci.org/pezra/hal-client.png?branch=master)](https://travis-ci.org/pezra/hal-client)
2
2
  [![Code Climate](https://codeclimate.com/github/pezra/hal-client.png)](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
@@ -1,3 +1,3 @@
1
1
  class HalClient
2
- VERSION = "3.4.2"
2
+ VERSION = "3.5.1"
3
3
  end
@@ -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
- stub_request(:post, repr.href)
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
- before(:each) do
32
- repr.post("abc")
33
- end
30
+ specify { expect(repr.post("abc")).to be_kind_of HalClient::Representation }
34
31
 
35
- specify("makes request") {
36
- expect(post_request.with(:body => "abc",
37
- :headers => {'Content-Type' => 'application/hal+json'}))
38
- .to have_been_made
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
- stub_request(:put, repr.href)
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
- before(:each) do
48
- repr.put("abc")
49
- end
57
+ specify { expect(repr.put("abc")).to be_kind_of HalClient::Representation }
50
58
 
51
- specify("makes request") {
52
- expect(put_request.with(:body => "abc",
53
- :headers => {'Content-Type' => 'application/hal+json'}))
54
- .to have_been_made
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
- stub_request(:patch, repr.href)
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("makes request") {
68
- expect(patch_request.with(:body => "abc",
69
- :headers => {'Content-Type' => 'application/hal+json'}))
70
- .to have_been_made
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.2
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-01 00:00:00.000000000 Z
11
+ date: 2014-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http