Object
This class represents multiple request/response transactions with an HTTP server. This is the primary API for Patron.
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
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
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
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
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
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
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
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
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
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
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.
Generated with the Darkfish Rdoc Generator 1.1.6.