Class: Webmention::Verification::Client
- Inherits:
-
Object
- Object
- Webmention::Verification::Client
- Defined in:
- lib/webmention/verification/client.rb
Constant Summary collapse
- HTTP_CLIENT_HEADERS =
{ accept: '*/*', user_agent: 'Webmention Verification Client (https://rubygems.org/gems/webmention-verification)' }.freeze
Class Attribute Summary collapse
-
.registered_verifiers ⇒ Object
readonly
Returns the value of attribute registered_verifiers.
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(source, target, **options) ⇒ Client
constructor
Create a client used to determine whether or not source URI links to target URI.
- #inspect ⇒ String
- #response ⇒ HTTP::Response
- #source_uri ⇒ HTTP::URI
- #target_uri ⇒ HTTP::URI
- #verified? ⇒ Boolean
Constructor Details
#initialize(source, target, **options) ⇒ Client
Create a client used to determine whether or not source URI links to target URI.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/webmention/verification/client.rb', line 38 def initialize(source, target, **) @source = source.to_str @target = target.to_str @options = = 'must be an absolute URI (e.g. https://example.com/post/100)' raise ArgumentError, "source #{}" unless absolute?(source_uri) raise ArgumentError, "target #{}" unless absolute?(target_uri) end |
Class Attribute Details
.registered_verifiers ⇒ Object (readonly)
Returns the value of attribute registered_verifiers.
14 15 16 |
# File 'lib/webmention/verification/client.rb', line 14 def registered_verifiers @registered_verifiers end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
17 18 19 |
# File 'lib/webmention/verification/client.rb', line 17 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
17 18 19 |
# File 'lib/webmention/verification/client.rb', line 17 def target @target end |
Class Method Details
.register_verifier(klass) ⇒ Object
19 20 21 |
# File 'lib/webmention/verification/client.rb', line 19 def self.register_verifier(klass) klass.mime_types.each { |mime_type| @registered_verifiers[mime_type] = klass } end |
Instance Method Details
#inspect ⇒ String
50 51 52 53 54 55 |
# File 'lib/webmention/verification/client.rb', line 50 def inspect "#<#{self.class.name}:#{format('%#0x', object_id)} " \ "source: #{source.inspect} " \ "target: #{target.inspect} " \ "options: #{@options.inspect}>" end |
#response ⇒ HTTP::Response
59 60 61 62 63 64 65 |
# File 'lib/webmention/verification/client.rb', line 59 def response @response ||= HTTP.follow.headers(HTTP_CLIENT_HEADERS).timeout(connect: 10, read: 10).get(source_uri) rescue HTTP::Error => e raise HttpError, e rescue OpenSSL::SSL::SSLError => e raise SSLError, e end |
#source_uri ⇒ HTTP::URI
69 70 71 72 73 |
# File 'lib/webmention/verification/client.rb', line 69 def source_uri @source_uri ||= HTTP::URI.parse(source) rescue Addressable::URI::InvalidURIError => e raise InvalidURIError, e end |
#target_uri ⇒ HTTP::URI
77 78 79 80 81 |
# File 'lib/webmention/verification/client.rb', line 77 def target_uri @target_uri ||= HTTP::URI.parse(target) rescue Addressable::URI::InvalidURIError => e raise InvalidURIError, e end |
#verified? ⇒ Boolean
85 86 87 88 89 90 91 92 |
# File 'lib/webmention/verification/client.rb', line 85 def verified? self.class .registered_verifiers[response.mime_type] .new(response, target, **@options) .verified? rescue NoMethodError raise UnsupportedMimeTypeError, "Unsupported MIME Type: #{response.mime_type}" end |