Parent

Patron::Request

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.

Constants

VALID_ACTIONS
AuthBasic
AuthDigest
AuthAny

Attributes

url[RW]
username[RW]
password[RW]
file_name[RW]
proxy[RW]
auth_type[RW]
insecure[RW]
action[R]
timeout[R]
connect_timeout[R]
max_redirects[R]
headers[R]
auth_type[R]

Public Class Methods

new() click to toggle source
    # File lib/patron/request.rb, line 35
35:     def initialize
36:       @action = :get
37:       @headers = {}
38:       @timeout = 0
39:       @connect_timeout = 0
40:       @max_redirects = 1
41:     end

Public Instance Methods

action=(new_action) click to toggle source
    # 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
action_name() click to toggle source
     # File lib/patron/request.rb, line 122
122:     def action_name
123:       @action.to_s.upcase
124:     end
auth_type=(type=:basic) click to toggle source

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
connect_timeout=(new_timeout) click to toggle source
     # 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
credentials() click to toggle source
     # File lib/patron/request.rb, line 126
126:     def credentials
127:       return nil if username.nil? || password.nil?
128:       "#{username}:#{password}"
129:     end
headers=(new_headers) click to toggle source
     # 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
max_redirects=(new_max_redirects) click to toggle source
     # 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
timeout=(new_timeout) click to toggle source
    # 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
upload_data() click to toggle source
    # File lib/patron/request.rb, line 78
78:     def upload_data
79:       @upload_data
80:     end
upload_data=(data) click to toggle source
    # File lib/patron/request.rb, line 69
69:     def upload_data=(data)
70:       @upload_data = case data
71:       when Hash
72:         hash_to_string(data)
73:       else
74:         data
75:       end
76:     end

Private Instance Methods

hash_to_string(hash) click to toggle source

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.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.