Module: NSOne::API::Zones

Defined in:
lib/nsone/api/zones.rb

Instance Method Summary collapse

Instance Method Details

#create_zone(zone, params = {}) ⇒ NSOne::Response

Create a new DNS zone. You must include a JSON body in the request with basic details of the zone. The only required element in the body is zone.

For all the zone options @see [NSOne API - create-a-new-dns-zone](jsapi.apiary.io/apis/ns1api/reference/zones-and-records/zone/create-a-new-dns-zone.html)

Parameters:

  • zone (required, String)

    zone name

  • params (Hash) (defaults to: {})

Returns:

Raises:



39
40
41
42
43
# File 'lib/nsone/api/zones.rb', line 39

def create_zone(zone, params = {})
  raise NSOne::MissingParameter, "zone cannot be blank" if blank?(zone)
  params = params.merge(zone: zone)
  perform_request(HTTP_PUT, "/v1/zones/#{zone}", params)
end

#delete_zone(zone) ⇒ NSOne::Response

Destroys an existing DNS zone and all records in the zone

Parameters:

  • zone (required, String)

    zone name

Returns:

Raises:



68
69
70
71
# File 'lib/nsone/api/zones.rb', line 68

def delete_zone(zone)
  raise NSOne::MissingParameter, "zone cannot be blank" if blank?(zone)
  perform_request(HTTP_DELETE, "/v1/zones/#{zone}")
end

#modify_zone(zone, params = {}) ⇒ NSOne::Response

Modifies basic details of a DNS zone. You must include a JSON body in the request, in which you may include ttl (SOA record TTL), refresh, retry, expiry, or nx_ttl values, as in a SOA record. You may not change the zone name or other details.

Parameters:

Returns:

Raises:



55
56
57
58
59
# File 'lib/nsone/api/zones.rb', line 55

def modify_zone(zone, params = {})
  raise NSOne::MissingParameter, "zone cannot be blank" if blank?(zone)
  raise NSOne::MissingParameter, "params hash must contain valid zone settings" if !params.is_a?(Hash) || params.empty?
  perform_request(HTTP_POST, "/v1/zones/#{zone}", params)
end

#search(string, params = {}) ⇒ NSOne::Response

Returns all zones and records that match the given ‘string`. You can limit the max number of results and you can restrict the type of results to zone, record, or all. Entries in the response without domain/type are zones, and those with domain/type are records.

Parameters:

  • string (required, String)

    search string

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :max (Integer)

    the max results to return

  • :type (String)

    to limit the search. valid options are ‘zone`, `record` or `all`

Returns:

Raises:



86
87
88
89
90
# File 'lib/nsone/api/zones.rb', line 86

def search(string, params = {})
  raise NSOne::MissingParameter, "search string cannot be blank" if blank?(string)
  params = params.merge(q: string)
  perform_request(HTTP_GET, "/v1/search", params)
end

#zone(zone) ⇒ NSOne::Response

Returns a single active Zone and its basic configuration details including all the zones records in a “records” array.

Parameters:

  • zone (required, String)

    zone name

Returns:

Raises:



23
24
25
26
# File 'lib/nsone/api/zones.rb', line 23

def zone(zone)
  raise NSOne::MissingParameter, "zone cannot be blank" if blank?(zone)
  perform_request(HTTP_GET, "/v1/zones/#{zone}")
end

#zonesNSOne::Response

Returns all active zones and basic zone configuration details for each

Returns:



12
13
14
# File 'lib/nsone/api/zones.rb', line 12

def zones
  perform_request(HTTP_GET, "/v1/zones")
end