hal-client 3.11.1 → 3.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +1 -1
- data/lib/hal_client/links_section.rb +2 -2
- data/lib/hal_client/version.rb +1 -1
- data/lib/hal_client.rb +8 -6
- data/spec/hal_client/links_section_spec.rb +6 -0
- data/spec/hal_client_spec.rb +13 -0
- 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: 95db91d4db8f1599d671ef361262bdbb22f64808
|
4
|
+
data.tar.gz: 7d293f6b47f9ee2512938f42c9bf54ee96f73b32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5be9718970338b4fc5b4b618b06297054fb3b855e1fe31b810df008f9ff11cb6bac7787adc2a5bf3b6da7b712b5a5f75bbea7af437c63b76f5e7a1f24c1c6b0
|
7
|
+
data.tar.gz: 32533202e76e007b18864ef1bd5ce149b32bf8f4f144df3b23348d61d307c21608ecc4a60ad0262aaf4ec4648bd0680d3c487d1f2533394fd1517577113865e5
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -104,7 +104,7 @@ HalClient supports PUT/POST/PATCH requests to remote resources via it's `#put`,
|
|
104
104
|
blog.patch(diffs_of_article_as_hal_json_str)
|
105
105
|
#=> #<Representation: http://blog.me>
|
106
106
|
|
107
|
-
The first argument to `#put`, `#post` and `#patch` may be a `String` or any object that responds to `#to_hal`. Additional options may be passed to change the content type of the post, etc.
|
107
|
+
The first argument to `#put`, `#post` and `#patch` may be a `String`, a `Hash` or any object that responds to `#to_hal`. Additional options may be passed to change the content type of the post, etc.
|
108
108
|
|
109
109
|
### PUT requests
|
110
110
|
|
@@ -7,7 +7,7 @@ class HalClient
|
|
7
7
|
def initialize(section, namespaces=nil)
|
8
8
|
@namespaces = namespaces || CurieResolver.new(section.fetch("curies"){[]})
|
9
9
|
|
10
|
-
@section = fully_qualified
|
10
|
+
@section = section.merge(fully_qualified(section))
|
11
11
|
end
|
12
12
|
|
13
13
|
attr_reader :namespaces
|
@@ -56,7 +56,7 @@ class HalClient
|
|
56
56
|
rescue KeyError
|
57
57
|
fail HalClient::InvalidRepresentationError
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def fully_qualified(relations_section)
|
61
61
|
Hash[relations_section.map {|rel, link_info|
|
62
62
|
[(namespaces.resolve rel), link_info]
|
data/lib/hal_client/version.rb
CHANGED
data/lib/hal_client.rb
CHANGED
@@ -86,6 +86,8 @@ class HalClient
|
|
86
86
|
|
87
87
|
req_body = if data.respond_to? :to_hal
|
88
88
|
data.to_hal
|
89
|
+
elsif data.is_a? Hash
|
90
|
+
data.to_json
|
89
91
|
else
|
90
92
|
data
|
91
93
|
end
|
@@ -101,24 +103,24 @@ class HalClient
|
|
101
103
|
end
|
102
104
|
end
|
103
105
|
|
104
|
-
# Post a `Representation` or `
|
106
|
+
# Post a `Representation`, `String` or `Hash` to the resource identified at `url`.
|
105
107
|
#
|
106
108
|
# url - The URL of the resource of interest.
|
107
|
-
# data - a `String` or an object that responds to `#to_hal`
|
109
|
+
# data - a `String`, a `Hash` or an object that responds to `#to_hal`
|
108
110
|
# headers - custom header fields to use for this request
|
109
111
|
def_unsafe_request :post
|
110
112
|
|
111
|
-
# Put a `Representation` or `
|
113
|
+
# Put a `Representation`, `String` or `Hash` to the resource identified at `url`.
|
112
114
|
#
|
113
115
|
# url - The URL of the resource of interest.
|
114
|
-
# data - a `String` or an object that responds to `#to_hal`
|
116
|
+
# data - a `String`, a `Hash` or an object that responds to `#to_hal`
|
115
117
|
# headers - custom header fields to use for this request
|
116
118
|
def_unsafe_request :put
|
117
119
|
|
118
|
-
# Patch a `Representation` or `
|
120
|
+
# Patch a `Representation`, `String` or `Hash` to the resource identified at `url`.
|
119
121
|
#
|
120
122
|
# url - The URL of the resource of interest.
|
121
|
-
# data - a `String` or an object that responds to `#to_hal`
|
123
|
+
# data - a `String`, a `Hash` or an object that responds to `#to_hal`
|
122
124
|
# headers - custom header fields to use for this request
|
123
125
|
def_unsafe_request :patch
|
124
126
|
|
@@ -10,7 +10,13 @@ describe HalClient::LinksSection, "namespaces embedded" do
|
|
10
10
|
specify { expect(section.hrefs(fully_qualified_first_rel))
|
11
11
|
.to contain_exactly "http://example.com/foo" }
|
12
12
|
|
13
|
+
specify { expect(section.hrefs("ns1:first"))
|
14
|
+
.to contain_exactly "http://example.com/foo" }
|
15
|
+
|
13
16
|
specify { expect(section.hrefs(fully_qualified_second_rel))
|
17
|
+
.to contain_exactly "http://example.com/bar", "http://example.com/baz" }
|
18
|
+
|
19
|
+
specify { expect(section.hrefs("ns2:second"))
|
14
20
|
.to contain_exactly "http://example.com/bar", "http://example.com/baz" }
|
15
21
|
|
16
22
|
specify { expect(section.hrefs("search"))
|
data/spec/hal_client_spec.rb
CHANGED
@@ -220,6 +220,19 @@ describe HalClient do
|
|
220
220
|
expect(return_val.code.to_s).to match(/^2../)
|
221
221
|
end
|
222
222
|
end
|
223
|
+
|
224
|
+
context "body as a Hash" do
|
225
|
+
before do return_val end
|
226
|
+
let(:post_data) { {example: "foo"} }
|
227
|
+
|
228
|
+
let(:post_request) { stub_request(:post, "http://example.com/foo").
|
229
|
+
with(:body => post_data.to_json).
|
230
|
+
to_return body: "{}" }
|
231
|
+
|
232
|
+
it "properly parses the request body" do
|
233
|
+
expect(post_request).to have_been_made
|
234
|
+
end
|
235
|
+
end
|
223
236
|
end
|
224
237
|
|
225
238
|
describe ".post(<url>)" 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.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|