Class: HTTPalooza::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/httpalooza/request.rb

Overview

Request presents a standard interface for describing an HTTP request that Players can translate into the underlying library’s representation.

Constant Summary collapse

STANDARD_METHODS =
[:get, :post, :put, :patch, :delete, :options, :head]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, method, options = {}) ⇒ Request

Instantiate a Request.

Parameters:

  • url (String)

    the URL to request

  • method (Symbol)

    the HTTP method

  • options (Hash) (defaults to: {})

    additional options

Options Hash (options):

  • :params (Hash)

    the URL parameters

  • :headers (Hash)

    the request headers

  • :payload (String)

    the request payload



26
27
28
29
30
31
32
33
34
# File 'lib/httpalooza/request.rb', line 26

def initialize(url, method, options = {})
  @url = url
  @method = method
  @params = options[:params] || {}
  @payload = options[:payload]
  @headers = Rack::Utils::HeaderHash.new(options[:headers] || {})

  normalize_url!
end

Instance Attribute Details

#headersHash (readonly)

Returns the request headers.

Returns:

  • (Hash)

    the request headers



7
8
9
# File 'lib/httpalooza/request.rb', line 7

def headers
  @headers
end

#methodSymbol (readonly)

Returns the HTTP method.

Returns:

  • (Symbol)

    the HTTP method



7
8
9
# File 'lib/httpalooza/request.rb', line 7

def method
  @method
end

#paramsHash (readonly)

Returns the URL parameters.

Returns:

  • (Hash)

    the URL parameters



7
8
9
# File 'lib/httpalooza/request.rb', line 7

def params
  @params
end

#payloadString (readonly)

Returns the request body.

Returns:

  • (String)

    the request body



7
8
9
# File 'lib/httpalooza/request.rb', line 7

def payload
  @payload
end

#urlString (readonly)

Returns the URL to request.

Returns:

  • (String)

    the URL to request



7
8
9
# File 'lib/httpalooza/request.rb', line 7

def url
  @url
end

Instance Method Details

#ssl?Boolean

Returns whether or not the URL is SSL.

Returns:

  • (Boolean)

    whether or not the URL is SSL



37
38
39
# File 'lib/httpalooza/request.rb', line 37

def ssl?
  !!(url.to_s =~ /^https/)
end