Module: Dnsimple::Client::Templates

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

Instance Method Summary collapse

Instance Method Details

#create_template(attributes = {}, options = {}) ⇒ Struct::Template Also known as: create

Creates a template in the account.

Parameters:

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

Returns:

Raises:

See Also:



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

def create_template(attributes = {}, options = {})
  Extra.validate_mandatory_attributes(attributes, [:name, :short_name])
  options  = options.merge({ dns_template: attributes })
  response = client.post(Client.versioned("templates"), options)

  Struct::Template.new(response["dns_template"])
end

#delete_template(template, options = {}) ⇒ void Also known as: delete

This method returns an undefined value.

Deletes a template from the account.

WARNING: this cannot be undone.

Parameters:

  • template (#to_s)

    The template id or short-name.

Raises:

See Also:



81
82
83
# File 'lib/dnsimple/client/templates.rb', line 81

def delete_template(template, options = {})
  client.delete(Client.versioned("templates/#{template}"), options)
end

#template(template, options = {}) ⇒ Struct::Template

Gets a template from the account.

Parameters:

  • template (#to_s)

    The template id or short-name.

Returns:

Raises:

See Also:



46
47
48
49
50
# File 'lib/dnsimple/client/templates.rb', line 46

def template(template, options = {})
  response = client.get(Client.versioned("templates/#{template}"), options)

  Struct::Template.new(response["dns_template"])
end

#templates(options = {}) ⇒ Array<Struct::Template> Also known as: list, list_templates

Lists the templates in the account.

Returns:

Raises:

See Also:



12
13
14
15
16
# File 'lib/dnsimple/client/templates.rb', line 12

def templates(options = {})
  response = client.get(Client.versioned("templates"), options)

  response.map { |r| Struct::Template.new(r["dns_template"]) }
end

#update_template(template, attributes = {}, options = {}) ⇒ Struct::Template Also known as: update

Updates a template in the account.

Parameters:

  • template (#to_s)

    The template id or short-name.

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

Returns:

Raises:

See Also:



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

def update_template(template, attributes = {}, options = {})
  options  = options.merge({ dns_template: attributes })
  response = client.put(Client.versioned("templates/#{template}"), options)

  Struct::Template.new(response["dns_template"])
end