Class: Gandi::Base

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

Direct Known Subclasses

Domain

Constant Summary collapse

TIMEOUT_EXCEPTIONS =
[EOFError, Errno::EPIPE, OpenSSL::SSL::SSLError]
URL =
"https://api.gandi.net/xmlrpc/"
TEST_URL =
"https://api.ote.gandi.net/xmlrpc/"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(login, password, uri = nil) ⇒ Base

Returns a new instance of Base.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gandi/base.rb', line 17

def initialize(, password, uri = nil)
  @login = 
  @password = password
  @uri = uri
  if @uri.nil?
    begin
      self.class.const_get(:URL)
    rescue NameError
      raise ArgumentError.new "You must provide an URL when using Gandi::Base directly"
    end
  end
end

Instance Attribute Details

#handlerObject (readonly)

Returns the value of attribute handler.



13
14
15
# File 'lib/gandi/base.rb', line 13

def handler
  @handler
end

#session_idObject (readonly)

Returns the value of attribute session_id.



13
14
15
# File 'lib/gandi/base.rb', line 13

def session_id
  @session_id
end

Class Method Details

.login(login, password, uri = nil) ⇒ Object



69
70
71
72
73
# File 'lib/gandi/base.rb', line 69

def self.(, password, uri = nil)
  client = self.new(, password, uri)
  client.
  return client
end

Instance Method Details

#account_balanceObject

Current prepaid account balance



60
61
62
# File 'lib/gandi/base.rb', line 60

def 
  call('account_balance')
end

#account_currencyObject

Currency name used with the prepaid account



65
66
67
# File 'lib/gandi/base.rb', line 65

def 
  call('account_currency')
end

#call(method, *arguments) ⇒ Object

Calls a RPC method, transparently providing the session id



31
32
33
34
# File 'lib/gandi/base.rb', line 31

def call(method, *arguments)
  raise "You have to log in before using methods requiring a session id" unless logged_in?
  raw_call(method.to_s, @session_id, *arguments)
end

#loginObject

Instanciates a rpc handler and log in to the interface to retrieve a session id



37
38
39
40
41
42
43
44
45
46
# File 'lib/gandi/base.rb', line 37

def 
  @handler = XMLRPC::Client.new_from_uri(@uri)
  #Get rid of SSL warnings "peer certificate won't be verified in this SSL session"
  #See http://developer.amazonwebservices.com/connect/thread.jspa?threadID=37139
  #and http://blog.chmouel.com/2008/03/21/ruby-xmlrpc-over-a-self-certified-ssl-with-a-warning/
  if @handler.instance_variable_get('@http').use_ssl?
    @handler.instance_variable_get('@http').instance_variable_get("@ssl_context").verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
  @session_id = raw_call("login", @login, @password, false)
end

#password(password) ⇒ Object

Changes password



54
55
56
57
# File 'lib/gandi/base.rb', line 54

def password(password)
  @password = password
  call("password", password)
end

#su(handle) ⇒ Object

Gets a new session id by switching to another handle



49
50
51
# File 'lib/gandi/base.rb', line 49

def su(handle)
  @session_id = call("su", handle)
end