class Webmention::Verification::Client
Constants
- HTTP_CLIENT_HEADERS
Attributes
source[R]
target[R]
Public Class Methods
new(source, target, **options)
click to toggle source
Create a client used to determine whether or not source URI links to target URI.
@example
source = 'https://source.example.com/post/100' target = 'https://target.example.com/post/100' client = Webmention::Verification::Client.new(source, target) puts client.verified? #=> TrueClass or FalseClass
@param source [String] @param target [String] @param options [Hash] @option options [Boolean] :strict (true)
# File lib/webmention/verification/client.rb, line 26 def initialize(source, target, **options) @source = source.to_str @target = target.to_str @options = options raise ArgumentError, 'source must be an absolute URI (e.g. https://example.com/post/100)' unless source_uri.absolute? raise ArgumentError, 'target must be an absolute URI (e.g. https://example.com/post/100)' unless target_uri.absolute? end
Public Instance Methods
inspect()
click to toggle source
@return [String]
# File lib/webmention/verification/client.rb, line 36 def inspect format(%(#<#{self.class.name}:%#0x source: #{source.inspect} target: #{target.inspect} options: #{@options.inspect}>), object_id) end
response()
click to toggle source
@return [HTTP::Response] @raise [Webmention::Verification::ConnectionError, Webmention::Verification::TimeoutError, Webmention::Verification::TooManyRedirectsError]
# File lib/webmention/verification/client.rb, line 42 def response @response ||= HTTP.follow.headers(HTTP_CLIENT_HEADERS).timeout(connect: 10, read: 10).get(source_uri) rescue HTTP::Error => exception raise HttpError, exception end
source_uri()
click to toggle source
@return [Addressable::URI] @raise [Webmention::Verification::InvalidURIError]
# File lib/webmention/verification/client.rb, line 50 def source_uri @source_uri ||= Addressable::URI.parse(source) rescue Addressable::URI::InvalidURIError => exception raise InvalidURIError, exception end
target_uri()
click to toggle source
@return [Addressable::URI] @raise [Webmention::Verification::InvalidURIError]
# File lib/webmention/verification/client.rb, line 58 def target_uri @target_uri ||= Addressable::URI.parse(target) rescue Addressable::URI::InvalidURIError => exception raise InvalidURIError, exception end
verified?()
click to toggle source
@return [Boolean] @raise [Webmention::Verification::UnsupportedMimeTypeError]
# File lib/webmention/verification/client.rb, line 66 def verified? raise UnsupportedMimeTypeError, "Unsupported MIME Type: #{response.mime_type}" unless verifier_for_mime_type verifier_for_mime_type.new(response, target, **@options).verified? end
Private Instance Methods
verifier_for_mime_type()
click to toggle source
# File lib/webmention/verification/client.rb, line 74 def verifier_for_mime_type @verifier_for_mime_type ||= Verifiers.registered[response.mime_type] end