Sha256: 7d368167444d33f5715f4dabede4c511f45fb515bb76c58701e43cce47b3ea73

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module Aranha
  module Parsers
    module Firefox
      class RequestFromFirefox
        BASE_URL_SUBPATH = 'base_url'
        BODY_SUBPATH = 'body'
        REQUEST_SUBPATH = 'request'

        class << self
          def from_directory(path)
            path = path.to_pathname
            body_path = path.join(BODY_SUBPATH)
            new(
              path.join(BASE_URL_SUBPATH).read.strip,
              ::Aranha::Parsers::Firefox::RequestHeaderFromFirefox
              .from_file(path.join(REQUEST_SUBPATH)),
              body_path.file? ? body_path.read : nil
            )
          end
        end

        enable_simple_cache
        common_constructor :the_base_uri, :header, :body, default: [nil] do
          self.the_base_uri = the_base_uri.to_uri
        end

        def to_uri_source
          {
            method: header.verb,
            url: url,
            headers: header.headers,
            body: body
          }
        end

        def url
          (the_base_uri + header.uri).to_s
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aranha-parsers-0.25.0 lib/aranha/parsers/firefox/request_from_firefox.rb
aranha-parsers-0.24.0 lib/aranha/parsers/firefox/request_from_firefox.rb