class Goldfinger::Client
Public Class Methods
new(uri, opts = {})
click to toggle source
# File lib/goldfinger/client.rb, line 10 def initialize(uri, opts = {}) @uri = uri @ssl = opts.delete(:ssl) { true } @scheme = @ssl ? 'https' : 'http' @opts = opts end
Public Instance Methods
finger()
click to toggle source
# File lib/goldfinger/client.rb, line 17 def finger response = perform_get(standard_url, @opts) return finger_from_template if response.code != 200 Goldfinger::Result.new(response) rescue Addressable::URI::InvalidURIError raise Goldfinger::NotFoundError, 'Invalid URI' end
Private Instance Methods
domain()
click to toggle source
# File lib/goldfinger/client.rb, line 60 def domain @uri.split('@').last end
finger_from_template()
click to toggle source
# File lib/goldfinger/client.rb, line 29 def finger_from_template template = perform_get(url, @opts) raise Goldfinger::NotFoundError, 'No host-meta on the server' if template.code != 200 response = perform_get(url_from_template(template.body), @opts) raise Goldfinger::NotFoundError, 'No such user on the server' if response.code != 200 Goldfinger::Result.new(response) end
standard_url()
click to toggle source
# File lib/goldfinger/client.rb, line 45 def standard_url "#{@scheme}://#{domain}/.well-known/webfinger?resource=#{@uri}" end
url()
click to toggle source
# File lib/goldfinger/client.rb, line 41 def url "#{@scheme}://#{domain}/.well-known/host-meta" end
url_from_template(template)
click to toggle source
# File lib/goldfinger/client.rb, line 49 def url_from_template(template) xml = Nokogiri::XML(template) links = xml.xpath('//xmlns:Link[@rel="lrdd"]') raise Goldfinger::NotFoundError if links.empty? links.first.attribute('template').value.gsub('{uri}', @uri) rescue Nokogiri::XML::XPath::SyntaxError raise Goldfinger::Error, "Bad XML: #{template}" end