Class: Loopiator::Client

Inherits:
Object
  • Object
show all
Includes:
Credits, Dns, 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 Dns

#add_zone_record, #get_zone_records, #remove_zone_record

Methods included from Domains

#domain_is_free, #get_domain, #get_domains, #order_domain, #purchase_domain, #remove_domain, #remove_subdomain, #update_nameservers

Methods included from Logger

#log

Constructor Details

#initialize(connection_options = {}) ⇒ Client

Returns a new instance of Client.



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

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

Instance Attribute Details

#clientObject

Returns the value of attribute client.



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

def client
  @client
end

Instance Method Details

#call(rpc_method, *args) ⇒ Object



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

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



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

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
     # :unknown_error will be returned when calling 'orderDomain' and the domain already exists in a customer account
     # do not raise an error until Loopia has updated their API to add an additional error code specifically targeting this phenomena
     #when :unknown_error       then  raise Loopiator::UnknownError
     else
       return response
   end
end

#set_client(connection_options = {}) ⇒ Object



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

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