Class: Webmention::Endpoint::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/webmention/endpoint/client.rb

Constant Summary collapse

REGEXP_REG_REL_TYPE_PATTERN =

Ultra-orthodox pattern matching allowed values in 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_WEBMENTION_REL_PATTERN =

Ultra-orthodox pattern matching Link header ‘rel` parameter including a `webmention` value www.w3.org/TR/webmention/#sender-discovers-receiver-webmention-endpoint-p-1

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

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Client

Returns a new instance of Client.



16
17
18
19
20
21
22
23
24
# File 'lib/webmention/endpoint/client.rb', line 16

def initialize(url)
  raise ArgumentError, "url must be a String (given #{url.class.name})" unless url.is_a?(String)

  @uri = Addressable::URI.parse(url)

  raise ArgumentError, 'url must be an absolute URI (e.g. https://example.com)' unless @uri.absolute?
rescue Addressable::URI::InvalidURIError => error
  raise InvalidURIError, error
end

Instance Method Details

#endpointObject



26
27
28
29
30
31
32
# File 'lib/webmention/endpoint/client.rb', line 26

def endpoint
  return unless endpoint_from_http_request

  @endpoint ||= Absolutely.to_absolute_uri(base: response.uri.to_s, relative: endpoint_from_http_request)
rescue Absolutely::InvalidURIError => error
  raise InvalidURIError, error
end

#responseObject



34
35
36
# File 'lib/webmention/endpoint/client.rb', line 34

def response
  @response ||= Request.new(@uri).response
end