Module: Dnsimple::Client::TemplatesRecords

Included in:
TemplatesService
Defined in:
lib/dnsimple/client/templates_records.rb

Instance Method Summary collapse

Instance Method Details

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

Lists ALL the records in the template.

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 the records for “alpha template

client.templates.all_records(1010, "alpha")

Parameters:

  • account_id (Integer)

    the account ID

  • template_id (String)

    the template 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

Returns:

Raises:

See Also:



61
62
63
# File 'lib/dnsimple/client/templates_records.rb', line 61

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

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

Creates a record in the template.

Examples:

Create an A record for “alpha” template

client.templates.create_record(1010, "alpha", name: "", type: "A", content: "192.168.1.1", ttl: 600)

Parameters:

  • account_id (Integer)

    the account ID

  • template_id (String)

    the template name

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

Returns:

Raises:

See Also:



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

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

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

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

Deletes a record from the template.

WARNING: this cannot be undone.

Examples:

Delete record 123 in “alpha template

client.templates.delete_record(1010, "alpha", 123)

Parameters:

  • account_id (Integer)

    the account ID

  • template_id (String)

    the template name

  • record_id (Integer)

    the record ID

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

Returns:

Raises:

See Also:



127
128
129
130
131
132
# File 'lib/dnsimple/client/templates_records.rb', line 127

def delete_record(, template_id, record_id, options = {})
  endpoint = Client.versioned("/%s/templates/%s/records/%s" % [, template_id, record_id])
  response = client.delete(endpoint, options)

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

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

Gets a record from the template.

Examples:

Get record 123 in “alpha template

client.templates.record(1010, "alpha", 123)

Parameters:

  • account_id (Integer)

    the account ID

  • template_id (String)

    the template name

  • record_id (Integer)

    the record ID

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

Returns:

Raises:

See Also:



103
104
105
106
107
108
# File 'lib/dnsimple/client/templates_records.rb', line 103

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

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

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

Lists the records in the template.

Examples:

List the first page of records for the template “alpha”

client.templates.records(1010, "alpha")

List records for the template “alpha”, providing a specific page

client.templates.records(1010, "alpha", page: 2)

List records for the template “alpha”, providing sorting policy

client.templates.records(1010, "alpha", sort: "type:asc")

Parameters:

  • account_id (Integer)

    the account ID

  • template_id (String)

    the template 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

Returns:

Raises:

See Also:



29
30
31
32
33
34
# File 'lib/dnsimple/client/templates_records.rb', line 29

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

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