hal-client 3.12.0 → 3.13.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.
- checksums.yaml +4 -4
- data/lib/hal_client/links_section.rb +9 -6
- data/lib/hal_client/representation.rb +9 -7
- data/lib/hal_client/version.rb +1 -1
- data/spec/hal_client/links_section_spec.rb +13 -3
- 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: 553aacea1a5e60830f4444b701d714433dcb7fbc
|
4
|
+
data.tar.gz: dacb874f8b57a68e908028dee737b7d48cae4ce0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e58ada075076a0ebd8ea3aa8366ed4980d972d6813be97294c6eafde889ae03e5bfab120fe8ca797b1590f6fee8c27c670c7f141f8e444f88b080da2039443d8
|
7
|
+
data.tar.gz: d746794430e8b5bc974b8917dc33c4ce0fe5afe08d0fdf4c51978cb1cb2bd8a76f949c0eeb0d15aae39bf03ca0e1266c9ce42f590f9d4a2fa5ba141212e521a4
|
@@ -4,10 +4,13 @@ class HalClient
|
|
4
4
|
class LinksSection
|
5
5
|
UNSET = Object.new
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
# section - json hash for the links section
|
8
|
+
# base_url - base URL with which to resolve relative URLs
|
9
|
+
def initialize(section, opts={} )
|
10
|
+
@namespaces = CurieResolver.new(section.fetch("curies"){[]})
|
9
11
|
|
10
12
|
@section = section.merge(fully_qualified(section))
|
13
|
+
@base_url = opts.fetch(:base_url) { raise ArgumentError, "base_url must be specified" }
|
11
14
|
end
|
12
15
|
|
13
16
|
attr_reader :namespaces
|
@@ -39,18 +42,18 @@ class HalClient
|
|
39
42
|
|
40
43
|
protected
|
41
44
|
|
42
|
-
attr_reader :section
|
45
|
+
attr_reader :section, :base_url
|
43
46
|
|
44
47
|
def resolve_to_url(link)
|
45
48
|
(fail HalClient::InvalidRepresentationError) unless link.respond_to? :fetch
|
46
49
|
|
47
|
-
url = link.fetch("href")
|
50
|
+
url = base_url + link.fetch("href")
|
48
51
|
is_templated = link.fetch("templated", false)
|
49
52
|
|
50
53
|
if is_templated
|
51
|
-
Addressable::Template.new(url)
|
54
|
+
Addressable::Template.new(url.to_s)
|
52
55
|
else
|
53
|
-
url
|
56
|
+
url.to_s
|
54
57
|
end
|
55
58
|
|
56
59
|
rescue KeyError
|
@@ -103,11 +103,10 @@ class HalClient
|
|
103
103
|
|
104
104
|
# Returns the URL of the resource this representation represents.
|
105
105
|
def href
|
106
|
-
@href ||=
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
end
|
106
|
+
@href ||= raw
|
107
|
+
.fetch("_links",{})
|
108
|
+
.fetch("self",{})
|
109
|
+
.fetch("href",nil)
|
111
110
|
end
|
112
111
|
|
113
112
|
# Returns the value of the specified property or representations
|
@@ -297,11 +296,14 @@ class HalClient
|
|
297
296
|
|
298
297
|
|
299
298
|
def links
|
300
|
-
@links ||= LinksSection.new
|
299
|
+
@links ||= LinksSection.new((raw.fetch("_links"){{}}),
|
300
|
+
base_url: Addressable::URI.parse(href || ""))
|
301
301
|
end
|
302
302
|
|
303
303
|
def embedded_section
|
304
|
-
|
304
|
+
embedded = raw.fetch("_embedded", {})
|
305
|
+
|
306
|
+
@embedded_section ||= embedded.merge fully_qualified(embedded)
|
305
307
|
end
|
306
308
|
|
307
309
|
def embedded(link_rel, &default_proc)
|
data/lib/hal_client/version.rb
CHANGED
@@ -2,11 +2,17 @@ require "spec_helper"
|
|
2
2
|
require 'hal-client'
|
3
3
|
|
4
4
|
describe HalClient::LinksSection, "namespaces embedded" do
|
5
|
-
subject(:section) {
|
5
|
+
subject(:section) {
|
6
|
+
described_class.new(raw_section,
|
7
|
+
base_url: Addressable::URI.parse("http://example.com/foo"))
|
8
|
+
}
|
6
9
|
|
7
10
|
specify { expect(section.hrefs("up"))
|
8
11
|
.to contain_exactly "http://example.com/parent" }
|
9
12
|
|
13
|
+
specify { expect(section.hrefs("next"))
|
14
|
+
.to contain_exactly "http://example.com/foo?p=2" }
|
15
|
+
|
10
16
|
specify { expect(section.hrefs(fully_qualified_first_rel))
|
11
17
|
.to contain_exactly "http://example.com/foo" }
|
12
18
|
|
@@ -39,7 +45,8 @@ describe HalClient::LinksSection, "namespaces embedded" do
|
|
39
45
|
"search" => {"href" => "http://example.com/s{?q}", "templated" => true },
|
40
46
|
"ns1:first" => {"href" => "http://example.com/foo"},
|
41
47
|
"ns2:second" => [{"href" => "http://example.com/bar"},
|
42
|
-
{"href" => "http://example.com/baz"}]
|
48
|
+
{"href" => "http://example.com/baz"}],
|
49
|
+
"next" => {"href" => "/foo?p=2"}
|
43
50
|
} }
|
44
51
|
|
45
52
|
matcher :all do |expected|
|
@@ -50,7 +57,10 @@ describe HalClient::LinksSection, "namespaces embedded" do
|
|
50
57
|
end
|
51
58
|
|
52
59
|
describe HalClient::LinksSection, "invalid" do
|
53
|
-
subject(:section) {
|
60
|
+
subject(:section) {
|
61
|
+
described_class.new(raw_section,
|
62
|
+
base_url: Addressable::URI.parse("http://example.com/"))
|
63
|
+
}
|
54
64
|
|
55
65
|
specify { expect{section.hrefs("bareurl")}
|
56
66
|
.to raise_error HalClient::InvalidRepresentationError }
|
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.13.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-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|