class WebFetch::Request

Attributes

body[RW]
custom[RW]
headers[RW]
method[W]
query[RW]
url[RW]

Public Class Methods

build_request(hash) click to toggle source
# File lib/web_fetch/request.rb, line 48
def build_request(hash)
  Request.new do |request|
    %i[url query headers body method custom].each do |key|
      request.send("#{key}=", hash.delete(key))
    end
  end
end
from_hash(hash, options = {}) click to toggle source
# File lib/web_fetch/request.rb, line 38
def self.from_hash(hash, options = {})
  hash_copy = hash.dup
  request = build_request(hash_copy)
  return request unless options.fetch(:validate, true)
  raise ArgumentError, "Unrecognized keys: #{hash}" unless hash_copy.empty?

  request
end
new() { |self| ... } click to toggle source
# File lib/web_fetch/request.rb, line 8
def initialize
  @method = 'GET'
  yield self
end

Public Instance Methods

==(other) click to toggle source
# File lib/web_fetch/request.rb, line 34
def ==(other)
  eql?(other)
end
eql?(other) click to toggle source
# File lib/web_fetch/request.rb, line 28
def eql?(other)
  # Makes testing WebFetch a bit easier (based on real world case I hit
  # using WebFetch in a Rails app)
  other.to_h == to_h
end
method() click to toggle source
# File lib/web_fetch/request.rb, line 13
def method
  @method.downcase.to_sym
end
to_h() click to toggle source
# File lib/web_fetch/request.rb, line 17
def to_h
  {
    url: url,
    query: query,
    headers: headers,
    body: body,
    method: method,
    custom: custom
  }
end