class IndieAuthDiscovery::Profile
User profile information discovery according to the IndieAuth spec.
Attributes
micropub_endpoint[R]
response[R]
token_endpoint[R]
url[R]
Public Class Methods
discover(url)
click to toggle source
new(url)
click to toggle source
# File lib/indieauth_discovery/profile.rb, line 18 def initialize(url) @url = URL.new(url) end
Public Instance Methods
Private Instance Methods
canonicalize_url()
click to toggle source
# File lib/indieauth_discovery/profile.rb, line 37 def canonicalize_url url.canonicalize end
fetch_profile()
click to toggle source
# File lib/indieauth_discovery/profile.rb, line 41 def fetch_profile @response ||= get_follow_redirects(url.to_s) @link_headers = parse_link_headers(response) @profile_document = parse_html_document(response) end
find_endpoints()
click to toggle source
# File lib/indieauth_discovery/profile.rb, line 47 def find_endpoints @authorization_endpoint = first_link('authorization_endpoint') @token_endpoint = first_link('token_endpoint') @micropub_endpoint = first_link('micropub') end
first_link(rel)
click to toggle source
# File lib/indieauth_discovery/profile.rb, line 65 def first_link(rel) @link_headers[rel.to_sym]&.first&.target_uri || @profile_document.at_xpath("//link[@rel='#{rel}']")&.attribute('href')&.to_s end
get_follow_redirects(url)
click to toggle source
# File lib/indieauth_discovery/profile.rb, line 70 def get_follow_redirects(url) Faraday.new(url: url) do |faraday| faraday.use(FaradayMiddleware::FollowRedirects) faraday.adapter(Faraday.default_adapter) end.get end
parse_html_document(response)
click to toggle source
# File lib/indieauth_discovery/profile.rb, line 59 def parse_html_document(response) return Nokogiri::HTML('') unless response.headers['content-type'].start_with?('text/html') Nokogiri::HTML(response.body) end
parse_link_headers(response)
click to toggle source
# File lib/indieauth_discovery/profile.rb, line 53 def parse_link_headers(response) return {} unless response.headers['link'] LinkHeaderParser.parse(response.headers['link'], base: url.to_s).group_by_relation_type end