Class: Namecheap::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/namecheap/api.rb

Direct Known Subclasses

Dns, Domains, Ns, Ssl, Transfers, Users, Whois_Guard

Constant Summary collapse

SANDBOX =
'https://api.sandbox.namecheap.com/xml.response'
PRODUCTION =
'https://api.namecheap.com/xml.response'
ENVIRONMENT =
defined?(Rails) && Rails.respond_to?(:env) ? Rails.env : (ENV["RACK_ENV"] || 'development')
ENDPOINT =
(ENVIRONMENT == 'production' ? PRODUCTION : SANDBOX)

Instance Method Summary collapse

Instance Method Details

#api_call(command, command_args) ⇒ Object



8
9
10
11
12
# File 'lib/namecheap/api.rb', line 8

def api_call(command, command_args)
  args = init_args(command_args.merge :command => command)
  query = ENDPOINT + '?' + args.to_param
  HTTParty.get(query)
end

#init_args(options = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/namecheap/api.rb', line 14

def init_args(options = {})
  args = {}
  args['ApiUser'] = args['UserName'] = Namecheap.username
  args['ApiKey'] = Namecheap.key
  args['ClientIp'] = Namecheap.client_ip
  args.merge options.camelize_keys!
end