Class: Ultradns::Client
- Inherits:
-
Object
- Object
- Ultradns::Client
- Includes:
- HTTParty, Api::Authentication
- Defined in:
- lib/ultradns/client.rb
Instance Method Summary collapse
-
#account(account_name) ⇒ Object
Access Account Level Resources for the given account_name.
-
#accounts ⇒ Object
Get account details for user.
-
#create_primary_zone(account_name, zone_name) ⇒ Object
Create a primary zone.
-
#initialize(username, password, options = {}) ⇒ Client
constructor
Initialize an Ultra REST API client.
-
#status ⇒ Object
Get status of REST API server.
-
#tasks(options = {}) ⇒ Object
List the background tasks (jobs) running.
-
#version ⇒ Object
Get version of REST API server.
-
#zone(zone_name) ⇒ Object
Required Parameters.
Methods included from Api::Authentication
#access_token, #add_auth_header!, #auth, #auth_failure?, #no_expiry?, #refresh, #refresh?, #with_auth_retry
Constructor Details
#initialize(username, password, options = {}) ⇒ Client
Initialize an Ultra REST API client
Required Parameters
-
username
- The user name -
password
- The user’s password
Optional Parameters
-
:use_http
- Use http instead of https. Defaults to false, set to true only in test environments. Will not work in production. -
:host
- host and port of the remote server. Defaults to restapi.ultradns.com.
Examples
c = RestClient.new("myUname", "myPwd")
c = RestClient.new("myUname", "myPwd", host: 'restapi-useast1b01-01.ct.ultradns.net:8080')
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ultradns/client.rb', line 49 def initialize(username, password, = {}) @logger ||= ::Logger.new($stdout) @options = {} # override or ignored if nil default_base_uri = URI(self.class.[:base_uri]) if [:host] host = [:host].prepend("#{default_base_uri.scheme}://") host << default_base_uri.path @options[:base_uri] = HTTParty.normalize_base_uri(host) elsif [:base_uri] # take whatever they provide @options[:base_uri] = HTTParty.normalize_base_uri([:base_uri]) end auth(username, password, @options[:base_uri] || self.class.[:base_uri]) logger.debug "Initializing UltraDNS Client using #{@options.inspect}" end |
Instance Method Details
#account(account_name) ⇒ Object
Access Account Level Resources for the given account_name
Required Parameters
-
account_name
- One of the user’s accounts. The user must have read access for zones in that account.
98 99 100 |
# File 'lib/ultradns/client.rb', line 98 def account(account_name) Ultradns::Api::Account.new(self, account_name) end |
#accounts ⇒ Object
Get account details for user
Examples
c.accounts
107 108 109 |
# File 'lib/ultradns/client.rb', line 107 def accounts with_auth_retry {|c| c.get '/accounts', } end |
#create_primary_zone(account_name, zone_name) ⇒ Object
Create a primary zone
Required Parameters
-
account_name
- The account that the zone will be created under. The user must have write access for zones in that account. -
zone_name
- The name of the zone. The trailing . is optional. The zone name must not be in use by anyone.
Examples
c.create_primary_zone('my_account', 'zone.invalid.')
131 132 133 134 135 136 137 138 |
# File 'lib/ultradns/client.rb', line 131 def create_primary_zone(account_name, zone_name) zone_properties = {:name => zone_name, :accountName => account_name, :type => 'PRIMARY'} primary_zone_info = {:forceImport => true, :createType => 'NEW'} zone_data = {:properties => zone_properties, :primaryCreateInfo => primary_zone_info} with_auth_retry {|c| c.post '/zones', ({:body => zone_data.to_json}) } end |
#status ⇒ Object
Get status of REST API server
Examples
c.status
87 88 89 |
# File 'lib/ultradns/client.rb', line 87 def status with_auth_retry {|c| c.get '/status', } end |
#tasks(options = {}) ⇒ Object
List the background tasks (jobs) running. Some APIs will return a Task Id which can used to determine the state of those jobs.
Optional Parameters
-
:q
- The search parameters, in a hash. The query used to construct the list.Valid keys are: code - valid values for 'code' are PENDING, IN_PROCESS, COMPLETE, and ERROR. hasData - valid values for 'hasData' are true and false.
-
offset
- The position in the list for the first returned element (0 based). Thedefault value is 0.
-
limit
- The maximum number of rows requested. The default value is 100. -
sort
- The sort column used to order the list. Valid sort fields are CODE, CONTENT_TYPE, EXTENSIONS,HAS_DATA, and DATE. The default value is CODE.
-
reverse
- Whether the list is ascending (false) or descending (true). The defaultvalue is false.
161 162 163 |
# File 'lib/ultradns/client.rb', line 161 def tasks( = {}) with_auth_retry {|c| c.get("/tasks", ()) } end |
#version ⇒ Object
Get version of REST API server
Examples
c.version
77 78 79 |
# File 'lib/ultradns/client.rb', line 77 def version with_auth_retry {|c| c.get '/version', } end |