Class: Esgob::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/esgob/client.rb

Constant Summary collapse

DEFAULT_API_ENDPOINT =
"https://api.esgob.com/1.0/".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Client


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/esgob/client.rb', line 12

def initialize(*args)
  if args.first.kind_of?(Hash)
    args.first.each_pair { |k,v| send("#{k}=", v) }
  else
    self. = args[0]
    self.api_key = args[1]
  end

  self.endpoint ||= DEFAULT_API_ENDPOINT
  self.  ||= ENV['ESGOB_ACCOUNT']
  self.api_key  ||= ENV['ESGOB_API_KEY']
end

Instance Attribute Details

#accountObject

Returns the value of attribute account


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

def 
  @account
end

#api_keyObject

Returns the value of attribute api_key


8
9
10
# File 'lib/esgob/client.rb', line 8

def api_key
  @api_key
end

#endpointObject

Returns the value of attribute endpoint


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

def endpoint
  @endpoint
end

Instance Method Details

#accounts_getObject

Return account status; credit balance, etc


49
50
51
# File 'lib/esgob/client.rb', line 49

def accounts_get
  call('accounts.get')
end

#call(function_name, arguments = {}) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/esgob/client.rb', line 25

def call(function_name, arguments={})
  uri = URI(endpoint + function_name)
  uri.query = build_query(default_arguments.merge(arguments))

  res = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
    req = Net::HTTP::Get.new(uri.request_uri)
    req['Accept'] = 'application/json'
    http.request(req)
  end

  if res.code =~ /^2/
    if res.content_type == 'application/json'
      symbolize_keys! JSON.parse(res.body)
    else
     raise "HTTP response from ESGOB is not of type JSON"
    end
  else
    # The badly named method throws an Net::HTTP exception
    res.value
  end

end

#domains_listObject

Returns all hosted domains


54
55
56
# File 'lib/esgob/client.rb', line 54

def domains_list
  call('domains.list')[:domains]
end

#domains_slaves_add(domain, masterip) ⇒ Object

Adds a new slave domain


69
70
71
# File 'lib/esgob/client.rb', line 69

def domains_slaves_add(domain, masterip)
  call('domains.slaves.add', :domain => domain, :masterip => masterip)
end

#domains_slaves_axfrout_add(domain, axfrip) ⇒ Object

Add a host allowed to AXFR out


89
90
91
# File 'lib/esgob/client.rb', line 89

def domains_slaves_axfrout_add(domain, axfrip)
  call('domains.slaves.axfrout.add', :domain => domain, :axfrip => axfrip)
end

#domains_slaves_axfrout_delete(domain, axfrip) ⇒ Object

Account Delete a host allowed to AXFR out


94
95
96
# File 'lib/esgob/client.rb', line 94

def domains_slaves_axfrout_delete(domain, axfrip)
  call('domains.slaves.axfrout.delete', :domain => domain, :axfrip => axfrip)
end

#domains_slaves_delete(domain) ⇒ Object

Deletes a slave domain


74
75
76
# File 'lib/esgob/client.rb', line 74

def domains_slaves_delete(domain)
  call('domains.slaves.delete', :domain => domain)
end

#domains_slaves_forcetransfer(domain) ⇒ Object

Force AXFR / transfer from master of a slave domain


79
80
81
# File 'lib/esgob/client.rb', line 79

def domains_slaves_forcetransfer(domain)
  call('domains.slaves.forcetransfer', :domain => domain)
end

#domains_slaves_listObject

Returns all hosted slave domains as a hash


60
61
62
63
64
65
66
# File 'lib/esgob/client.rb', line 60

def domains_slaves_list
  Hash[
    call('domains.slaves.list')[:domains].map do |item|
      [item[:domain], item[:masterip]]
    end
  ]
end

#domains_slaves_updatemasterip(domain, masterip) ⇒ Object

Updates the master IP of a slave domain


84
85
86
# File 'lib/esgob/client.rb', line 84

def domains_slaves_updatemasterip(domain, masterip)
  call('domains.slaves.updatemasterip', :domain => domain, :masterip => masterip)
end

#domains_tools_soacheck(domain) ⇒ Object

Retrieve the domain SOA serial number from the master and each anycast node


99
100
101
# File 'lib/esgob/client.rb', line 99

def domains_tools_soacheck(domain)
  call('domains.tools.soacheck', :domain => domain)
end