rest-client 1.1.0 → 1.6.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rest-client might be problematic. Click here for more details.

@@ -0,0 +1,112 @@
1
+ # 1.6.3
2
+ - 1.6.2 was yanked
3
+
4
+ # 1.6.2
5
+
6
+ - add support for HEAD in resources (patch provided by tpresa)
7
+ - fix shell for 1.9.2
8
+ - workaround when some gem monkeypatch net/http (patch provided by Ian Warshak)
9
+ - DELETE requests should process parameters just like GET and HEAD
10
+ - adding :block_response parameter for manual processing
11
+ - limit number of redirections (patch provided by Chris Dinn)
12
+ - close and unlink the temp file created by playload (patch provided by Chris Green)
13
+ - make gemspec Rubygems 1.8 compatible (patch provided by David Backeus)
14
+ - added RestClient.reset_before_execution_procs (patch provided by Cloudify)
15
+ - added PATCH method (patch provided by Jeff Remer)
16
+ - hack for HTTP servers that use raw DEFLATE compression, see http://www.ruby-forum.com/topic/136825 (path provided by James Reeves)
17
+
18
+ # 1.6.1
19
+
20
+ - add response body in Exception#inspect
21
+ - add support for RestClient.options
22
+ - fix tests for 1.9.2 (patch provided by Niko Dittmann)
23
+ - block passing in Resource#[] (patch provided by Niko Dittmann)
24
+ - cookies set in a response should be kept in a redirect
25
+ - HEAD requests should process parameters just like GET (patch provided by Rob Eanes)
26
+ - exception message should never be nil (patch provided by Michael Klett)
27
+
28
+ # 1.6.0
29
+
30
+ - forgot to include rest-client.rb in the gem
31
+ - user, password and user-defined headers should survive a redirect
32
+ - added all missing status codes
33
+ - added parameter passing for get request using the :param key in header
34
+ - the warning about the logger when using a string was a bad idea
35
+ - multipart parameters names should not be escaped
36
+ - remove the cookie escaping introduced by migrating to CGI cookie parsing in 1.5.1
37
+ - add a streamed payload type (patch provided by Caleb Land)
38
+ - Exception#http_body works even when no response
39
+
40
+ # 1.5.1
41
+
42
+ - only converts headers keys which are Symbols
43
+ - use CGI for cookie parsing instead of custom code
44
+ - unescape user and password before using them (patch provided by Lars Gierth)
45
+ - expand ~ in ~/.restclientrc (patch provided by Mike Fletcher)
46
+ - ssl verification raise an exception when the ca certificate is incorrect (patch provided by Braintree)
47
+
48
+ # 1.5.0
49
+
50
+ - the response is now a String with the Response module a.k.a. the change in 1.4.0 was a mistake (Response.body is returning self for compatability)
51
+ - added AbstractResponse.to_i to improve semantic
52
+ - multipart Payloads ignores the name attribute if it's not set (patch provided by Tekin Suleyman)
53
+ - correctly takes into account user headers whose keys are strings (path provided by Cyril Rohr)
54
+ - use binary mode for payload temp file
55
+ - concatenate cookies with ';'
56
+ - fixed deeper parameter handling
57
+ - do not quote the boundary in the Content-Type header (patch provided by W. Andrew Loe III)
58
+
59
+ # 1.4.2
60
+
61
+ - fixed RestClient.add_before_execution_proc (patch provided by Nicholas Wieland)
62
+ - fixed error when an exception is raised without a response (patch provided by Caleb Land)
63
+
64
+ # 1.4.1
65
+
66
+ - fixed parameters managment when using hash
67
+
68
+ # 1.4.0
69
+
70
+ - Response is no more a String, and the mixin is replaced by an abstract_response, existing calls are redirected to response body with a warning.
71
+ - enable repeated parameters RestClient.post 'http://example.com/resource', :param1 => ['one', 'two', 'three'], => :param2 => 'foo' (patch provided by Rodrigo Panachi)
72
+ - fixed the redirect code concerning relative path and query string combination (patch provided by Kevin Read)
73
+ - redirection code moved to Response so redirection can be customized using the block syntax
74
+ - only get and head redirections are now followed by default, as stated in the specification
75
+ - added RestClient.add_before_execution_proc to hack the http request, like for oauth
76
+
77
+ The response change may be breaking in rare cases.
78
+
79
+ # 1.3.1
80
+
81
+ - added compatibility to enable responses in exception to act like Net::HTTPResponse
82
+
83
+ # 1.3.0
84
+
85
+ - a block can be used to process a request's result, this enable to handle custom error codes or paththrought (design by Cyril Rohr)
86
+ - cleaner log API, add a warning for some cases but should be compatible
87
+ - accept multiple "Set-Cookie" headers, see http://www.ietf.org/rfc/rfc2109.txt (patch provided by Cyril Rohr)
88
+ - remove "Content-Length" and "Content-Type" headers when following a redirection (patch provided by haarts)
89
+ - all http error codes have now a corresponding exception class and all of them contain the Reponse -> this means that the raised exception can be different
90
+ - changed "Content-Disposition: multipart/form-data" to "Content-Disposition: form-data" per RFC 2388 (patch provided by Kyle Crawford)
91
+
92
+ The only breaking change should be the exception classes, but as the new classes inherits from the existing ones, the breaking cases should be rare.
93
+
94
+ # 1.2.0
95
+
96
+ - formatting changed from tabs to spaces
97
+ - logged requests now include generated headers
98
+ - accept and content-type headers can now be specified using extentions: RestClient.post "http://example.com/resource", { 'x' => 1 }.to_json, :content_type => :json, :accept => :json
99
+ - should be 1.1.1 but renamed to 1.2.0 because 1.1.X versions has already been packaged on Debian
100
+
101
+ # 1.1.0
102
+
103
+ - new maintainer: Archiloque, the working repo is now at http://github.com/archiloque/rest-client
104
+ - a mailing list has been created at rest.client@librelist.com and an freenode irc channel #rest-client
105
+ - François Beausoleil' multipart code from http://github.com/francois/rest-client has been merged
106
+ - ability to use hash in hash as payload
107
+ - the mime-type code now rely on the mime-types gem http://mime-types.rubyforge.org/ instead of an internal partial list
108
+ - 204 response returns a Response instead of nil (patch provided by Elliott Draper)
109
+
110
+ All changes exept the last one should be fully compatible with the previous version.
111
+
112
+ NOTE: due to a dependency problem and to the last change, heroku users should update their heroku gem to >= 1.5.3 to be able to use this version.
@@ -0,0 +1,2 @@
1
+ # More logical way to require 'rest-client'
2
+ require File.dirname(__FILE__) + '/restclient'
@@ -3,18 +3,18 @@ require 'zlib'
3
3
  require 'stringio'
4
4
 
5
5
  begin
6
- require 'net/https'
6
+ require 'net/https'
7
7
  rescue LoadError => e
8
- raise e unless RUBY_PLATFORM =~ /linux/
9
- raise LoadError, "no such file to load -- net/https. Try running apt-get install libopenssl-ruby"
8
+ raise e unless RUBY_PLATFORM =~ /linux/
9
+ raise LoadError, "no such file to load -- net/https. Try running apt-get install libopenssl-ruby"
10
10
  end
11
11
 
12
+ require File.dirname(__FILE__) + '/restclient/exceptions'
12
13
  require File.dirname(__FILE__) + '/restclient/request'
13
- require File.dirname(__FILE__) + '/restclient/mixin/response'
14
+ require File.dirname(__FILE__) + '/restclient/abstract_response'
14
15
  require File.dirname(__FILE__) + '/restclient/response'
15
16
  require File.dirname(__FILE__) + '/restclient/raw_response'
16
17
  require File.dirname(__FILE__) + '/restclient/resource'
17
- require File.dirname(__FILE__) + '/restclient/exceptions'
18
18
  require File.dirname(__FILE__) + '/restclient/payload'
19
19
  require File.dirname(__FILE__) + '/restclient/net_http_ext'
20
20
 
@@ -63,45 +63,112 @@ require File.dirname(__FILE__) + '/restclient/net_http_ext'
63
63
  # => "PUT http://rest-test.heroku.com/resource with a 7 byte payload, content type application/x-www-form-urlencoded {\"foo\"=>\"baz\"}"
64
64
  #
65
65
  module RestClient
66
- def self.get(url, headers={})
67
- Request.execute(:method => :get, :url => url, :headers => headers)
68
- end
69
-
70
- def self.post(url, payload, headers={})
71
- Request.execute(:method => :post, :url => url, :payload => payload, :headers => headers)
72
- end
73
-
74
- def self.put(url, payload, headers={})
75
- Request.execute(:method => :put, :url => url, :payload => payload, :headers => headers)
76
- end
77
-
78
- def self.delete(url, headers={})
79
- Request.execute(:method => :delete, :url => url, :headers => headers)
80
- end
81
-
82
- def self.head(url, headers={})
83
- Request.execute(:method => :head, :url => url, :headers => headers)
84
- end
85
-
86
- class << self
87
- attr_accessor :proxy
88
- end
89
-
90
- # Print log of RestClient calls. Value can be stdout, stderr, or a filename.
91
- # You can also configure logging by the environment variable RESTCLIENT_LOG.
92
- def self.log=(log)
93
- @@log = log
94
- end
95
-
96
- def self.log # :nodoc:
97
- return ENV['RESTCLIENT_LOG'] if ENV['RESTCLIENT_LOG']
98
- return @@log if defined? @@log
99
- nil
100
- end
66
+
67
+ def self.get(url, headers={}, &block)
68
+ Request.execute(:method => :get, :url => url, :headers => headers, &block)
69
+ end
70
+
71
+ def self.post(url, payload, headers={}, &block)
72
+ Request.execute(:method => :post, :url => url, :payload => payload, :headers => headers, &block)
73
+ end
74
+
75
+ def self.patch(url, payload, headers={}, &block)
76
+ Request.execute(:method => :patch, :url => url, :payload => payload, :headers => headers, &block)
77
+ end
78
+
79
+ def self.put(url, payload, headers={}, &block)
80
+ Request.execute(:method => :put, :url => url, :payload => payload, :headers => headers, &block)
81
+ end
82
+
83
+ def self.delete(url, headers={}, &block)
84
+ Request.execute(:method => :delete, :url => url, :headers => headers, &block)
85
+ end
86
+
87
+ def self.head(url, headers={}, &block)
88
+ Request.execute(:method => :head, :url => url, :headers => headers, &block)
89
+ end
90
+
91
+ def self.options(url, headers={}, &block)
92
+ Request.execute(:method => :options, :url => url, :headers => headers, &block)
93
+ end
94
+
95
+ class << self
96
+ attr_accessor :proxy
97
+ end
98
+
99
+ # Setup the log for RestClient calls.
100
+ # Value should be a logger but can can be stdout, stderr, or a filename.
101
+ # You can also configure logging by the environment variable RESTCLIENT_LOG.
102
+ def self.log= log
103
+ @@log = create_log log
104
+ end
101
105
 
102
106
  def self.version
103
107
  version_path = File.dirname(__FILE__) + "/../VERSION"
104
108
  return File.read(version_path).chomp if File.file?(version_path)
105
109
  "0.0.0"
106
110
  end
111
+
112
+ # Create a log that respond to << like a logger
113
+ # param can be 'stdout', 'stderr', a string (then we will log to that file) or a logger (then we return it)
114
+ def self.create_log param
115
+ if param
116
+ if param.is_a? String
117
+ if param == 'stdout'
118
+ stdout_logger = Class.new do
119
+ def << obj
120
+ STDOUT.puts obj
121
+ end
122
+ end
123
+ stdout_logger.new
124
+ elsif param == 'stderr'
125
+ stderr_logger = Class.new do
126
+ def << obj
127
+ STDERR.puts obj
128
+ end
129
+ end
130
+ stderr_logger.new
131
+ else
132
+ file_logger = Class.new do
133
+ attr_writer :target_file
134
+
135
+ def << obj
136
+ File.open(@target_file, 'a') { |f| f.puts obj }
137
+ end
138
+ end
139
+ logger = file_logger.new
140
+ logger.target_file = param
141
+ logger
142
+ end
143
+ else
144
+ param
145
+ end
146
+ end
147
+ end
148
+
149
+ @@env_log = create_log ENV['RESTCLIENT_LOG']
150
+
151
+ @@log = nil
152
+
153
+ def self.log # :nodoc:
154
+ @@env_log || @@log
155
+ end
156
+
157
+ @@before_execution_procs = []
158
+
159
+ # Add a Proc to be called before each request in executed.
160
+ # The proc parameters will be the http request and the request params.
161
+ def self.add_before_execution_proc &proc
162
+ @@before_execution_procs << proc
163
+ end
164
+
165
+ # Reset the procs to be called before each request is executed.
166
+ def self.reset_before_execution_procs
167
+ @@before_execution_procs = []
168
+ end
169
+
170
+ def self.before_execution_procs # :nodoc:
171
+ @@before_execution_procs
172
+ end
173
+
107
174
  end
@@ -0,0 +1,106 @@
1
+ require 'cgi'
2
+
3
+ module RestClient
4
+
5
+ module AbstractResponse
6
+
7
+ attr_reader :net_http_res, :args
8
+
9
+ # HTTP status code
10
+ def code
11
+ @code ||= @net_http_res.code.to_i
12
+ end
13
+
14
+ # A hash of the headers, beautified with symbols and underscores.
15
+ # e.g. "Content-type" will become :content_type.
16
+ def headers
17
+ @headers ||= AbstractResponse.beautify_headers(@net_http_res.to_hash)
18
+ end
19
+
20
+ # The raw headers.
21
+ def raw_headers
22
+ @raw_headers ||= @net_http_res.to_hash
23
+ end
24
+
25
+ # Hash of cookies extracted from response headers
26
+ def cookies
27
+ @cookies ||= (self.headers[:set_cookie] || {}).inject({}) do |out, cookie_content|
28
+ out.merge parse_cookie(cookie_content)
29
+ end
30
+ end
31
+
32
+ # Return the default behavior corresponding to the response code:
33
+ # the response itself for code in 200..206, redirection for 301, 302 and 307 in get and head cases, redirection for 303 and an exception in other cases
34
+ def return! request = nil, result = nil, & block
35
+ if (200..207).include? code
36
+ self
37
+ elsif [301, 302, 307].include? code
38
+ unless [:get, :head].include? args[:method]
39
+ raise Exceptions::EXCEPTIONS_MAP[code].new(self, code)
40
+ else
41
+ follow_redirection(request, result, & block)
42
+ end
43
+ elsif code == 303
44
+ args[:method] = :get
45
+ args.delete :payload
46
+ follow_redirection(request, result, & block)
47
+ elsif Exceptions::EXCEPTIONS_MAP[code]
48
+ raise Exceptions::EXCEPTIONS_MAP[code].new(self, code)
49
+ else
50
+ raise RequestFailed.new(self, code)
51
+ end
52
+ end
53
+
54
+ def to_i
55
+ code
56
+ end
57
+
58
+ def description
59
+ "#{code} #{STATUSES[code]} | #{(headers[:content_type] || '').gsub(/;.*$/, '')} #{size} bytes\n"
60
+ end
61
+
62
+ # Follow a redirection
63
+ def follow_redirection request = nil, result = nil, & block
64
+ url = headers[:location]
65
+ if url !~ /^http/
66
+ url = URI.parse(args[:url]).merge(url).to_s
67
+ end
68
+ args[:url] = url
69
+ if request
70
+ if request.max_redirects == 0
71
+ raise MaxRedirectsReached
72
+ end
73
+ args[:password] = request.password
74
+ args[:user] = request.user
75
+ args[:headers] = request.headers
76
+ args[:max_redirects] = request.max_redirects - 1
77
+ # pass any cookie set in the result
78
+ if result && result['set-cookie']
79
+ args[:headers][:cookies] = (args[:headers][:cookies] || {}).merge(parse_cookie(result['set-cookie']))
80
+ end
81
+ end
82
+ Request.execute args, &block
83
+ end
84
+
85
+ def AbstractResponse.beautify_headers(headers)
86
+ headers.inject({}) do |out, (key, value)|
87
+ out[key.gsub(/-/, '_').downcase.to_sym] = %w{ set-cookie }.include?(key.downcase) ? value : value.first
88
+ out
89
+ end
90
+ end
91
+
92
+ private
93
+
94
+ # Parse a cookie value and return its content in an Hash
95
+ def parse_cookie cookie_content
96
+ out = {}
97
+ CGI::Cookie::parse(cookie_content).each do |key, cookie|
98
+ unless ['expires', 'path'].include? key
99
+ out[CGI::escape(key)] = cookie.value[0] ? (CGI::escape(cookie.value[0]) || '') : ''
100
+ end
101
+ end
102
+ out
103
+ end
104
+ end
105
+
106
+ end
@@ -1,88 +1,193 @@
1
1
  module RestClient
2
- # This is the base RestClient exception class. Rescue it if you want to
3
- # catch any exception that your request might raise
4
- class Exception < RuntimeError
5
- def message(default=nil)
6
- self.class::ErrorMessage
7
- end
8
- end
9
-
10
- # Base RestClient exception when there's a response available
11
- class ExceptionWithResponse < Exception
12
- attr_accessor :response
13
-
14
- def initialize(response=nil)
15
- @response = response
16
- end
17
-
18
- def http_code
19
- @response.code.to_i if @response
20
- end
21
-
22
- def http_body
23
- RestClient::Request.decode(@response['content-encoding'], @response.body) if @response
24
- end
25
- end
26
-
27
- # A redirect was encountered; caught by execute to retry with the new url.
28
- class Redirect < Exception
29
- ErrorMessage = "Redirect"
30
-
31
- attr_accessor :url
32
- def initialize(url)
33
- @url = url
34
- end
35
- end
36
-
37
- class NotModified < ExceptionWithResponse
38
- ErrorMessage = 'NotModified'
39
- end
40
-
41
- # Authorization is required to access the resource specified.
42
- class Unauthorized < ExceptionWithResponse
43
- ErrorMessage = 'Unauthorized'
44
- end
45
-
46
- # No resource was found at the given URL.
47
- class ResourceNotFound < ExceptionWithResponse
48
- ErrorMessage = 'Resource not found'
49
- end
50
-
51
- # The server broke the connection prior to the request completing. Usually
52
- # this means it crashed, or sometimes that your network connection was
53
- # severed before it could complete.
54
- class ServerBrokeConnection < Exception
55
- ErrorMessage = 'Server broke connection'
56
- end
57
-
58
- # The server took too long to respond.
59
- class RequestTimeout < Exception
60
- ErrorMessage = 'Request timed out'
61
- end
62
-
63
- # The request failed, meaning the remote HTTP server returned a code other
64
- # than success, unauthorized, or redirect.
65
- #
66
- # The exception message attempts to extract the error from the XML, using
67
- # format returned by Rails: <errors><error>some message</error></errors>
68
- #
69
- # You can get the status code by e.http_code, or see anything about the
70
- # response via e.response. For example, the entire result body (which is
71
- # probably an HTML error page) is e.response.body.
72
- class RequestFailed < ExceptionWithResponse
73
- def message
74
- "HTTP status code #{http_code}"
75
- end
76
-
77
- def to_s
78
- message
79
- end
80
- end
2
+
3
+ STATUSES = {100 => 'Continue',
4
+ 101 => 'Switching Protocols',
5
+ 102 => 'Processing', #WebDAV
6
+
7
+ 200 => 'OK',
8
+ 201 => 'Created',
9
+ 202 => 'Accepted',
10
+ 203 => 'Non-Authoritative Information', # http/1.1
11
+ 204 => 'No Content',
12
+ 205 => 'Reset Content',
13
+ 206 => 'Partial Content',
14
+ 207 => 'Multi-Status', #WebDAV
15
+
16
+ 300 => 'Multiple Choices',
17
+ 301 => 'Moved Permanently',
18
+ 302 => 'Found',
19
+ 303 => 'See Other', # http/1.1
20
+ 304 => 'Not Modified',
21
+ 305 => 'Use Proxy', # http/1.1
22
+ 306 => 'Switch Proxy', # no longer used
23
+ 307 => 'Temporary Redirect', # http/1.1
24
+
25
+ 400 => 'Bad Request',
26
+ 401 => 'Unauthorized',
27
+ 402 => 'Payment Required',
28
+ 403 => 'Forbidden',
29
+ 404 => 'Resource Not Found',
30
+ 405 => 'Method Not Allowed',
31
+ 406 => 'Not Acceptable',
32
+ 407 => 'Proxy Authentication Required',
33
+ 408 => 'Request Timeout',
34
+ 409 => 'Conflict',
35
+ 410 => 'Gone',
36
+ 411 => 'Length Required',
37
+ 412 => 'Precondition Failed',
38
+ 413 => 'Request Entity Too Large',
39
+ 414 => 'Request-URI Too Long',
40
+ 415 => 'Unsupported Media Type',
41
+ 416 => 'Requested Range Not Satisfiable',
42
+ 417 => 'Expectation Failed',
43
+ 418 => 'I\'m A Teapot',
44
+ 421 => 'Too Many Connections From This IP',
45
+ 422 => 'Unprocessable Entity', #WebDAV
46
+ 423 => 'Locked', #WebDAV
47
+ 424 => 'Failed Dependency', #WebDAV
48
+ 425 => 'Unordered Collection', #WebDAV
49
+ 426 => 'Upgrade Required',
50
+ 449 => 'Retry With', #Microsoft
51
+ 450 => 'Blocked By Windows Parental Controls', #Microsoft
52
+
53
+ 500 => 'Internal Server Error',
54
+ 501 => 'Not Implemented',
55
+ 502 => 'Bad Gateway',
56
+ 503 => 'Service Unavailable',
57
+ 504 => 'Gateway Timeout',
58
+ 505 => 'HTTP Version Not Supported',
59
+ 506 => 'Variant Also Negotiates',
60
+ 507 => 'Insufficient Storage', #WebDAV
61
+ 509 => 'Bandwidth Limit Exceeded', #Apache
62
+ 510 => 'Not Extended'}
63
+
64
+ # Compatibility : make the Response act like a Net::HTTPResponse when needed
65
+ module ResponseForException
66
+ def method_missing symbol, *args
67
+ if net_http_res.respond_to? symbol
68
+ warn "[warning] The response contained in an RestClient::Exception is now a RestClient::Response instead of a Net::HTTPResponse, please update your code"
69
+ net_http_res.send symbol, *args
70
+ else
71
+ super
72
+ end
73
+ end
74
+ end
75
+
76
+ # This is the base RestClient exception class. Rescue it if you want to
77
+ # catch any exception that your request might raise
78
+ # You can get the status code by e.http_code, or see anything about the
79
+ # response via e.response.
80
+ # For example, the entire result body (which is
81
+ # probably an HTML error page) is e.response.
82
+ class Exception < RuntimeError
83
+ attr_accessor :response
84
+ attr_writer :message
85
+
86
+ def initialize response = nil, initial_response_code = nil
87
+ @response = response
88
+ @initial_response_code = initial_response_code
89
+
90
+ # compatibility: this make the exception behave like a Net::HTTPResponse
91
+ response.extend ResponseForException if response
92
+ end
93
+
94
+ def http_code
95
+ # return integer for compatibility
96
+ if @response
97
+ @response.code.to_i
98
+ else
99
+ @initial_response_code
100
+ end
101
+ end
102
+
103
+ def http_body
104
+ @response.body if @response
105
+ end
106
+
107
+ def inspect
108
+ "#{message}: #{http_body}"
109
+ end
110
+
111
+ def to_s
112
+ inspect
113
+ end
114
+
115
+ def message
116
+ @message || self.class.name
117
+ end
118
+
119
+ end
120
+
121
+ # Compatibility
122
+ class ExceptionWithResponse < Exception
123
+ end
124
+
125
+ # The request failed with an error code not managed by the code
126
+ class RequestFailed < ExceptionWithResponse
127
+
128
+ def message
129
+ "HTTP status code #{http_code}"
130
+ end
131
+
132
+ def to_s
133
+ message
134
+ end
135
+ end
136
+
137
+ # We will a create an exception for each status code, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
138
+ module Exceptions
139
+ # Map http status codes to the corresponding exception class
140
+ EXCEPTIONS_MAP = {}
141
+ end
142
+
143
+ STATUSES.each_pair do |code, message|
144
+
145
+ # Compatibility
146
+ superclass = ([304, 401, 404].include? code) ? ExceptionWithResponse : RequestFailed
147
+ klass = Class.new(superclass) do
148
+ send(:define_method, :message) {"#{http_code ? "#{http_code} " : ''}#{message}"}
149
+ end
150
+ klass_constant = const_set message.delete(' \-\''), klass
151
+ Exceptions::EXCEPTIONS_MAP[code] = klass_constant
152
+ end
153
+
154
+ # A redirect was encountered; caught by execute to retry with the new url.
155
+ class Redirect < Exception
156
+
157
+ message = 'Redirect'
158
+
159
+ attr_accessor :url
160
+
161
+ def initialize(url)
162
+ @url = url
163
+ end
164
+ end
165
+
166
+ class MaxRedirectsReached < Exception
167
+ message = 'Maximum number of redirect reached'
168
+ end
169
+
170
+ # The server broke the connection prior to the request completing. Usually
171
+ # this means it crashed, or sometimes that your network connection was
172
+ # severed before it could complete.
173
+ class ServerBrokeConnection < Exception
174
+ def initialize(message = 'Server broke connection')
175
+ super nil, nil
176
+ self.message = message
177
+ end
178
+ end
179
+
180
+ class SSLCertificateNotVerified < Exception
181
+ def initialize(message)
182
+ super nil, nil
183
+ self.message = message
184
+ end
185
+ end
81
186
  end
82
187
 
83
188
  # backwards compatibility
84
189
  class RestClient::Request
85
- Redirect = RestClient::Redirect
86
- Unauthorized = RestClient::Unauthorized
87
- RequestFailed = RestClient::RequestFailed
190
+ Redirect = RestClient::Redirect
191
+ Unauthorized = RestClient::Unauthorized
192
+ RequestFailed = RestClient::RequestFailed
88
193
  end