Class: Webmention::Verification::Client
- Inherits:
-
Object
- Object
- Webmention::Verification::Client
- Defined in:
- lib/webmention/verification/client.rb
Constant Summary collapse
- HTTP_HEADERS_OPTS =
{ accept: '*/*', user_agent: 'Webmention Verification Client (https://rubygems.org/gems/webmention-verification)' }.freeze
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(source, target, **options) ⇒ Client
constructor
A new instance of Client.
- #response ⇒ Object
- #source_uri ⇒ Object
- #target_uri ⇒ Object
- #verified? ⇒ Boolean
Constructor Details
#initialize(source, target, **options) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/webmention/verification/client.rb', line 11 def initialize(source, target, **) raise ArgumentError, "source must be a String (given #{source.class.name})" unless source.is_a?(String) raise ArgumentError, "target must be a String (given #{target.class.name})" unless target.is_a?(String) @source = source @target = target @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 |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
9 10 11 |
# File 'lib/webmention/verification/client.rb', line 9 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
9 10 11 |
# File 'lib/webmention/verification/client.rb', line 9 def target @target end |
Instance Method Details
#response ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/webmention/verification/client.rb', line 23 def response @response ||= HTTP.follow.headers(HTTP_HEADERS_OPTS).timeout(connect: 10, read: 10).get(source_uri) rescue HTTP::ConnectionError, HTTP::TimeoutError, HTTP::Redirector::TooManyRedirectsError => exception raise Webmention::Verification.const_get(exception.class.name.split('::').last), exception end |
#source_uri ⇒ Object
31 32 33 34 35 |
# File 'lib/webmention/verification/client.rb', line 31 def source_uri @source_uri ||= Addressable::URI.parse(source) rescue Addressable::URI::InvalidURIError => exception raise InvalidURIError, exception end |
#target_uri ⇒ Object
37 38 39 40 41 |
# File 'lib/webmention/verification/client.rb', line 37 def target_uri @target_uri ||= Addressable::URI.parse(target) rescue Addressable::URI::InvalidURIError => exception raise InvalidURIError, exception end |
#verified? ⇒ Boolean
43 44 45 46 47 |
# File 'lib/webmention/verification/client.rb', line 43 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 |