class Aliyun::ESS::Base
Attributes
attributes[R]
Public Class Methods
request(verb, path, params = {}, options = {}, body = nil, attempts = 0, &block)
click to toggle source
Wraps the current connection’s request method and picks the appropriate response class to wrap the response in. If the response is an error, it will raise that error as an exception. All such exceptions can be caught by rescuing their superclass, the ResponseError
exception class.
It is unlikely that you would call this method directly. Subclasses of Base have convenience methods for each http request verb that wrap calls to request.
# File lib/aliyun/ess/base.rb, line 12 def request(verb, path, params = {}, options = {}, body = nil, attempts = 0, &block) Service.response = nil process_params!(params, verb) response = response_class.new(connection.request(verb, path, params, options, body, attempts, &block)) Service.response = response Error::Response.new(response.response).error.raise if response.error? response # Once in a while, a request to OSS returns an internal error. A glitch in the matrix I presume. Since these # errors are few and far between the request method will rescue InternalErrors the first three times they encouter them # and will retry the request again. Most of the time the second attempt will work. rescue InternalError, RequestTimeout if attempts == 3 raise else attempts += 1 retry end end
Private Class Methods
process_params!(params, verb)
click to toggle source
# File lib/aliyun/ess/base.rb, line 46 def process_params!(params, verb) params.replace(RequestParams.process(params, verb)) end
respond_with(klass) { || ... }
click to toggle source
Using the conventions layed out in the response_class
works for more than 80% of the time. There are a few edge cases though where we want a given class to wrap its responses in different response classes depending on which method is being called.
# File lib/aliyun/ess/base.rb, line 53 def respond_with(klass) eval(<<-EVAL, binding, __FILE__, __LINE__) def new_response_class #{klass} end class << self alias_method :old_response_class, :response_class alias_method :response_class, :new_response_class end EVAL yield ensure # Restore the original version eval(<<-EVAL, binding, __FILE__, __LINE__) class << self alias_method :response_class, :old_response_class end EVAL end
response_class()
click to toggle source
# File lib/aliyun/ess/base.rb, line 42 def response_class FindResponseClass.for(self) end
Private Instance Methods
connection()
click to toggle source
# File lib/aliyun/ess/base.rb, line 102 def connection self.class.connection end
http()
click to toggle source
# File lib/aliyun/ess/base.rb, line 106 def http connection.http end
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/aliyun/ess/base.rb, line 114 def method_missing(method, *args, &block) case when attributes.has_key?(method.to_s) attributes[method.to_s] when attributes.has_key?(method) attributes[method] else super end end
request(*args, &block)
click to toggle source
# File lib/aliyun/ess/base.rb, line 110 def request(*args, &block) self.class.request(*args, &block) end