Class: RedirectUri::Discover

Inherits:
Object
  • Object
show all
Defined in:
lib/redirect_uri/discover.rb

Constant Summary collapse

REGEXP_REG_REL_TYPE_PATTERN =

Ultra-orthodox pattern matching allowed values in HTTP Link header ‘rel` parameter tools.ietf.org/html/rfc8288#section-3.3

'[a-z\d][a-z\d\-\.]*'.freeze
REGEXP_TARGET_URI_PATTERN =

Liberal pattern matching a string of text between angle brackets tools.ietf.org/html/rfc5988#section-5.1

/^<(.*)>;/.freeze
REGEXP_REDIRECT_URI_REL_PATTERN =

Ultra-orthodox pattern matching HTTP Link header ‘rel` parameter including an `redirect_uri` value www.w3.org/TR/indieauth/#x4-discovery

/(?:;|\s)rel="?(?:#{REGEXP_REG_REL_TYPE_PATTERN}+\s)?redirect_uri(?:\s#{REGEXP_REG_REL_TYPE_PATTERN})?"?/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Discover

Returns a new instance of Discover.

Raises:



15
16
17
18
19
# File 'lib/redirect_uri/discover.rb', line 15

def initialize(response)
  raise ArgumentError, "response must be an HTTP::Response (given #{response.class.name})" unless response.is_a?(HTTP::Response)

  @response = response
end

Instance Method Details

#endpointsObject



21
22
23
24
25
# File 'lib/redirect_uri/discover.rb', line 21

def endpoints
  @endpoints ||= endpoints_from_http_request.map { |endpoint| Absolutely.to_absolute_uri(base: @response.uri.to_s, relative: endpoint) }.uniq.sort
rescue Absolutely::InvalidURIError => error
  raise InvalidURIError, error
end