class IndieAuthDiscovery::Profile

User profile information discovery according to the IndieAuth spec.

@see indieauth.spec.indieweb.org/#discovery-by-clients

Attributes

authorization_endpoint[R]
micropub_endpoint[R]
response[R]
token_endpoint[R]
url[R]

Public Class Methods

discover(url) click to toggle source

Returns a new Profile after canonicalizing and verifying the URL and discovering endpoints.

# File lib/indieauth_discovery/profile.rb, line 23
def self.discover(url)
  new(url).discover
end
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

discover() click to toggle source

Returns the Profile after canonicalizing and verifying the URL and discovering endpoints.

# File lib/indieauth_discovery/profile.rb, line 28
def discover
  canonicalize_url
  fetch_profile
  find_endpoints
  self
end

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
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