Class: Namecheap::Api
- Inherits:
-
Object
show all
- Defined in:
- lib/namecheap/api.rb
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
#delete(command, options = {}) ⇒ Object
22
23
24
|
# File 'lib/namecheap/api.rb', line 22
def delete(command, options = {})
request 'post', command, options
end
|
#get(command, options = {}) ⇒ Object
10
11
12
|
# File 'lib/namecheap/api.rb', line 10
def get(command, options = {})
request 'get', command, options
end
|
#post(command, options = {}) ⇒ Object
14
15
16
|
# File 'lib/namecheap/api.rb', line 14
def post(command, options = {})
request 'post', command, options
end
|
#put(command, options = {}) ⇒ Object
18
19
20
|
# File 'lib/namecheap/api.rb', line 18
def put(command, options = {})
request 'post', command, options
end
|
#request(method, command, options = {}) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/namecheap/api.rb', line 26
def request(method, command, options = {})
command = 'namecheap.' + command
options = init_args.merge(options).merge({:command => command})
options.keys.each do |key|
options[key.to_s.camelize] = options.delete(key)
end
case method
when 'get'
HTTParty.get(ENDPOINT, { :query => options})
when 'post'
HTTParty.post(ENDPOINT, { :query => options})
when 'put'
HTTParty.put(ENDPOINT, { :query => options})
when 'delete'
HTTParty.delete(ENDPOINT, { :query => options})
end
end
|