Object
Represents the information necessary for an HTTP request. This is basically a data object with validation. Not all fields will be used in every request.
# File lib/patron/request.rb, line 82
82: def action=(new_action)
83: if !VALID_ACTIONS.include?(new_action)
84: raise ArgumentError, "Action must be one of #{VALID_ACTIONS.join(', ')}"
85: end
86:
87: @action = new_action
88: end
# File lib/patron/request.rb, line 122
122: def action_name
123: @action.to_s.upcase
124: end
Set the type of authentication to use for this request.
@param [String, Symbol] type - The type of authentication to use for this request, can be one of
:basic, :digest, or :any
@example
sess.username = "foo" sess.password = "sekrit" sess.auth_type = :digest
# File lib/patron/request.rb, line 56
56: def auth_type=(type=:basic)
57: @auth_type = case type
58: when :basic, "basic"
59: Request::AuthBasic
60: when :digest, "digest"
61: Request::AuthDigest
62: when :any, "any"
63: Request::AuthAny
64: else
65: raise "#{type.inspect} is an unknown authentication type"
66: end
67: end
# File lib/patron/request.rb, line 98
98: def connect_timeout=(new_timeout)
99: if new_timeout && new_timeout.to_i < 1
100: raise ArgumentError, "Timeout must be a positive integer greater than 0"
101: end
102:
103: @connect_timeout = new_timeout.to_i
104: end
# File lib/patron/request.rb, line 126
126: def credentials
127: return nil if username.nil? || password.nil?
128: "#{username}:#{password}"
129: end
# File lib/patron/request.rb, line 114
114: def headers=(new_headers)
115: if !new_headers.kind_of?(Hash)
116: raise ArgumentError, "Headers must be a hash"
117: end
118:
119: @headers = new_headers
120: end
# File lib/patron/request.rb, line 106
106: def max_redirects=(new_max_redirects)
107: if new_max_redirects.to_i < 1
108: raise ArgumentError, "Max redirects must be a positive integer, 0 or -1"
109: end
110:
111: @max_redirects = new_max_redirects.to_i
112: end
# File lib/patron/request.rb, line 90
90: def timeout=(new_timeout)
91: if new_timeout && new_timeout.to_i < 1
92: raise ArgumentError, "Timeout must be a positive integer greater than 0"
93: end
94:
95: @timeout = new_timeout.to_i
96: end
serialize hash for Rails-style params
# File lib/patron/request.rb, line 134
134: def hash_to_string(hash)
135: pairs = []
136: recursive = Proc.new do |h, prefix|
137: h.each_pair do |k,v|
138: key = prefix == '' ? k : "#{prefix}[#{k}]"
139: v.is_a?(Hash) ? recursive.call(v, key) : pairs << "#{key}=#{v}"
140: end
141: end
142: recursive.call(hash, '')
143: return pairs.join('&')
144: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.