Sha256: 87b2a69192f1e59234b94ed96a4791f43963b93009306e7128b23189087604d6

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

module IndieWeb
  module Endpoints
    module Parsers
      extend Concerns::Registerable

      class BaseParser
        def initialize(response)
          raise ArgumentError, "response must be an HTTP::Response (given #{response.class.name})" unless response.is_a?(HTTP::Response)

          @response = response
        end

        def results
          mapped_results.shift
        end

        private

        attr_reader :response

        def mapped_results
          @mapped_results ||= results_from_http_request.map { |endpoint| Absolutely.to_abs(base: response.uri.to_s, relative: endpoint) }.uniq.sort
        rescue Absolutely::InvalidURIError => exception
          raise InvalidURIError, exception
        end

        def results_from_body
          @results_from_body ||= Services::ResponseBodyParserService.new.parse(response, self.class.identifier)
        end

        def results_from_headers
          @results_from_headers ||= Services::ResponseHeadersParserService.new.parse(response, self.class.identifier)
        end

        def results_from_http_request
          @results_from_http_request ||= [results_from_headers, results_from_body].flatten.compact
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
indieweb-endpoints-2.0.0 lib/indieweb/endpoints/parsers.rb
indieweb-endpoints-1.1.0 lib/indieweb/endpoints/parsers.rb
indieweb-endpoints-1.0.2 lib/indieweb/endpoints/parsers.rb
indieweb-endpoints-1.0.1 lib/indieweb/endpoints/parsers.rb
indieweb-endpoints-1.0.0 lib/indieweb/endpoints/parsers.rb