Module: Idcf::Dns::ClientExtensions::Record

Included in:
Idcf::Dns::Client
Defined in:
lib/idcf/dns/client_extensions/record.rb

Overview

SDK APIs for record resource

Instance Method Summary collapse

Instance Method Details

#create_record(zone_uuid, attributes, headers = {}) ⇒ Response

Create a new record.

Examples:

response =
  client.create_record(
    "ddcd8dbf-8d99-4f49-9958-7dd9a0bfb67f",
    name: "www.foobar.example.com",
    type: "A",
    content: "8.8.8.8",
    ttl: 3600
  )

response.body #=>
  {"uuid"=>"40d5f26f-02bd-4fb1-b363-323675772289",
   "name"=>"www.foobar.example.com",
   "type"=>"A",
   "content"=>"8.8.8.8",
   "ttl"=>3600,
   "created_at"=>"2015-11-09T11:43:50+09:00",
   "updated_at"=>nil,
   "priority"=>nil}

response.uuid #=> "40d5f26f-02bd-4fb1-b363-323675772289"

Parameters:

  • zone_uuid (String)

    UUID of zone

  • attributes (Hash)

    request attributes

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

    HTTP request headers

Options Hash (attributes):

  • :name (String)

    name of record (required)

  • :type (String)

    type of record (required) (A, AAAA, CNAME, MX, TXT or SRV)

  • :content (String)

    content of record (required)

  • :ttl (Integer)

    TTL (required)

  • :priority (Integer)

    priority of record

Returns:



39
40
41
42
# File 'lib/idcf/dns/client_extensions/record.rb', line 39

def create_record(zone_uuid, attributes, headers = {})
  Validators::Record.validate_attributes!(attributes, :create)
  post!("zones/#{zone_uuid}/records", attributes, headers)
end

#delete_record(zone_uuid, uuid, headers = {}) ⇒ Response

Delete a record.

Examples:

response =
  client.delete_record(
    "ddcd8dbf-8d99-4f49-9958-7dd9a0bfb67f",
    "d612aabb-3fea-471a-8712-586f1ac9c29c"
  )

response.body #=> {}

response.status #=> 200

Parameters:

  • zone_uuid (String)

    UUID of zone

  • uuid (String)

    UUID of record

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

    HTTP request headers

Returns:



60
61
62
# File 'lib/idcf/dns/client_extensions/record.rb', line 60

def delete_record(zone_uuid, uuid, headers = {})
  delete!("zones/#{zone_uuid}/records/#{uuid}", {}, headers)
end

#get_record(zone_uuid, uuid, headers = {}) ⇒ Response

Get a record.

Examples:

response =
  client.get_record(
    "ddcd8dbf-8d99-4f49-9958-7dd9a0bfb67f",
    "d612aabb-3fea-471a-8712-586f1ac9c29c"
  )

response.body #=>
  {"uuid"=>"ecacc77f-e678-4f29-b6dd-6bec79c172a1",
   "name"=>"www.foobar.example.com",
   "type"=>"A",
   "content"=>"8.8.8.8",
   "ttl"=>3600,
   "created_at"=>"2015-11-09T16:07:21+09:00",
   "updated_at"=>nil,
   "priority"=>nil}

Parameters:

  • zone_uuid (String)

    UUID of zone

  • uuid (String)

    UUID of record

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

    HTTP request headers

Returns:



86
87
88
# File 'lib/idcf/dns/client_extensions/record.rb', line 86

def get_record(zone_uuid, uuid, headers = {})
  get!("zones/#{zone_uuid}/records/#{uuid}", {}, headers)
end

#list_records(zone_uuid, headers = {}) ⇒ Response

Get list of records.

Examples:

response =
  client.list_records("ddcd8dbf-8d99-4f49-9958-7dd9a0bfb67f")

response.body #=>
  [{"uuid"=>"9fae4a12-319c-4afc-ac33-4542ef79dd0b",
    "name"=>"foobar.example.com",
    "type"=>"SOA",
    "content"=>
     {"dns"=>"ns01.idcfcloud.com",
      "email"=>"foobar.example.com.",
      "serial"=>4,
      "refresh"=>10800,
      "retry"=>3600,
      "expire"=>604800,
      "ttl"=>3600},
    "ttl"=>3600,
    "created_at"=>"2015-11-09T13:24:58+09:00",
    "updated_at"=>"2015-11-09T16:07:21+09:00",
    "priority"=>nil},
   {"uuid"=>"f61a75b7-8e9c-4e69-a91a-6e6aa90c2990",
    "name"=>"foobar.example.com",
    "type"=>"NS",
    "content"=>"ns01.idcfcloud.com",
    "ttl"=>3600,
    "created_at"=>"2015-11-09T13:24:58+09:00",
    "updated_at"=>nil,
    "priority"=>nil},
   {"uuid"=>"0195fe5d-7cff-4f94-8886-a13bb0f609b4",
    "name"=>"foobar.example.com",
    "type"=>"NS",
    "content"=>"ns02.idcfcloud.com",
    "ttl"=>3600,
    "created_at"=>"2015-11-09T13:24:58+09:00",
    "updated_at"=>nil,
    "priority"=>nil},
   {"uuid"=>"0bdc7d49-b1aa-4455-903f-35dc3c4338be",
    "name"=>"foobar.example.com",
    "type"=>"NS",
    "content"=>"ns03.idcfcloud.com",
    "ttl"=>3600,
    "created_at"=>"2015-11-09T13:24:58+09:00",
    "updated_at"=>nil,
    "priority"=>nil},
   {"uuid"=>"ecacc77f-e678-4f29-b6dd-6bec79c172a1",
    "name"=>"www.foobar.example.com",
    "type"=>"A",
    "content"=>"8.8.8.8",
    "ttl"=>3600,
    "created_at"=>"2015-11-09T16:07:21+09:00",
    "updated_at"=>nil,
    "priority"=>nil}]

Parameters:

  • zone_uuid (String)

    UUID of zone

Returns:



146
147
148
# File 'lib/idcf/dns/client_extensions/record.rb', line 146

def list_records(zone_uuid, headers = {})
  get!("zones/#{zone_uuid}/records", {}, headers)
end

#record(zone_uuid, uuid, headers = {}) ⇒ Resources::Record

Get a record object.

Parameters:

  • zone_uuid (String)

    UUID of zone

  • uuid (String)

    UUID of record

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

    HTTP request headers

Returns:



191
192
193
# File 'lib/idcf/dns/client_extensions/record.rb', line 191

def record(zone_uuid, uuid, headers = {})
  Resources::Record.new(self, get_record(zone_uuid, uuid, headers).body)
end

#records(zone_uuid, headers = {}) ⇒ Array<Resource::Record>

Get an array of existing record objects.

Parameters:

  • zone_uuid (String)

    UUID of zone

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

    HTTP request headers

Returns:

  • (Array<Resource::Record>)

    an array of record objects



200
201
202
# File 'lib/idcf/dns/client_extensions/record.rb', line 200

def records(zone_uuid, headers = {})
  zone(zone_uuid).records
end

#update_record(zone_uuid, uuid, attributes, headers = {}) ⇒ Response

Update a record.

Examples:

response =
  client.update_record(
    "ddcd8dbf-8d99-4f49-9958-7dd9a0bfb67f",
    "d612aabb-3fea-471a-8712-586f1ac9c29c",
    content: "6.6.6.6"
  )

response.body #=>
  {"uuid"=>"ecacc77f-e678-4f29-b6dd-6bec79c172a1",
   "name"=>"www.foobar.example.com",
   "type"=>"A",
   "content"=>"6.6.6.6",
   "ttl"=>3600,
   "created_at"=>"2015-11-09T16:07:21+09:00",
   "updated_at"=>"2015-11-09T16:22:17+09:00",
   "priority"=>nil}

Parameters:

  • zone_uuid (String)

    UUID of zone

  • uuid (String)

    UUID of record

  • attributes (Hash)

    request attributes

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

    HTTP request headers

Options Hash (attributes):

  • :name (String)

    name of record

  • :type (String)

    type of record (A, AAAA, CNAME, MX, TXT or SRV)

  • :content (String)

    content of record

  • :ttl (Integer)

    TTL

  • :priority (Integer)

    priority of record

Returns:



180
181
182
183
# File 'lib/idcf/dns/client_extensions/record.rb', line 180

def update_record(zone_uuid, uuid, attributes, headers = {})
  Validators::Record.validate_attributes!(attributes, :update)
  put!("zones/#{zone_uuid}/records/#{uuid}", attributes, headers)
end