Class: Aliyun::ESS::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/aliyun/ess/base.rb,
lib/aliyun/ess/response.rb

Direct Known Subclasses

ScalingGroup, ScalingInstance, ScalingRule, Service

Defined Under Namespace

Classes: RequestParams, Response

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Base

:nodoc:



95
96
97
# File 'lib/aliyun/ess/base.rb', line 95

def initialize(attributes = {}) #:nodoc:
  @attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



115
116
117
118
119
120
121
122
123
124
# File 'lib/aliyun/ess/base.rb', line 115

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

Class Method Details

.request(verb, path, params = {}, options = {}, body = nil, attempts = 0, &block) ⇒ Object

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.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/aliyun/ess/base.rb', line 13

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