A Ruby client for IDCF Cloud DNS service.
Add this line to your application's Gemfile:
gem 'idcf-dns'
And then execute:
$ bundle
Or install it yourself as:
$ gem install idcf-dns
- Ruby 2.1.10 or higher
require "idcf/dns"
client =
Idcf::Dns::Client.new(
api_key: ENV["IDCF_API_KEY"],
secret_key: ENV["IDCF_SECRET_KEY"]
)
# Call GET request directly
# returns Response object
response = client.get("zones")
response.success? #=> true
response.status #=> 200
# Response#body returns HTTP response body as a hash or an array
response.body #=> [zone1, zone2, ...]
response.body[0] #=> zone1
# Response#[] is alias to Response#body[]
response[0] #=> zone1
response =
client.create_zone(
name: "foobar.example.com",
email: "[email protected]",
description: "description",
default_ttl: 600
)
response.uuid #=> UUID of new zone
# Get all zones
zones = client.list_zones.body
zones[0]["name"] #=> "foobar.example.com"
# Get a zone
zone = client.get_zone(zone_uuid).body
zone["name"] #=> "foobar.example.com"
zone["records"].size #=> 3
client.update_zone(zone_uuid, description: "Updated")
client.delete_zone(zone_uuid)
response =
client.create_record(
zone_uuid,
name: "baz.foobar.example.com",
type: "A",
content: "8.8.8.8",
ttl: 600
)
response.uuid #=> UUID of new record
# Get all records of a zone
records = client.list_records(zone_uuid).body
records[0]["name"] #=> "baz.foobar.example.com"
# Get a record
record = client.get_record(zone_uuid, record_uuid).body
record["name"] #=> "baz.foobar.example.com"
client.update_record(zone_uuid, record_uuid, content: "210.140.158.1")
client.delete_record(zone_uuid, record_uuid)
In default, requests will expire in 600 seconds. You can use custom expirations for each request.
expiration = Time.now.to_i + 10
client.list_zones("X-IDCF-Expires": expiration).success?
#=> true
# wait for 10 seconds ...
client.list_zones("X-IDCF-Expires": expiration)
#=> Idcf::Dns::ApiError: HTTP status code: 403, Error message: This api request is expired., Reference: http://docs.idcf.jp/cloud/dns
http://www.rubydoc.info/gems/idcf-dns
- Fork it ( https://github.com/idcf/idcf-dns-ruby/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request