Sha256: 8276ed85b9cb6f3580d29609db05e6de447c518f8de57047b0f48da4812639dd

Contents?: true

Size: 1.15 KB

Versions: 5

Compression:

Stored size: 1.15 KB

Contents

module Webmention
  module Verification
    module Verifiers
      extend Registerable

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

          @response = response
          @target = target
          @options = options

          raise UnsupportedMimeTypeError, "Unsupported MIME Type: #{response.mime_type}" unless self.class.mime_types.include?(response.mime_type)
        end

        def results
          @results ||= parse_response_body
        end

        def verified?
          results.any?
        end

        private

        def response_body
          @response_body ||= @response.body.to_s
        end

        def target_regexp
          @target_regexp ||= /^#{target_regexp_str}$/
        end

        def target_regexp_str
          return @target if @options.fetch(:strict, true)

          @target.sub(%r{https?://}, 'https?://')
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
webmention-verification-2.0.0 lib/webmention/verification/verifiers.rb
webmention-verification-1.2.0 lib/webmention/verification/verifiers.rb
webmention-verification-1.1.1 lib/webmention/verification/verifiers.rb
webmention-verification-1.1.0 lib/webmention/verification/verifiers.rb
webmention-verification-1.0.0 lib/webmention/verification/verifiers.rb