hal-client 2.4.0 → 2.5.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.
- data/lib/hal_client/version.rb +1 -1
- data/lib/hal_client.rb +14 -8
- data/spec/hal_client_spec.rb +30 -0
- metadata +4 -4
data/lib/hal_client/version.rb
CHANGED
data/lib/hal_client.rb
CHANGED
@@ -19,9 +19,13 @@ class HalClient
|
|
19
19
|
# prepended to the `Accept` header field of each request.
|
20
20
|
# :content_type - a single content type that should be
|
21
21
|
# prepended to the `Content-Type` header field of each request.
|
22
|
+
# :headers - a hash of other headers to send on each request.
|
22
23
|
def initialize(options={})
|
23
|
-
|
24
|
-
|
24
|
+
accept = options.fetch(:accept, 'application/hal+json')
|
25
|
+
content_type = options.fetch(:content_type, 'application/hal+json')
|
26
|
+
headers = options.fetch(:headers, {})
|
27
|
+
|
28
|
+
@headers = {accept: accept, content_type: content_type}.merge(headers)
|
25
29
|
end
|
26
30
|
|
27
31
|
# Returns a `Representation` of the resource identified by `url`.
|
@@ -50,17 +54,19 @@ class HalClient
|
|
50
54
|
|
51
55
|
protected
|
52
56
|
|
53
|
-
attr_reader :
|
57
|
+
attr_reader :headers
|
54
58
|
|
59
|
+
# Exclude headers that shouldn't go with a GET
|
55
60
|
def get_options(overrides)
|
56
|
-
|
61
|
+
@cleansed_get_options ||= headers.dup.tap do |get_headers|
|
62
|
+
get_headers.delete(:content_type)
|
63
|
+
end
|
64
|
+
|
65
|
+
@cleansed_get_options.merge overrides
|
57
66
|
end
|
58
67
|
|
59
68
|
def post_options(overrides)
|
60
|
-
|
61
|
-
accept: default_accept,
|
62
|
-
content_type: default_content_type
|
63
|
-
}.merge overrides
|
69
|
+
headers.merge(overrides)
|
64
70
|
end
|
65
71
|
|
66
72
|
module EntryPointCovenienceMethods
|
data/spec/hal_client_spec.rb
CHANGED
@@ -37,6 +37,28 @@ describe HalClient do
|
|
37
37
|
to have_been_made
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
context "explicit content type" do
|
42
|
+
subject(:client) { HalClient.new content_type: 'custom' }
|
43
|
+
it "does not send the content type header" do
|
44
|
+
expect(request.with(headers: {'Accept' => 'application/hal+json'})).to have_been_made
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "other headers" do
|
49
|
+
let(:headers) { {"Authorization" => "Bearer f73c04b0970f1deb6005fab53edd1708"} }
|
50
|
+
subject(:client) { HalClient.new headers: headers }
|
51
|
+
it "sends the supplied header" do
|
52
|
+
expect(request.with(headers: headers)).to have_been_made
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "header overrides" do
|
57
|
+
let!(:return_val) { client.get "http://example.com/foo", { "DummyHeader" => "Test" } }
|
58
|
+
it "sends the supplied header" do
|
59
|
+
expect(request.with(headers: { "DummyHeader" => "Test" })).to have_been_made
|
60
|
+
end
|
61
|
+
end
|
40
62
|
end
|
41
63
|
|
42
64
|
describe ".get(<url>)" do
|
@@ -83,6 +105,14 @@ describe HalClient do
|
|
83
105
|
end
|
84
106
|
end
|
85
107
|
|
108
|
+
context "other headers" do
|
109
|
+
let(:headers) { {"Authorization" => "Bearer f73c04b0970f1deb6005fab53edd1708"} }
|
110
|
+
subject(:client) { HalClient.new headers: headers }
|
111
|
+
it "sends the supplied header" do
|
112
|
+
expect(post_request.with(headers: headers)).to have_been_made
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
86
116
|
context "with no response body" do
|
87
117
|
subject { empty_post_request }
|
88
118
|
let!(:return_val) { client.post "http://example.com/foo", nil }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hal-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -184,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
184
184
|
version: '0'
|
185
185
|
segments:
|
186
186
|
- 0
|
187
|
-
hash:
|
187
|
+
hash: 1272540946785022860
|
188
188
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
189
|
none: false
|
190
190
|
requirements:
|
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
193
|
version: '0'
|
194
194
|
segments:
|
195
195
|
- 0
|
196
|
-
hash:
|
196
|
+
hash: 1272540946785022860
|
197
197
|
requirements: []
|
198
198
|
rubyforge_project:
|
199
199
|
rubygems_version: 1.8.23
|