hypermedia 1.0.7 → 1.0.8
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/api/api.rb +1 -1
- data/lib/api/document.rb +17 -12
- data/lib/api/link.rb +1 -1
- data/lib/hypermedia.rb +1 -0
- metadata +1 -1
data/lib/api/api.rb
CHANGED
@@ -41,6 +41,6 @@ module HypermediaAPI
|
|
41
41
|
headers = response.to_hash
|
42
42
|
nokogiri_html_document = Nokogiri::HTML::Document.parse(response.body, uri.to_s)
|
43
43
|
|
44
|
-
Document.new(nokogiri_html_document, status, headers)
|
44
|
+
Document.new(nokogiri_html_document, status, headers, auth)
|
45
45
|
end
|
46
46
|
end
|
data/lib/api/document.rb
CHANGED
@@ -8,10 +8,6 @@ class HypermediaAPI::Document
|
|
8
8
|
klass.new_from_fields(article_element.element_children.filter('code'))
|
9
9
|
end
|
10
10
|
|
11
|
-
def entity_with_attribute (klass, kv_pairs)
|
12
|
-
article_element = @document.at_css("article.#{klass.name.underscore}")
|
13
|
-
end
|
14
|
-
|
15
11
|
def entities (klass)
|
16
12
|
article_elements = @document.css("article.#{klass.name.underscore}")
|
17
13
|
article_elements.map {|article_element| klass.new_from_fields(article_element.element_children.filter('code')) }
|
@@ -36,26 +32,35 @@ class HypermediaAPI::Document
|
|
36
32
|
@document.to_html
|
37
33
|
end
|
38
34
|
|
39
|
-
def initialize (nokogiri_html_document, status, headers)
|
35
|
+
def initialize (nokogiri_html_document, status, headers, auth)
|
40
36
|
@document = nokogiri_html_document
|
41
37
|
@status = status.to_i
|
42
38
|
@headers = headers
|
39
|
+
@auth = auth
|
43
40
|
end
|
44
41
|
|
45
42
|
def link (css_selector)
|
46
43
|
if a_element = @document.at_css(css_selector)
|
47
44
|
href_uri = a_element['href']
|
48
|
-
Link.new(
|
45
|
+
HypermediaAPI::Link.new(href_uri)
|
49
46
|
else
|
50
|
-
raise MissingLink, "The API does not have a link matching '#{css_selector}'."
|
47
|
+
raise HypermediaAPI::MissingLink, "The API does not have a link matching '#{css_selector}'."
|
51
48
|
end
|
52
49
|
end
|
53
50
|
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
51
|
+
def look_up_entity (klass, kv_pair)
|
52
|
+
index_link = self.link("nav#index-links a##{klass.name.underscore.pluralize}-link")
|
53
|
+
index_doc = index_link.click(basic_auth: @auth)
|
54
|
+
|
55
|
+
data_name, value = kv_pair.first
|
56
|
+
article_element = index_doc.instance_variable_get(:@document).xpath("//article[@class='#{klass.name.underscore}']/code[@data-name='#{data_name}' and text()='#{value}']/ancestor::article")
|
57
|
+
return nil unless article_element
|
58
|
+
|
59
|
+
bookmark_link_element = article_element.at_css('a[rel="bookmark"]')
|
60
|
+
bookmark_link = HypermediaAPI::Link.new(bookmark_link_element['href'])
|
61
|
+
entity_doc = bookmark_link.click(basic_auth: @auth)
|
62
|
+
|
63
|
+
entity_doc.entity(klass)
|
59
64
|
end
|
60
65
|
|
61
66
|
def status
|
data/lib/api/link.rb
CHANGED
@@ -6,7 +6,7 @@ class HypermediaAPI::Link
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def click (options = {})
|
9
|
-
|
9
|
+
document = HypermediaAPI.get(@href_uri, options)
|
10
10
|
rescue SocketError
|
11
11
|
raise BadURI, "The client was unable to interact with a resource at #{@href_uri}."
|
12
12
|
end
|
data/lib/hypermedia.rb
CHANGED