Module: Dnsimple::Client::ZonesRecords

Included in:
ZonesService
Defined in:
lib/dnsimple/client/zones_records.rb

Instance Method Summary collapse

Instance Method Details

#all_records(account_id, zone_id, options = {}) ⇒ Dnsimple::CollectionResponse<Dnsimple::Struct::Record>

Lists ALL the zone records in the account.

This method is similar to #records, but instead of returning the results of a specific page it iterates all the pages and returns the entire collection.

Please use this method carefully, as fetching the entire collection will increase the number of requests you send to the API server and you may eventually risk to hit the throttle limit.

Parameters:

  • account_id (Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT)

    the account ID or wildcard

  • zone_id (String)

    the zone name

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

    the filtering and sorting option

Returns:

Raises:

See Also:



46
47
48
# File 'lib/dnsimple/client/zones_records.rb', line 46

def all_records(, zone_id, options = {})
  paginate(:records, , zone_id, options)
end

#create_record(account_id, zone_id, attributes, options = {}) ⇒ Dnsimple::Response<Dnsimple::Struct::Record>

Creates a zone record in the account.

Parameters:

  • account_id (Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT)

    the account ID or wildcard

  • zone_id (String)

    the zone name

  • attributes (Hash)
  • options (Hash) (defaults to: {})

Returns:

Raises:

See Also:



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

def create_record(, zone_id, attributes, options = {})
  Extra.validate_mandatory_attributes(attributes, [:type, :name, :content])
  response = client.post(Client.versioned("/%s/zones/%s/records" % [, zone_id]), attributes, options)

  Dnsimple::Response.new(response, Struct::Record.new(response["data"]))
end

#delete_record(account_id, zone_id, record_id, options = {}) ⇒ Dnsimple::Response<nil>

Deletes a zone record from the account.

WARNING: this cannot be undone.

Parameters:

  • account_id (Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT)

    the account ID or wildcard

  • zone_id (String)

    the zone name

  • record_id (Fixnum)

    the record ID

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

Returns:

Raises:

See Also:



119
120
121
122
123
# File 'lib/dnsimple/client/zones_records.rb', line 119

def delete_record(, zone_id, record_id, options = {})
  response = client.delete(Client.versioned("/%s/zones/%s/records/%s" % [, zone_id, record_id]), nil, options)

  Dnsimple::Response.new(response, nil)
end

#record(account_id, zone_id, record_id, options = {}) ⇒ Dnsimple::Response<Dnsimple::Struct::Domain>

Gets a zone record from the account.

Parameters:

  • account_id (Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT)

    the account ID or wildcard

  • zone_id (String)

    the zone name

  • record_id (Fixnum)

    the record ID

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

Returns:

Raises:

See Also:



80
81
82
83
84
# File 'lib/dnsimple/client/zones_records.rb', line 80

def record(, zone_id, record_id, options = {})
  response = client.get(Client.versioned("/%s/zones/%s/records/%s" % [, zone_id, record_id]), options)

  Dnsimple::Response.new(response, Struct::Record.new(response["data"]))
end

#records(account_id, zone_id, options = {}) ⇒ Dnsimple::PaginatedResponse<Dnsimple::Struct::Record> Also known as: list_records

Lists the zone records in the account.

Examples:

List records for the zone “example.com” in the first page

client.zones.records(1010, "example.com")

List records for the zone “example.com”, provide a specific page

client.zones.records(1010, "example.com", query: { page: 2 })

Parameters:

  • account_id (Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT)

    the account ID or wildcard

  • zone_id (String)

    the zone name

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

    the filtering and sorting option

Returns:

Raises:

See Also:



22
23
24
25
26
# File 'lib/dnsimple/client/zones_records.rb', line 22

def records(, zone_id, options = {})
  response = client.get(Client.versioned("/%s/zones/%s/records" % [, zone_id]), options)

  Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Record.new(r) })
end

#update_record(account_id, zone_id, record_id, attributes, options = {}) ⇒ Dnsimple::Response<Dnsimple::Struct::Record>

Updates a zone record in the account.

Parameters:

  • account_id (Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT)

    the account ID or wildcard

  • zone_id (String)

    the zone name

  • record_id (Fixnum)

    the record ID

  • attributes (Hash)
  • options (Hash) (defaults to: {})

Returns:

Raises:

See Also:



99
100
101
102
103
# File 'lib/dnsimple/client/zones_records.rb', line 99

def update_record(, zone_id, record_id, attributes, options = {})
  response = client.patch(Client.versioned("/%s/zones/%s/records/%s" % [, zone_id, record_id]), attributes, options)

  Dnsimple::Response.new(response, Struct::Record.new(response["data"]))
end