Sha256: 40840d10ca404413627c66298463c78dc727cc4e1255b8b72a11ab799936d1d8

Contents?: true

Size: 888 Bytes

Versions: 1

Compression:

Stored size: 888 Bytes

Contents

module Webmention
  module Verification
    class BaseVerifier
      class << self
        attr_reader :mime_types
      end

      def initialize(response, target, **options)
        @response = response
        @target = target.to_str
        @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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
webmention-verification-5.0.0 lib/webmention/verification/verifiers/base_verifier.rb