Class: INWX::Domrobot

Inherits:
Object
  • Object
show all
Defined in:
lib/inwx/domrobot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address) ⇒ Domrobot

Returns a new instance of Domrobot.



7
8
9
10
11
# File 'lib/inwx/domrobot.rb', line 7

def initialize(address)
  @cookie = ""
  # Create a new client instance
  @client = XMLRPC::Client.new(address,"/xmlrpc/","443", nil, nil, nil, nil, true, 100)
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



5
6
7
# File 'lib/inwx/domrobot.rb', line 5

def client
  @client
end

Returns the value of attribute cookie.



5
6
7
# File 'lib/inwx/domrobot.rb', line 5

def cookie
  @cookie
end

Instance Method Details

#call(object, method, params = {}) ⇒ Object



46
47
48
49
50
# File 'lib/inwx/domrobot.rb', line 46

def call(object, method, params = {})
  client.cookie = getCookie()
  # Call the remote method
  client.call(object+"."+method, params)
end

#getCookieObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/inwx/domrobot.rb', line 34

def getCookie()
  if self.cookie.length > 2
    return self.cookie
  end
  if File.exist?("domrobot.tmp")
    fp = File.new("domrobot.tmp", "r")
    cookie = fp.read()
    fp.close
    return cookie
  end
end

#login(username = false, password = false, language = 'en') ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/inwx/domrobot.rb', line 13

def (username = false, password = false, language = 'en')
  params = { :user => username, :pass => password, 'lang' => language }
  ret = call("account","login",params)
  cookie = client.cookie
  unless cookie.nil? || cookie.length <= 2
    setCookie(cookie)
  end
  return ret
end

#logoutObject



23
24
25
# File 'lib/inwx/domrobot.rb', line 23

def logout()
  call("account","logout")
end

#setCookie(cookie) ⇒ Object



27
28
29
30
31
32
# File 'lib/inwx/domrobot.rb', line 27

def setCookie(cookie)
  self.cookie = cookie
  fp = File.new("domrobot.tmp", "w")
  fp.write(cookie)
  fp.close
end