Class: Loopiator::Client

Inherits:
Object
  • Object
show all
Includes:
Credits, Domains, Logger
Defined in:
lib/loopiator/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Credits

#get_credits_amount, #pay_invoice_using_credits

Methods included from Domains

#domain_is_free, #get_domain, #get_domains, #order_domain, #purchase_domain

Methods included from Logger

#log

Constructor Details

#initialize(connection_options = {}) ⇒ Client

Returns a new instance of Client.



10
11
12
13
# File 'lib/loopiator/client.rb', line 10

def initialize(connection_options = {})
   connection_options.symbolize_keys!
   set_client(connection_options)
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



6
7
8
# File 'lib/loopiator/client.rb', line 6

def client
  @client
end

Instance Method Details

#call(rpc_method, *args) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/loopiator/client.rb', line 21

def call(rpc_method, *args)
  response    =   nil
  
  begin
     response  =   self.client.call(rpc_method, Loopiator.configuration.username, Loopiator.configuration.password, *args)
     
   rescue EOFError => eof_error
     raise Loopiator::ConnectionError
   end
   
   return response
end

#parse_status_response(response) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/loopiator/client.rb', line 34

def parse_status_response(response)
  response    =   response.downcase.to_sym
  
  case response
     when :ok                  then  return response
     when :domain_occupied     then  return response
     when :auth_error          then  raise Loopiator::AuthError
     when :rate_limited        then  raise Loopiator::RateLimitError
     when :insufficient_funds  then  raise Loopiator::InsufficientFundsError
     when :bad_indata          then  raise Loopiator::InvalidParameterError
     when :unknown_error       then  raise Loopiator::UnknownError
     else
       return response
   end
end

#set_client(connection_options = {}) ⇒ Object



15
16
17
18
19
# File 'lib/loopiator/client.rb', line 15

def set_client(connection_options = {})
  self.client         =   XMLRPC::Client.new_from_hash(generate_connection_options(connection_options))
   enable_debugging if Loopiator.configuration.debug
   set_client_options(connection_options)
end