Module: Dnsimple::Client::ZonesRecords

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

Instance Method Summary collapse

Instance Method Details

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

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.

Examples:

List all records for the zone “example.com”

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

Parameters:

  • account_id (Integer)

    the account ID

  • zone_id (String)

    the zone name

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

    the filtering and sorting options

Options Hash (options):

  • :page (Integer)

    current page (pagination)

  • :per_page (Integer)

    number of entries to return (pagination)

  • :sort (String)

    sorting policy

  • :filter (Hash)

    filtering policy

Returns:

Raises:

See Also:



67
68
69
# File 'lib/dnsimple/client/zones_records.rb', line 67

def all_zone_records(, zone_id, options = {})
  paginate(:list_zone_records, , zone_id, options)
end

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

Creates a zone record in the account.

Examples:

Create a URL record in zone “example.com”

client.zones.create_zone_record(1010, "example.com", name: "www", type: "url", content: "example.com")

Parameters:

  • account_id (Integer)

    the account ID

  • zone_id (String)

    the zone name

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

Returns:

Raises:

See Also:



86
87
88
89
90
91
# File 'lib/dnsimple/client/zones_records.rb', line 86

def create_zone_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::ZoneRecord.new(response["data"]))
end

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

Deletes a zone record from the account.

WARNING: this cannot be undone.

Examples:

Delete record 123 in zone “example.com”

client.zones.delete_zone_record(1010, "example.com", 123)

Parameters:

  • account_id (Integer)

    the account ID

  • zone_id (String)

    the zone name

  • record_id (Integer)

    the record ID

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

Returns:

Raises:

See Also:



153
154
155
156
157
# File 'lib/dnsimple/client/zones_records.rb', line 153

def delete_zone_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

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

Updates a zone record in the account.

Examples:

Update the TTL to 600 of record 123 in zone “example.com”

client.zones.update_zone_record(1010, "example.com", 123, ttl: 600)

Parameters:

  • account_id (Integer)

    the account ID

  • zone_id (String)

    the zone name

  • record_id (Integer)

    the record ID

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

Returns:

Raises:

See Also:



130
131
132
133
134
# File 'lib/dnsimple/client/zones_records.rb', line 130

def update_zone_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::ZoneRecord.new(response["data"]))
end

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

Gets a zone record from the account.

Examples:

Get record 123 in zone “example.com”

client.zones.zone_record(1010, "example.com", 123)

Parameters:

  • account_id (Integer)

    the account ID

  • zone_id (String)

    the zone name

  • record_id (Integer)

    the record ID

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

Returns:

Raises:

See Also:



108
109
110
111
112
# File 'lib/dnsimple/client/zones_records.rb', line 108

def zone_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::ZoneRecord.new(response["data"]))
end

#zone_records(account_id, zone_id, options = {}) ⇒ Dnsimple::PaginatedResponse<Dnsimple::Struct::ZoneRecord> Also known as: list_zone_records

Lists the zone records in the account.

Examples:

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

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

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

client.zones.list_zone_records(1010, "example.com", page: 2)

List records for the zone “example.com”, sorting in ascending order

client.zones.list_zone_records(1010, "example.com", sort: "type:asc")

List records for the zone “example.com”, filtering by ‘A’ record type

client.zones.list_zone_records(1010, "example.com", filter: { type: 'A' })

Parameters:

  • account_id (Integer)

    the account ID

  • zone_id (String)

    the zone name

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

    the filtering and sorting options

Options Hash (options):

  • :page (Integer)

    current page (pagination)

  • :per_page (Integer)

    number of entries to return (pagination)

  • :sort (String)

    sorting policy

  • :filter (Hash)

    filtering policy

Returns:

Raises:

See Also:



35
36
37
38
39
# File 'lib/dnsimple/client/zones_records.rb', line 35

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

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