Module: NSOne::API::Records

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

Instance Method Summary collapse

Instance Method Details

#create_record(zone, domain, type, params = {}) ⇒ NSOne::Response

<Description>

Examples:

Request body with answers and filter chain arrays. @see [NSOne API](ns1.com/api)

{
  "zone":"example.com",
  "domain":"georegion.example.com",
  "type":"A",
  "use_client_subnet":false,
  "answers":[
    {
      "answer":[
        "1.1.1.1"
      ],
      "meta":{
        "georegion":[
          "US-EAST"
        ]
      }
    },
    {
      "answer":[
        "9.9.9.9"
      ],
      "meta":{
        "georegion":[
          "US-WEST"
        ]
      }
    }
  ],
  "filters":[
    {
      "filter":"geotarget_regional",
      "config": {}
    },
    {
      "filter":"select_first_n",
      "config":{
        "N":1
      }
    }
  ]
}

Parameters:

  • zone (String)

    zone name

  • domain (String)

    record name

  • type (String)

    record type (A, CNAME etc)

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

    will be used as the request body

Options Hash (params):

  • :zone (String)

    zone name

  • :domain (String)

    record name

  • :type (String)

    record type (A, CNAME etc)

  • :link (String)

    record name. This is used to create a ‘linked` record to another record. When using :link answers array should be empty and filters arrays should be omitted.

  • :answers (Array<Hash>)

    Array of Hashes with the RDATA values

  • :filters (Array<Hash>)

    Array of Hashes with settings for record filter-chains rules

  • :use_client_subnet (Boolean)

    enable EDNS on the record.

    Default: ‘true`

Returns:

Raises:



95
96
97
98
99
100
101
102
103
# File 'lib/nsone/api/records.rb', line 95

def create_record(zone, domain, type, params = {})
  raise NSOne::MissingParameter, "zone cannot be blank" if blank?(zone)
  raise NSOne::MissingParameter, "domain cannot be blank" if blank?(domain)
  raise NSOne::MissingParameter, "type cannot be blank" if blank?(type)
  validate_required!(params, :answers)
  normalize_names!(zone, domain)
  params = params.merge(zone: zone, domain: domain, type: type)
  perform_request(HTTP_PUT, "/v1/zones/#{zone}/#{domain}/#{type}", params)
end

#delete_record(zone, domain, type) ⇒ NSOne::Response

Removes an existing record and all associated answers and configuration details

Parameters:

  • zone (String)

    zone name

  • domain (String)

    record name

  • type (String)

    record type (A, CNAME etc)

Returns:

Raises:



127
128
129
130
131
132
133
# File 'lib/nsone/api/records.rb', line 127

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

#modify_record(zone, domain, type, params) ⇒ NSOne::Response

Modify an existing record. See #create_record for available options.



110
111
112
113
114
115
116
# File 'lib/nsone/api/records.rb', line 110

def modify_record(zone, domain, type, params)
  raise NSOne::MissingParameter, "zone cannot be blank" if blank?(zone)
  raise NSOne::MissingParameter, "domain cannot be blank" if blank?(domain)
  raise NSOne::MissingParameter, "type cannot be blank" if blank?(type)
  normalize_names!(zone, domain)
  perform_request(HTTP_POST, "/v1/zones/#{zone}/#{domain}/#{type}", params)
end

#record(zone, domain, type) ⇒ NSOne::Response

Returns full configuration for a DNS record including basic config, answers, regions, filter chain configuration, and all metadata tables and data feeds attached to entities in the record

Parameters:

  • zone (String)

    zone name

  • domain (String)

    record name

  • type (String)

    record type (A, CNAME etc)

Returns:

Raises:



17
18
19
20
21
22
23
# File 'lib/nsone/api/records.rb', line 17

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