Module: Idcf::Dns::ClientExtensions::Zone

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

Overview

SDK APIs for zone resource

Instance Method Summary collapse

Instance Method Details

#create_zone(attributes, headers = {}) ⇒ Response

Create a new zone.

Examples:

response =
  client.create_zone(
    name: "foobar.example.com",
    email: "[email protected]",
    description: "",
    default_ttl: 600
  )

response.body #=>
  {"uuid"=>"384178f5-58a5-4f3c-9607-5e189ab2990d",
   "name"=>"foobar.example.com",
   "default_ttl"=>600,
   "created_at"=>"2015-11-09T11:43:49+09:00",
   "updated_at"=>nil,
   "records"=>
    [{"uuid"=>"6aba1170-83b9-4324-b331-8c2b8dcb5162",
      "name"=>"foobar.example.com",
      "type"=>"SOA",
      "content"=>
       {"dns"=>"ns01.idcfcloud.com",
        "email"=>"foobar.example.com.",
        "serial"=>1,
        "refresh"=>10800,
        "retry"=>3600,
        "expire"=>604800,
        "ttl"=>3600},
      "ttl"=>3600,
      "created_at"=>"2015-11-09T11:43:49+09:00",
      "updated_at"=>nil,
      "priority"=>nil},
     {"uuid"=>"0b18679d-dd47-46fe-8812-d20c284001ac",
      "name"=>"foobar.example.com",
      "type"=>"NS",
      "content"=>"ns01.idcfcloud.com",
      "ttl"=>3600,
      "created_at"=>"2015-11-09T11:43:49+09:00",
      "updated_at"=>nil,
      "priority"=>nil},
     {"uuid"=>"a5a9ab9c-b19f-4411-880e-842ffd53027c",
      "name"=>"foobar.example.com",
      "type"=>"NS",
      "content"=>"ns02.idcfcloud.com",
      "ttl"=>3600,
      "created_at"=>"2015-11-09T11:43:49+09:00",
      "updated_at"=>nil,
      "priority"=>nil},
     {"uuid"=>"2756ed66-2b69-4ae2-8065-69ac2b12b71d",
      "name"=>"foobar.example.com",
      "type"=>"NS",
      "content"=>"ns03.idcfcloud.com",
      "ttl"=>3600,
      "created_at"=>"2015-11-09T11:43:49+09:00",
      "updated_at"=>nil,
      "priority"=>nil}],
   "description"=>"",
   "authenticated"=>false}

response.uuid #=> "384178f5-58a5-4f3c-9607-5e189ab2990d"

Parameters:

  • attributes (Hash)

    request attributes

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

    HTTP request headers

Options Hash (attributes):

  • :name (String)

    unique name of zone (required)

  • :email (String)

    e-mail address (required)

  • :description (String)

    description

  • :default_ttl (Integer)

    default TTL (required)

Returns:



74
75
76
77
# File 'lib/idcf/dns/client_extensions/zone.rb', line 74

def create_zone(attributes, headers = {})
  Validators::Zone.validate_attributes!(attributes, :create)
  post!("zones", attributes, headers)
end

#delete_zone(uuid, headers = {}) ⇒ Response

Delete a zone.

Examples:

response =
  client.delete_zone("83f55e72-e3fa-4961-89b3-99ee43617b93")

response.body #=> {}

response.status #=> 200

Parameters:

  • uuid (String)

    UUID of target zone

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

    HTTP request headers

Returns:



91
92
93
# File 'lib/idcf/dns/client_extensions/zone.rb', line 91

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

#get_token(uuid, headers = {}) ⇒ Response

Get a verify token.

Examples:

response =
  client.get_token(
    "384178f5-58a5-4f3c-9607-5e189ab2990d"
  )

response.body #=>
  {"TXT"=>["idcf-dns-token=0123456789abcdef0123456789abcdef"],
    "NS"=>[
      "0123456789abcdef0123456789abcdef.dns-verify.idc.jp",
      "ns01.idcfcloud.com",
      "ns02.idcfcloud.com",
      "ns03.idcfcloud.com"
    ]}

Parameters:

  • uuid (String)

    UUID of target zone

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

    HTTP request headers

Returns:



280
281
282
# File 'lib/idcf/dns/client_extensions/zone.rb', line 280

def get_token(uuid, headers = {})
  get!("zones/#{uuid}/token", {}, headers)
end

#get_zone(uuid, headers = {}) ⇒ Response

Get a zone.

Examples:

response =
  client.get_zone("b19e8211-e492-425d-b66a-7642dc2ff8fb")

response.body #=>
  {"uuid"=>"b19e8211-e492-425d-b66a-7642dc2ff8fb",
   "name"=>"foobar.example.com",
   "default_ttl"=>600,
   "created_at"=>"2015-11-09T11:43:49+09:00",
   "updated_at"=>nil,
   "records"=>
    [{"uuid"=>"1f30afd1-9b5e-45df-b03e-d07779a90e1c",
      "name"=>"foobar.example.com",
      "type"=>"SOA",
      "content"=>
       {"dns"=>"ns01.idcfcloud.com",
        "email"=>"foobar.example.com.",
        "serial"=>2,
        "refresh"=>10800,
        "retry"=>3600,
        "expire"=>604800,
        "ttl"=>3600},
      "ttl"=>3600,
      "created_at"=>"2015-11-09T11:43:49+09:00",
      "updated_at"=>"2015-11-09T11:43:50+09:00",
      "priority"=>nil},
     {"uuid"=>"b5322649-625d-4b50-8cd3-7542f64912fa",
      "name"=>"foobar.example.com",
      "type"=>"NS",
      "content"=>"ns01.idcfcloud.com",
      "ttl"=>3600,
      "created_at"=>"2015-11-09T11:43:49+09:00",
      "updated_at"=>nil,
      "priority"=>nil},
     {"uuid"=>"1fb4d44c-160a-45cd-835c-eb47fe1edb27",
      "name"=>"foobar.example.com",
      "type"=>"NS",
      "content"=>"ns02.idcfcloud.com",
      "ttl"=>3600,
      "created_at"=>"2015-11-09T11:43:49+09:00",
      "updated_at"=>nil,
      "priority"=>nil},
     {"uuid"=>"765f8426-70b8-46c6-a45b-836c5dd57a7d",
      "name"=>"foobar.example.com",
      "type"=>"NS",
      "content"=>"ns03.idcfcloud.com",
      "ttl"=>3600,
      "created_at"=>"2015-11-09T11:43:49+09:00",
      "updated_at"=>nil,
      "priority"=>nil},
     {"uuid"=>"ea81d8c0-8c6d-47e7-bca7-33656888a293",
      "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}],
   "description"=>"",
   "authenticated"=>false}

Parameters:

  • uuid (String)

    UUID of target zone

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

    HTTP request headers

Returns:



160
161
162
# File 'lib/idcf/dns/client_extensions/zone.rb', line 160

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

#list_zones(headers = {}) ⇒ Response

Get list of existing zones

Examples:

response =
  client.list_zones

response.body #=>
  [{"uuid"=>"384178f5-58a5-4f3c-9607-5e189ab2990d",
    "name"=>"foobar.example.com",
    "default_ttl"=>600,
    "created_at"=>"2015-11-09T11:43:49+09:00",
    "updated_at"=>nil,
    "description"=>"",
    "authenticated"=>false}]

Parameters:

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

    HTTP request headers

Returns:



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

def list_zones(headers = {})
  get!("zones", {}, headers)
end

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

Update a zone.

Examples:

response =
  client.update_zone(
    "384178f5-58a5-4f3c-9607-5e189ab2990d",
    description: "Change description",
    default_ttl: 3600
  )

response.body #=>
  {"uuid"=>"384178f5-58a5-4f3c-9607-5e189ab2990d",
   "name"=>"foobar.example.com",
   "default_ttl"=>3600,
   "created_at"=>"2015-11-09T11:43:49+09:00",
   "updated_at"=>"2015-11-09T11:43:50+09:00",
   "records"=>
    [{"uuid"=>"6aba1170-83b9-4324-b331-8c2b8dcb5162",
      "name"=>"foobar.example.com",
      "type"=>"SOA",
      "content"=>
       {"dns"=>"ns01.idcfcloud.com",
        "email"=>"foobar.example.com.",
        "serial"=>2,
        "refresh"=>10800,
        "retry"=>3600,
        "expire"=>604800,
        "ttl"=>3600},
      "ttl"=>3600,
      "created_at"=>"2015-11-09T11:43:49+09:00",
      "updated_at"=>"2015-11-09T11:43:50+09:00",
      "priority"=>nil},
     {"uuid"=>"0b18679d-dd47-46fe-8812-d20c284001ac",
      "name"=>"foobar.example.com",
      "type"=>"NS",
      "content"=>"ns01.idcfcloud.com",
      "ttl"=>3600,
      "created_at"=>"2015-11-09T11:43:49+09:00",
      "updated_at"=>nil,
      "priority"=>nil},
     {"uuid"=>"a5a9ab9c-b19f-4411-880e-842ffd53027c",
      "name"=>"foobar.example.com",
      "type"=>"NS",
      "content"=>"ns02.idcfcloud.com",
      "ttl"=>3600,
      "created_at"=>"2015-11-09T11:43:49+09:00",
      "updated_at"=>nil,
      "priority"=>nil},
     {"uuid"=>"2756ed66-2b69-4ae2-8065-69ac2b12b71d",
      "name"=>"foobar.example.com",
      "type"=>"NS",
      "content"=>"ns03.idcfcloud.com",
      "ttl"=>3600,
      "created_at"=>"2015-11-09T11:43:49+09:00",
      "updated_at"=>nil,
      "priority"=>nil},
     {"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}],
   "description"=>"Change description",
   "authenticated"=>false}

Parameters:

  • uuid (String)

    UUID of target zone

  • attributes (Hash)

    request attributes

Options Hash (attributes):

  • :email (String)

    e-mail address

  • :description (String)

    description

  • :default_ttl (Integer)

    default TTL

Returns:



256
257
258
259
# File 'lib/idcf/dns/client_extensions/zone.rb', line 256

def update_zone(uuid, attributes, headers = {})
  Validators::Zone.validate_attributes!(attributes, :update)
  put!("zones/#{uuid}", attributes, headers)
end

#verify_zone(uuid, headers = {}) ⇒ Response

Verify a zone.

Examples:

response =
  client.verify_zone(
    "384178f5-58a5-4f3c-9607-5e189ab2990d"
  )

response.body #=>
  {}

Parameters:

  • uuid (String)

    UUID of target zone

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

    HTTP request headers

Returns:



297
298
299
# File 'lib/idcf/dns/client_extensions/zone.rb', line 297

def verify_zone(uuid, headers = {})
  post!("zones/#{uuid}/verify", {}, headers)
end

#zone(uuid, headers = {}) ⇒ Resources::Zone

Get a zone object.

Parameters:

  • uuid (String)

    UUID of target zone

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

    HTTP request headers

Returns:



306
307
308
# File 'lib/idcf/dns/client_extensions/zone.rb', line 306

def zone(uuid, headers = {})
  Resources::Zone.new(self, get_zone(uuid, headers).body)
end

#zones(headers = {}) ⇒ Array<Resources::Zone>

Get an array of existing zone objects.

Parameters:

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

    HTTP request headers

Returns:



314
315
316
317
318
# File 'lib/idcf/dns/client_extensions/zone.rb', line 314

def zones(headers = {})
  list_zones(headers).resources.map do |zone|
    Resources::Zone.new(self, zone)
  end
end