Module: Dnsimple::Client::Templates

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

Instance Method Summary collapse

Instance Method Details

#all_templates(account_id, options = {}) ⇒ Dnsimple::PaginatedResponse<Dnsimple::Struct::Template>

Lists ALL the templates in the account.

This method is similar to #templates, 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 templates for account 1010:

client.templates.all_templates(1010)

Parameters:

  • account_id (Integer)

    the account ID

  • 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:



56
57
58
# File 'lib/dnsimple/client/templates.rb', line 56

def all_templates(, options = {})
  paginate(:templates, , options)
end

#create_template(account_id, attributes, options = {}) ⇒ Dnsimple::Response<Dnsimple::Struct::Template>

Creates a template in the account.

Examples:

Creating a template:

client.templates.create_template(1010, name: "Pi", short_name: "pi", description: "Pi template")

Parameters:

  • account_id (Integer)

    the account ID

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

Returns:

Raises:

See Also:



73
74
75
76
77
78
# File 'lib/dnsimple/client/templates.rb', line 73

def create_template(, attributes, options = {})
  endpoint = Client.versioned("/%s/templates" % [])
  response = client.post(endpoint, attributes, options)

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

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

Deletes a template from the account.

WARNING: this cannot be undone.

Examples:

Delete template 5401 in account 1010:

client.templates.delete_template(1010, 5401)

Parameters:

  • account_id (Integer)

    The account ID

  • template_id (#to_s)

    The template ID

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

Returns:

Raises:

See Also:



137
138
139
140
141
142
# File 'lib/dnsimple/client/templates.rb', line 137

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

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

#template(account_id, template_id, options = {}) ⇒ Dnsimple::Response<Dnsimple::Struct::Template>

Gets the template with specified ID.

Examples:

Get template 5401 in account 1010:

client.templates.template(1010, 5401)

Parameters:

  • account_id (Integer)

    the account ID

  • template_id (#to_s)

    The template ID

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

Returns:

Raises:

See Also:



93
94
95
96
97
98
# File 'lib/dnsimple/client/templates.rb', line 93

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

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

#templates(account_id, options = {}) ⇒ Dnsimple::PaginatedResponse<Dnsimple::Struct::Template> Also known as: list_templates

Lists the templates in the account.

Examples:

List the templates for account 1010:

client.templates.list_templates(1010)

List the templates for account 1010, provide a specific page:

client.templates.list_templates(1010, page: 2)

List the templates for account 1010, provide sorting policy:

client.templates.list_templates(1010, sort: "short_name:asc")

Parameters:

  • account_id (Integer)

    the account ID

  • 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:



26
27
28
29
30
31
# File 'lib/dnsimple/client/templates.rb', line 26

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

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

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

Updates template with specified ID with provided data.

Examples:

Change the name of template 1 in account 1010:

client.templates.update_template(1010, 1, name: "New name")

Parameters:

  • account_id (Integer)

    the account ID

  • template_id (#to_s)

    The template ID

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

Returns:

Raises:

See Also:



114
115
116
117
118
119
# File 'lib/dnsimple/client/templates.rb', line 114

def update_template(, template_id, attributes, options = {})
  endpoint = Client.versioned("/%s/templates/%s" % [, template_id])
  response = client.patch(endpoint, attributes, options)

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