Class: Esgob::Client
- Inherits:
-
Object
- Object
- Esgob::Client
- Defined in:
- lib/esgob/client.rb
Instance Attribute Summary collapse
-
#config ⇒ Esgob::Config
readonly
Esgob configuration, used to store account name and key.
Instance Method Summary collapse
-
#accounts_get ⇒ Hash
Return account status; credit balance, etc.
-
#call(function_name, args = {}) ⇒ Hash
Call a named Esgob API function.
-
#domains_list ⇒ Array<Hash>
Returns all hosted domains.
-
#domains_slaves_add(domain, masterip) ⇒ Hash
Adds a new slave domain.
-
#domains_slaves_axfrout_add(domain, axfrip) ⇒ Hash
Add a host allowed to AXFR out.
-
#domains_slaves_axfrout_delete(domain, axfrip) ⇒ Hash
Account Delete a host allowed to AXFR out.
-
#domains_slaves_delete(domain) ⇒ Hash
Deletes a slave domain.
-
#domains_slaves_forcetransfer(domain) ⇒ Hash
Force AXFR / transfer from master of a slave domain.
-
#domains_slaves_list ⇒ Hash
Returns all hosted slave domains as a hash.
-
#domains_slaves_sync(domains, masterip) ⇒ Array<Hash>
Given a list of domains and a master IP, add and delete domains so that the Esgob account matches the local list.
-
#domains_slaves_updatemasterip(domain, masterip) ⇒ Hash
Updates the master IP of a slave domain.
-
#domains_tools_soacheck(domain) ⇒ Hash
Retrieve the domain SOA serial number from the master and each anycast node.
-
#initialize(*args) ⇒ Esgob::Client
constructor
Create a new Esgob Client instance.
- #inspect ⇒ String
Constructor Details
#initialize ⇒ Esgob::Client #initialize(account, key) ⇒ Esgob::Client #initialize(args) ⇒ Esgob::Client #initialize(config) ⇒ Esgob::Client
Create a new Esgob Client instance.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/esgob/client.rb', line 28 def initialize(*args) if args.empty? # Load configuration from file if no arguments were given @config = Esgob::Config.load elsif args.first.is_a?(Esgob::Config) @config = args.first elsif args.first.is_a?(Hash) @config = Esgob::Config.new(args.first) elsif args.length == 2 @config = Esgob::Config.new(:account => args[0], :key => args[1]) else raise(ArgumentError, "Unsupported arguments for creating Esgob::Client") end if config.nil? raise(Esgob::UnconfiguredError, "Unable to load Esgob configuration") end if config.account.nil? or config.account.empty? raise(ArgumentError, "No account name configured for Esgob") end if config.key.nil? or config.key.empty? raise(ArgumentError, "No API key configured for Esgob") end end |
Instance Attribute Details
#config ⇒ Esgob::Config (readonly)
Esgob configuration, used to store account name and key
8 9 10 |
# File 'lib/esgob/client.rb', line 8 def config @config end |
Instance Method Details
#accounts_get ⇒ Hash
Return account status; credit balance, etc.
90 91 92 93 94 |
# File 'lib/esgob/client.rb', line 90 def accounts_get account = call('accounts.get') account[:added] = Time.at(account[:added]) if account[:added].is_a?(Fixnum) account end |
#call(function_name, args = {}) ⇒ Hash
Call a named Esgob API function.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/esgob/client.rb', line 61 def call(function_name, args = {}) uri = URI(config.endpoint + function_name) uri.query = build_query(default_arguments.merge(args)) 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.content_type == 'application/json' data = symbolize_keys! JSON.parse(res.body) if data.key?(:error) raise Esgob::ServerError.new( data[:error][:message], data[:error][:code].to_s ) elsif res.code !~ /^2/ raise Esgob::ServerError.new(res., res.code) else return data end else raise "HTTP response from ESGOB is not of type JSON" end end |
#domains_list ⇒ Array<Hash>
Returns all hosted domains
98 99 100 |
# File 'lib/esgob/client.rb', line 98 def domains_list call('domains.list')[:domains] end |
#domains_slaves_add(domain, masterip) ⇒ Hash
Adds a new slave domain.
116 117 118 119 120 |
# File 'lib/esgob/client.rb', line 116 def domains_slaves_add(domain, masterip) result = call('domains.slaves.add', :domain => domain, :masterip => masterip) result[:domain] ||= domain result end |
#domains_slaves_axfrout_add(domain, axfrip) ⇒ Hash
Add a host allowed to AXFR out
154 155 156 157 158 |
# File 'lib/esgob/client.rb', line 154 def domains_slaves_axfrout_add(domain, axfrip) result = call('domains.slaves.axfrout.add', :domain => domain, :axfrip => axfrip) result[:domain] ||= domain result end |
#domains_slaves_axfrout_delete(domain, axfrip) ⇒ Hash
Account Delete a host allowed to AXFR out
164 165 166 167 168 |
# File 'lib/esgob/client.rb', line 164 def domains_slaves_axfrout_delete(domain, axfrip) result = call('domains.slaves.axfrout.delete', :domain => domain, :axfrip => axfrip) result[:domain] ||= domain result end |
#domains_slaves_delete(domain) ⇒ Hash
Deletes a slave domain.
125 126 127 128 129 |
# File 'lib/esgob/client.rb', line 125 def domains_slaves_delete(domain) result = call('domains.slaves.delete', :domain => domain) result[:domain] ||= domain result end |
#domains_slaves_forcetransfer(domain) ⇒ Hash
Force AXFR / transfer from master of a slave domain
134 135 136 137 138 |
# File 'lib/esgob/client.rb', line 134 def domains_slaves_forcetransfer(domain) result = call('domains.slaves.forcetransfer', :domain => domain) result[:domain] ||= domain result end |
#domains_slaves_list ⇒ Hash
Returns all hosted slave domains as a hash
104 105 106 107 108 109 110 |
# File 'lib/esgob/client.rb', line 104 def domains_slaves_list Hash[ call('domains.slaves.list')[:domains].map do |item| [item[:domain], item[:masterip]] end ] end |
#domains_slaves_sync(domains, masterip) ⇒ Array<Hash>
Given a list of domains and a master IP, add and delete domains so that the Esgob account matches the local list
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/esgob/client.rb', line 182 def domains_slaves_sync(domains, masterip) existing_domains = domains_slaves_list # Add any missing domains responses = [] domains.each do |domain| unless existing_domains.include?(domain) response = domains_slaves_add(domain, masterip) response[:domain] ||= domain responses << response end end # Now check the existing domains existing_domains.keys.sort.each do |domain| if domains.include?(domain) # Update the masterip if it isn't correct if existing_domains[domain] != masterip response = domains_slaves_updatemasterip(domain, masterip) response[:domain] ||= domain responses << response end else # Delete domain; not on list response = domains_slaves_delete(domain) response[:domain] ||= domain responses << response end end responses end |
#domains_slaves_updatemasterip(domain, masterip) ⇒ Hash
Updates the master IP of a slave domain
144 145 146 147 148 |
# File 'lib/esgob/client.rb', line 144 def domains_slaves_updatemasterip(domain, masterip) result = call('domains.slaves.updatemasterip', :domain => domain, :masterip => masterip) result[:domain] ||= domain result end |
#domains_tools_soacheck(domain) ⇒ Hash
Retrieve the domain SOA serial number from the master and each anycast node
173 174 175 |
# File 'lib/esgob/client.rb', line 173 def domains_tools_soacheck(domain) call('domains.tools.soacheck', :domain => domain) end |
#inspect ⇒ String
216 217 218 |
# File 'lib/esgob/client.rb', line 216 def inspect "\#<#{self.class} account=#{config.account}>" end |