Class: Gandi::ProxyCall

Inherits:
Object
  • Object
show all
Defined in:
lib/gandi/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, api_key) ⇒ ProxyCall

Returns a new instance of ProxyCall.



171
172
173
174
175
176
# File 'lib/gandi/session.rb', line 171

def initialize(server, api_key)
  self.server = server
  self.api_key = api_key
  self.chained = []
  self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/gandi/session.rb', line 180

def method_missing(method, *args)
  self.chained << method
  method_name = chained.join(".")
  if Gandi::VALID_METHODS.include?(method_name)
    begin
      res = self.server.call(method_name, api_key, *args)
    rescue XMLRPC::FaultException => e
      raise Gandi::FaultCode.parse(e.faultCode, e.faultString).exception
    end

    if res.is_a?(Array)
      res.collect! { |x| x.is_a?(Hash) ? Hashie::Mash.new(x) : x }
    elsif res.is_a?(Hash)
      Hashie::Mash.new(res)
    else
      res
    end
  else
    self
  end
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



169
170
171
# File 'lib/gandi/session.rb', line 169

def api_key
  @api_key
end

#chainedObject

Returns the value of attribute chained.



169
170
171
# File 'lib/gandi/session.rb', line 169

def chained
  @chained
end

#serverObject

Returns the value of attribute server.



169
170
171
# File 'lib/gandi/session.rb', line 169

def server
  @server
end