Parent

Patron::Session

This class represents multiple request/response transactions with an HTTP server. This is the primary API for Patron.

Attributes

connect_timeout[RW]

HTTP connection timeout in seconds. Defaults to 1 second.

timeout[RW]

HTTP transaction timeout in seconds. Defaults to 5 seconds.

max_redirects[RW]

Maximum number of times to follow redirects. Set to 0 to disable and -1 to follow all redirects. Defaults to 5.

base_url[RW]

Prepended to the URL in all requests.

username[RW]

Username and password for http authentication

password[RW]

Username and password for http authentication

proxy[RW]

HTTP proxy URL

headers[R]

Standard set of headers that are used in all requests.

auth_type[RW]

Set the authentication type for the request. @see Patron::Request#auth_type

insecure[RW]

Does this session stricly verify SSL certificates?

Public Class Methods

new() click to toggle source

Create a new Session object.

    # File lib/patron/session.rb, line 69
69:     def initialize
70:       ext_initialize
71:       @headers = {}
72:       @timeout = 5
73:       @connect_timeout = 1
74:       @max_redirects = 5
75:       @auth_type = :basic
76:     end

Public Instance Methods

copy(url, dest, headers = {}) click to toggle source

Sends a WebDAV COPY request to the specified url.

     # File lib/patron/session.rb, line 151
151:     def copy(url, dest, headers = {})
152:       headers['Destination'] = dest
153:       request(:copy, url, headers)
154:     end
delete(url, headers = {}) click to toggle source

As # but sends an HTTP DELETE request.

     # File lib/patron/session.rb, line 120
120:     def delete(url, headers = {})
121:       request(:delete, url, headers)
122:     end
get(url, headers = {}) click to toggle source

Retrieve the contents of the specified url optionally sending the specified headers. If the base_url varaible is set then it is prepended to the url parameter. Any custom headers are merged with the contents of the headers instance variable. The results are returned in a Response object.

     # File lib/patron/session.rb, line 104
104:     def get(url, headers = {})
105:       request(:get, url, headers)
106:     end
get_file(url, filename, headers = {}) click to toggle source

Retrieve the contents of the specified url as with #, but the content at the URL is downloaded directly into the specified file.

     # File lib/patron/session.rb, line 110
110:     def get_file(url, filename, headers = {})
111:       request(:get, url, headers, :file => filename)
112:     end
handle_cookies(file = nil) click to toggle source

Makes this session handle cookies and store them in in file. If file is nil they will be stored in memory. Otherwise the file must be readable and writable. Calling multiple times will add more files.

    # File lib/patron/session.rb, line 81
81:     def handle_cookies(file = nil)
82:       if file
83:         path = Pathname(file).expand_path
84:         unless File.exists?(file) and File.writable?(path.dirname)
85:           raise ArgumentError, "Can't create file #{path} (permission error)"
86:         end
87:         unless File.readable?(file) or File.writable?(path)
88:           raise ArgumentError, "Cant read or write file #{path} (permission error)"
89:         end
90:       end
91:       enable_cookie_session(path.to_s)
92:       self
93:     end
head(url, headers = {}) click to toggle source

As # but sends an HTTP HEAD request.

     # File lib/patron/session.rb, line 115
115:     def head(url, headers = {})
116:       request(:head, url, headers)
117:     end
post(url, data, headers = {}) click to toggle source

Uploads the passed data to the specified url using HTTP POST. data must be a string.

     # File lib/patron/session.rb, line 137
137:     def post(url, data, headers = {})
138:       request(:post, url, headers, :data => data)
139:     end
post_file(url, filename, headers = {}) click to toggle source

Uploads the contents of a file to the specified url using HTTP POST.

     # File lib/patron/session.rb, line 142
142:     def post_file(url, filename, headers = {})
143:       request(:post, url, headers, :file => filename)
144:     end
put(url, data, headers = {}) click to toggle source

Uploads the passed data to the specified url using HTTP PUT. data must be a string.

     # File lib/patron/session.rb, line 126
126:     def put(url, data, headers = {})
127:       request(:put, url, headers, :data => data)
128:     end
put_file(url, filename, headers = {}) click to toggle source

Uploads the contents of a file to the specified url using HTTP PUT.

     # File lib/patron/session.rb, line 131
131:     def put_file(url, filename, headers = {})
132:       request(:put, url, headers, :file => filename)
133:     end
request(action, url, headers, options = {}) click to toggle source

Send an HTTP request to the specified url.

     # File lib/patron/session.rb, line 161
161:     def request(action, url, headers, options = {})
162:       # If the Expect header isn't set uploads are really slow
163:       headers['Expect'] ||= ''
164: 
165:       req = Request.new
166:       req.action = action
167:       req.timeout = self.timeout
168:       req.connect_timeout = self.connect_timeout
169:       req.max_redirects = self.max_redirects
170:       req.headers = self.headers.merge(headers)
171:       req.username = self.username
172:       req.password = self.password
173:       req.upload_data = options[:data]
174:       req.file_name = options[:file]
175:       req.proxy = proxy
176:       req.auth_type = auth_type
177:       req.insecure = insecure
178: 
179:       req.url = self.base_url.to_s + url.to_s
180:       raise ArgumentError, "Empty URL" if req.url.empty?
181: 
182:       handle_request(req)
183:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.