Sha256: 0a541173a7120d469eab3d68258c21004d1c07077b39eb744916268d3712a1a0

Contents?: true

Size: 766 Bytes

Versions: 3

Compression:

Stored size: 766 Bytes

Contents

module Webmention
  module Verification
    class JsonVerifier < Verifier
      def self.mime_types
        ['application/json']
      end

      private

      def comparator(value)
        value.is_a?(String) && value.match?(target_regexp)
      end

      def locate(object, matches = [])
        if object.is_a?(Enumerable)
          matches << object if object.any? { |_, value| comparator(value) }

          (object.respond_to?(:values) ? object.values : object.entries).each do |obj|
            locate(obj, matches)
          end
        end

        matches
      end

      def parse_response_body
        locate(JSON.parse(response_body))
      end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
webmention-verification-0.1.2 lib/webmention/verification/verifiers/json_verifier.rb
webmention-verification-0.1.1 lib/webmention/verification/verifiers/json_verifier.rb
webmention-verification-0.1.0 lib/webmention/verification/verifiers/json_verifier.rb