Class: Discodactyl::HostMeta

Inherits:
XRD::Document show all
Defined in:
lib/discodactyl/host_meta.rb

Overview

Convienient access to host metadata and individual resources controlled by the host. See also: tools.ietf.org/html/draft-hammer-hostmeta

Instance Attribute Summary

Attributes inherited from XRD::Document

#raw

Class Method Summary collapse

Methods inherited from XRD::Document

#append, #escapeXPath, #find_all_links_by_rel, #find_link_by_id, #generate_tag_uri, #ids, #linkelems_by_rel, #links, #links_by_rel, parse, #rels, #subject, #to_s, #uris_by_rel

Class Method Details

.from_uri(uri) ⇒ Object

Take a URI and retrieve its HostMeta document


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/discodactyl/host_meta.rb', line 17

def from_uri(uri)
  uri = get_uri_from_uri(uri)
  Discodactyl.log.debug("got xrd host-meta uri: #{uri}") if Discodactyl.log
  begin
    raw = uri.open
  rescue OpenURI::HTTPError => error
    if error.io.status[1] == 'Not Found'
      error.io.base_uri = uri
      raise HostMetaHTTPError.new(error.message, error.io)
    else
      raise
    end
  rescue ::SocketError => error
    raise HostMetaSocketError.new(error.message, uri.host, uri.port)
  end
  self.parse raw
end

.get_uri_from_uri(uri) ⇒ Object

Take a URI and return the URI for its HostMeta document


11
12
13
14
# File 'lib/discodactyl/host_meta.rb', line 11

def get_uri_from_uri(uri)
  host = uri.respond_to?('host') ? uri.host : uri
  URI.parse('http://'+ host + '/.well-known/host-meta')
end