Class: Discodactyl::HostMetaJRD

Inherits:
JRD::Document show all
Defined in:
lib/discodactyl/host_meta_jrd.rb

Class Method Summary collapse

Methods inherited from JRD::Document

#links, #links_by_rel, parse, #rels, #subject, #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_jrd.rb', line 17

def self.from_uri(uri)
  uri = get_uri_from_uri(uri)
  Discodactyl.log.debug("got jrd 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_jrd.rb', line 11

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