hal-client 3.12.0 → 3.13.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: 95db91d4db8f1599d671ef361262bdbb22f64808
4
- data.tar.gz: 7d293f6b47f9ee2512938f42c9bf54ee96f73b32
3
+ metadata.gz: 553aacea1a5e60830f4444b701d714433dcb7fbc
4
+ data.tar.gz: dacb874f8b57a68e908028dee737b7d48cae4ce0
5
5
  SHA512:
6
- metadata.gz: d5be9718970338b4fc5b4b618b06297054fb3b855e1fe31b810df008f9ff11cb6bac7787adc2a5bf3b6da7b712b5a5f75bbea7af437c63b76f5e7a1f24c1c6b0
7
- data.tar.gz: 32533202e76e007b18864ef1bd5ce149b32bf8f4f144df3b23348d61d307c21608ecc4a60ad0262aaf4ec4648bd0680d3c487d1f2533394fd1517577113865e5
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
- def initialize(section, namespaces=nil)
8
- @namespaces = namespaces || CurieResolver.new(section.fetch("curies"){[]})
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 ||= if has_related? "self"
107
- links.hrefs('self').first
108
- else
109
- nil
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 raw.fetch("_links"){{}}
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
- @embedded_section ||= fully_qualified raw.fetch("_embedded", {})
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)
@@ -1,3 +1,3 @@
1
1
  class HalClient
2
- VERSION = "3.12.0"
2
+ VERSION = "3.13.0"
3
3
  end
@@ -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) { described_class.new(raw_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) { described_class.new(raw_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.12.0
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-22 00:00:00.000000000 Z
11
+ date: 2015-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http