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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 253c1dbaeef9a44aa3d64d9f6a440cdcd04567ad
4
- data.tar.gz: 74898c74f70a37334b50b8ce1284759c0043e4be
3
+ metadata.gz: 95db91d4db8f1599d671ef361262bdbb22f64808
4
+ data.tar.gz: 7d293f6b47f9ee2512938f42c9bf54ee96f73b32
5
5
  SHA512:
6
- metadata.gz: 5b8bece5e9c60060a29711057b029d768c6661cdf654f3d3ff507f1894ceebfbd92111d7675bfa310d20037c0d9b4719191b445e058f5d08eb253d8752f1e9f4
7
- data.tar.gz: f72e017752ebbcf1a3274cc798a68ae9b8724f5bd78c850abceb941632b3649d3c14bf48476d37153186a7df8c23ea5d7e57efa05dfc6585f7634d5d71233e74
6
+ metadata.gz: d5be9718970338b4fc5b4b618b06297054fb3b855e1fe31b810df008f9ff11cb6bac7787adc2a5bf3b6da7b712b5a5f75bbea7af437c63b76f5e7a1f24c1c6b0
7
+ data.tar.gz: 32533202e76e007b18864ef1bd5ce149b32bf8f4f144df3b23348d61d307c21608ecc4a60ad0262aaf4ec4648bd0680d3c487d1f2533394fd1517577113865e5
data/.travis.yml CHANGED
@@ -5,5 +5,5 @@ rvm:
5
5
  - "2.0.0"
6
6
  - "2.1.0"
7
7
  - "2.2.0"
8
- - rbx-2.5.2
8
+ - rbx-2.7
9
9
 
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 section
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]
@@ -1,3 +1,3 @@
1
1
  class HalClient
2
- VERSION = "3.11.1"
2
+ VERSION = "3.12.0"
3
3
  end
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 `String` to the resource identified at `url`.
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 `String` to the resource identified at `url`.
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 `String` to the resource identified at `url`.
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"))
@@ -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.11.1
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 00:00:00.000000000 Z
11
+ date: 2015-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http