Class: DiasporaFederation::Discovery::HostMeta
- Inherits:
-
Object
- Object
- DiasporaFederation::Discovery::HostMeta
- Defined in:
- lib/diaspora_federation/discovery/host_meta.rb
Overview
Generates and parses Host Meta documents.
This is a minimal implementation of the standard, only to the degree of what is used for the purposes of the diaspora* protocol. (e.g. WebFinger)
Constant Summary collapse
- WEBFINGER_SUFFIX =
URL fragment to append to the base URL
"/webfinger?q={uri}".freeze
Class Method Summary collapse
-
.from_base_url(base_url) ⇒ HostMeta
Builds a new HostMeta instance and constructs the WebFinger URL from the given base URL by appending HostMeta::WEBFINGER_SUFFIX.
-
.from_xml(hostmeta_xml) ⇒ Object
Reads the given Host Meta XML document string and populates the
webfinger_url
.
Instance Method Summary collapse
-
#initialize(webfinger_url) ⇒ HostMeta
constructor
Creates a new host-meta instance.
-
#to_xml ⇒ String
Produces the XML string for the Host Meta instance with a
Link
element containing thewebfinger_url
. -
#webfinger_template_url ⇒ String
Returns the WebFinger URL that was used to build this instance (either from xml or by giving a base URL).
Constructor Details
#initialize(webfinger_url) ⇒ HostMeta
Creates a new host-meta instance
24 25 26 |
# File 'lib/diaspora_federation/discovery/host_meta.rb', line 24 def initialize(webfinger_url) @webfinger_url = webfinger_url end |
Class Method Details
.from_base_url(base_url) ⇒ HostMeta
Builds a new HostMeta instance and constructs the WebFinger URL from the given base URL by appending HostMeta::WEBFINGER_SUFFIX.
54 55 56 57 58 59 |
# File 'lib/diaspora_federation/discovery/host_meta.rb', line 54 def self.from_base_url(base_url) webfinger_url = "#{base_url.to_s.chomp('/')}#{WEBFINGER_SUFFIX}" raise InvalidData, "invalid webfinger url: #{webfinger_url}" unless webfinger_url_valid?(webfinger_url) new(webfinger_url) end |
.from_xml(hostmeta_xml) ⇒ Object
Reads the given Host Meta XML document string and populates the webfinger_url
.
65 66 67 68 69 70 71 72 73 |
# File 'lib/diaspora_federation/discovery/host_meta.rb', line 65 def self.from_xml() data = XrdDocument.xml_data() raise InvalidData, "received an invalid xml" unless data.key?(:links) webfinger_url = webfinger_url_from_xrd(data) raise InvalidData, "invalid webfinger url: #{webfinger_url}" unless webfinger_url_valid?(webfinger_url) new(webfinger_url) end |
Instance Method Details
#to_xml ⇒ String
Produces the XML string for the Host Meta instance with a Link
element containing the webfinger_url
.
41 42 43 44 45 46 47 |
# File 'lib/diaspora_federation/discovery/host_meta.rb', line 41 def to_xml doc = XrdDocument.new doc.links << {rel: "lrdd", type: "application/xrd+xml", template: @webfinger_url} doc.to_xml end |
#webfinger_template_url ⇒ String
Returns the WebFinger URL that was used to build this instance (either from xml or by giving a base URL).
34 35 36 |
# File 'lib/diaspora_federation/discovery/host_meta.rb', line 34 def webfinger_template_url @webfinger_url end |