Parent

HTTPI::Request

HTTPI::Request

Represents an HTTP request and contains various methods for customizing that request.

Constants

ATTRIBUTES

Available attribute writers.

Attributes

body[R]
open_timeout[RW]
proxy[R]

Returns the proxy to use.

read_timeout[RW]
ssl[W]

Sets whether to use SSL.

url[R]

Returns the url to access.

Public Class Methods

new(args = {}) click to toggle source

Accepts a Hash of args to mass assign attributes and authentication credentials.

# File lib/httpi/request.rb, line 16
def initialize(args = {})
  if args.kind_of? String
    self.url = args
  elsif args.kind_of?(Hash) && !args.empty?
    mass_assign args
  end
end

Public Instance Methods

auth() click to toggle source

Returns the HTTPI::Authentication object.

# File lib/httpi/request.rb, line 74
def auth
  @auth ||= Auth::Config.new
end
auth?() click to toggle source

Returns whether any authentication credentials were specified.

# File lib/httpi/request.rb, line 79
def auth?
  !!auth.type
end
body=(params) click to toggle source

Sets a body request given a String or a Hash.

# File lib/httpi/request.rb, line 69
def body=(params)
  @body = params.kind_of?(Hash) ? Rack::Utils.build_query(params) : params
end
gzip() click to toggle source

Adds a header information to accept gzipped content.

# File lib/httpi/request.rb, line 61
def gzip
  headers["Accept-Encoding"] = "gzip,deflate"
end
headers() click to toggle source

Returns a Hash of HTTP headers. Defaults to return an empty Hash.

# File lib/httpi/request.rb, line 51
def headers
  @headers ||= Rack::Utils::HeaderHash.new
end
headers=(headers) click to toggle source

Sets the Hash of HTTP headers.

# File lib/httpi/request.rb, line 56
def headers=(headers)
  @headers = Rack::Utils::HeaderHash.new(headers)
end
mass_assign(args) click to toggle source

Expects a Hash of args to assign.

# File lib/httpi/request.rb, line 84
def mass_assign(args)
  ATTRIBUTES.each { |key| send("#{key}=", args[key]) if args[key] }
end
proxy=(proxy) click to toggle source

Sets the proxy to use. Raises an ArgumentError unless the proxy is valid.

# File lib/httpi/request.rb, line 34
def proxy=(proxy)
  @proxy = normalize_url! proxy
end
ssl?() click to toggle source

Returns whether to use SSL.

# File lib/httpi/request.rb, line 42
def ssl?
  return @ssl unless @ssl.nil?
  !!(url.to_s =~ /^https/)
end
url=(url) click to toggle source

Sets the url to access. Raises an ArgumentError unless the url is valid.

# File lib/httpi/request.rb, line 25
def url=(url)
  @url = normalize_url! url
  auth.basic @url.user, @url.password || '' if @url.user
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.