Enables modification of timeout in RestClient
STATUSES | = | {100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', #WebDAV 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', # http/1.1 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-Status', #WebDAV 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', # http/1.1 304 => 'Not Modified', 305 => 'Use Proxy', # http/1.1 306 => 'Switch Proxy', # no longer used 307 => 'Temporary Redirect', # http/1.1 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Resource Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 418 => 'I\'m A Teapot', 421 => 'Too Many Connections From This IP', 422 => 'Unprocessable Entity', #WebDAV 423 => 'Locked', #WebDAV 424 => 'Failed Dependency', #WebDAV 425 => 'Unordered Collection', #WebDAV 426 => 'Upgrade Required', 449 => 'Retry With', #Microsoft 450 => 'Blocked By Windows Parental Controls', #Microsoft 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported', 506 => 'Variant Also Negotiates', 507 => 'Insufficient Storage', #WebDAV 509 => 'Bandwidth Limit Exceeded', #Apache 510 => 'Not Extended'} |
proxy | [RW] | |
timeout | [RW] |
Add a Proc to be called before each request in executed. The proc parameters will be the http request and the request params.
# File lib/rest-client-1.6.3/lib/restclient.rb, line 161 def self.add_before_execution_proc &proc @@before_execution_procs << proc end
Create a log that respond to << like a logger param can be ‘stdout’, ‘stderr’, a string (then we will log to that file) or a logger (then we return it)
# File lib/rest-client-1.6.3/lib/restclient.rb, line 114 def self.create_log param if param if param.is_a? String if param == 'stdout' stdout_logger = Class.new do def << obj STDOUT.puts obj end end stdout_logger.new elsif param == 'stderr' stderr_logger = Class.new do def << obj STDERR.puts obj end end stderr_logger.new else file_logger = Class.new do attr_writer :target_file def << obj File.open(@target_file, 'a') { |f| f.puts obj } end end logger = file_logger.new logger.target_file = param logger end else param end end end
# File lib/rest-client-1.6.3/lib/restclient.rb, line 83 def self.delete(url, headers={}, &block) Request.execute(:method => :delete, :url => url, :headers => headers, &block) end
# File lib/restclient_fix.rb, line 36 def self.delete(url, headers={}, &block) Request.execute(:method => :delete, :url => url, :headers => headers, :timeout => @timeout, &block) end
# File lib/rest-client-1.6.3/lib/restclient.rb, line 67 def self.get(url, headers={}, &block) Request.execute(:method => :get, :url => url, :headers => headers, &block) end
# File lib/restclient_fix.rb, line 20 def self.get(url, headers={}, &block) Request.execute(:method => :get, :url => url, :headers => headers, :timeout => @timeout, &block) end
# File lib/rest-client-1.6.3/lib/restclient.rb, line 87 def self.head(url, headers={}, &block) Request.execute(:method => :head, :url => url, :headers => headers, &block) end
Setup the log for RestClient calls. Value should be a logger but can can be stdout, stderr, or a filename. You can also configure logging by the environment variable RESTCLIENT_LOG.
# File lib/rest-client-1.6.3/lib/restclient.rb, line 102 def self.log= log @@log = create_log log end
# File lib/rest-client-1.6.3/lib/restclient.rb, line 91 def self.options(url, headers={}, &block) Request.execute(:method => :options, :url => url, :headers => headers, &block) end
# File lib/rest-client-1.6.3/lib/restclient.rb, line 75 def self.patch(url, payload, headers={}, &block) Request.execute(:method => :patch, :url => url, :payload => payload, :headers => headers, &block) end
# File lib/restclient_fix.rb, line 28 def self.patch(url, payload, headers={}, &block) Request.execute(:method => :patch, :url => url, :payload => payload, :headers => headers, :timeout => @timeout, &block) end
# File lib/rest-client-1.6.3/lib/restclient.rb, line 71 def self.post(url, payload, headers={}, &block) Request.execute(:method => :post, :url => url, :payload => payload, :headers => headers, &block) end
# File lib/restclient_fix.rb, line 24 def self.post(url, payload, headers={}, &block) Request.execute(:method => :post, :url => url, :payload => payload, :headers => headers, :timeout => @timeout, &block) end
# File lib/restclient_fix.rb, line 32 def self.put(url, payload, headers={}, &block) Request.execute(:method => :put, :url => url, :payload => payload, :headers => headers, :timeout => @timeout, &block) end
# File lib/rest-client-1.6.3/lib/restclient.rb, line 79 def self.put(url, payload, headers={}, &block) Request.execute(:method => :put, :url => url, :payload => payload, :headers => headers, &block) end
Reset the procs to be called before each request is executed.
# File lib/rest-client-1.6.3/lib/restclient.rb, line 166 def self.reset_before_execution_procs @@before_execution_procs = [] end
# File lib/rest-client-1.6.3/lib/restclient.rb, line 106 def self.version version_path = File.dirname(__FILE__) + "/../VERSION" return File.read(version_path).chomp if File.file?(version_path) "0.0.0" end