class Patron::Request
used in every request.
This is basically a data object with validation. Not all fields will be
Represents the information necessary for an HTTP request.
def action=(action)
-
action
(String
) -- the name of the HTTP verb
def action=(action) if !VALID_ACTIONS.include?(action.to_s.upcase) raise ArgumentError, "Action must be one of #{VALID_ACTIONS.join(', ')}" end @action = action.downcase.to_sym end
def action_name
-
(String)
- the HTTP verb
def action_name @action.to_s.upcase end
def auth_type=(type=:basic)
-
type
(String, Symbol
) -- The type of authentication to use for this request, can be one of
def auth_type=(type=:basic) @auth_type = case type when :basic, "basic" Request::AuthBasic when :digest, "digest" Request::AuthDigest when :any, "any" Request::AuthAny else raise "#{type.inspect} is an unknown authentication type" end end
def buffer_size=(buffer_size)
-
buffer_size
(Integer, nil
) -- the desired buffer size, or `nil` for automatic buffer size
def buffer_size=(buffer_size) if buffer_size != nil && buffer_size.to_i < 1 raise ArgumentError, "Buffer size must be a positive integer greater than 0 or nil" end @buffer_size = buffer_size != nil ? buffer_size.to_i : nil end
def connect_timeout=(new_timeout)
-
new_timeout
(Integer
) -- the number of seconds to wait before raising a timeout error
def connect_timeout=(new_timeout) if new_timeout && new_timeout.to_i < 1 raise ArgumentError, "Timeout must be a positive integer greater than 0" end @connect_timeout = new_timeout.to_i end
def credentials
-
(String, NilClass)
- the authentication string or nil if no authentication is used
def credentials return nil if username.nil? || password.nil? "#{username}:#{password}" end
def eql?(request)
-
(TrueClass, FalseClass)
-
def eql?(request) return false unless Request === request READER_VARS.inject(true) do |memo, name| memo && (self.send(name) == request.send(name)) end end
def headers=(new_headers)
-
new_headers
(Hash
) -- the hash of headers to set.
def headers=(new_headers) if !new_headers.kind_of?(Hash) raise ArgumentError, "Headers must be a hash" end @headers = new_headers end
def initialize
Initializes a new Request, which defaults to the GET HTTP verb and
def initialize @action = :get @headers = {} @timeout = 0 @connect_timeout = 0 @max_redirects = -1 end
def marshal_dump
-
(Array)
-
def marshal_dump [ @url, @username, @password, @file_name, @proxy, @proxy_type, @insecure, @ignore_content_length, @multipart, @action, @timeout, @connect_timeout, @max_redirects, @headers, @auth_type, @upload_data, @buffer_size, @cacert ] end
def marshal_load(data)
-
(void)
-
Parameters:
-
data
(Array
) --
def marshal_load(data) @url, @username, @password, @file_name, @proxy, @proxy_type, @insecure, @ignore_content_length, @multipart, @action, @timeout, @connect_timeout, @max_redirects, @headers, @auth_type, @upload_data, @buffer_size, @cacert = data end
def max_redirects=(new_max_redirects)
-
new_max_redirects
(Integer
) -- The number of redirects to follow, or `-1` for unlimited redirects.
def max_redirects=(new_max_redirects) if new_max_redirects.to_i < -1 raise ArgumentError, "Max redirects must be a positive integer, 0 or -1" end @max_redirects = new_max_redirects.to_i end
def timeout=(new_timeout)
-
new_timeout
(Integer
) -- the number of seconds to wait before raising a timeout error
def timeout=(new_timeout) if new_timeout && new_timeout.to_i < 1 raise ArgumentError, "Timeout must be a positive integer greater than 0" end @timeout = new_timeout.to_i end
def upload_data=(data)
-
data
(Hash, #to_s
) -- a Hash of form fields to values, or an object that responds to `to_s`
def upload_data=(data) @upload_data = case data when Hash self.multipart ? data : Util.build_query_string_from_hash(data, action == :post) else data end end