Module: DataMapper::DhApi::Adapter

Includes:
HTTParty
Defined in:
lib/dm-dh_api-adapter.rb

Defined Under Namespace

Classes: APIRequestError

Class Method Summary collapse

Class Method Details

.api_key(api_key) ⇒ Object



11
12
13
# File 'lib/dm-dh_api-adapter.rb', line 11

def self.api_key(api_key)
  @@api_key = api_key
end

.dnsesObject



18
19
20
21
# File 'lib/dm-dh_api-adapter.rb', line 18

def self.dnses
  options = {:query => {:key => @@api_key, :format => 'json', :cmd => 'dns-list_records'}}
  request_api(options)
end

.domainsObject



14
15
16
17
# File 'lib/dm-dh_api-adapter.rb', line 14

def self.domains
  options = {:query => {:key => @@api_key, :format => 'json', :cmd => 'domain-list_domains'}}
  request_api(options)
end

.request_api(options) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dm-dh_api-adapter.rb', line 31

def self.request_api(options)
  response = get('/', options)
  case response['result']
    when 'success'
      response['data']
    when 'error'
      raise APIRequestError, "Error: #{response['data']}" + (response['reason'].blank? ? " " : " - Reason: #{response['reason']}")
    else
      raise APIRequestError, "Unknown exception"
  end
end

.usersObject



22
23
24
25
# File 'lib/dm-dh_api-adapter.rb', line 22

def self.users
  options = {:query => {:key => @@api_key, :format => 'json', :cmd => 'user-list_users_no_pw'}}
  request_api(options)
end

.users_pwObject



26
27
28
29
# File 'lib/dm-dh_api-adapter.rb', line 26

def self.users_pw
  options = {:query => {:key => @@api_key, :format => 'json', :cmd => 'user-list_users'}}
  request_api(options)
end