-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from aetrion/domain-records
API v2 Zone > Records methods
- Loading branch information
Showing
16 changed files
with
606 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
module Dnsimple | ||
class Client | ||
module ZonesRecords | ||
|
||
# Lists the zone records in the account. | ||
# | ||
# @see https://developer.dnsimple.com/v2/zones/records/#list | ||
# @see #all_records | ||
# | ||
# @example List records for the zone "example.com" in the first page | ||
# client.zones.records(1010, "example.com") | ||
# | ||
# @example List records for the zone "example.com", provide a specific page | ||
# client.zones.records(1010, "example.com", query: { page: 2 }) | ||
# | ||
# @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard | ||
# @param [String] zone_id the zone name | ||
# @param [Hash] options the filtering and sorting option | ||
# @return [Dnsimple::PaginatedResponse<Dnsimple::Struct::Record>] | ||
# | ||
# @raise [Dnsimple::RequestError] | ||
def records(account_id, zone_id, options = {}) | ||
response = client.get(Client.versioned("/%s/zones/%s/records" % [account_id, zone_id]), options) | ||
|
||
Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Record.new(r) }) | ||
end | ||
alias :list_records :records | ||
|
||
# Lists ALL the zone records in the account. | ||
# | ||
# This method is similar to {#records}, 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. | ||
# | ||
# @see https://developer.dnsimple.com/v2/zones/records/#list | ||
# @see #records | ||
# | ||
# @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard | ||
# @param [String] zone_id the zone name | ||
# @param [Hash] options the filtering and sorting option | ||
# @return [Dnsimple::CollectionResponse<Dnsimple::Struct::Record>] | ||
# | ||
# @raise [Dnsimple::RequestError] | ||
def all_records(account_id, zone_id, options = {}) | ||
paginate(:records, account_id, zone_id, options) | ||
end | ||
|
||
# Creates a zone record in the account. | ||
# | ||
# @see https://developer.dnsimple.com/v2/zones/records/#create | ||
# | ||
# @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard | ||
# @param [String] zone_id the zone name | ||
# @param [Hash] attributes | ||
# @param [Hash] options | ||
# @return [Dnsimple::Response<Dnsimple::Struct::Record>] | ||
# | ||
# @raise [Dnsimple::RequestError] | ||
def create_record(account_id, zone_id, attributes = {}, options = {}) | ||
Extra.validate_mandatory_attributes(attributes, [:record_type, :name, :content]) | ||
options = options.merge(attributes) | ||
response = client.post(Client.versioned("/%s/zones/%s/records" % [account_id, zone_id]), options) | ||
|
||
Dnsimple::Response.new(response, Struct::Record.new(response["data"])) | ||
end | ||
|
||
# Gets a zone record from the account. | ||
# | ||
# @see https://developer.dnsimple.com/v2/zones/records/#get | ||
# | ||
# @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard | ||
# @param [String] zone_id the zone name | ||
# @param [Fixnum] record_id the record ID | ||
# @param [Hash] options | ||
# @return [Dnsimple::Response<Dnsimple::Struct::Domain>] | ||
# | ||
# @raise [Dnsimple::NotFoundError] | ||
# @raise [Dnsimple::RequestError] | ||
def record(account_id, zone_id, record_id, options = {}) | ||
response = client.get(Client.versioned("/%s/zones/%s/records/%s" % [account_id, zone_id, record_id]), options) | ||
|
||
Dnsimple::Response.new(response, Struct::Record.new(response["data"])) | ||
end | ||
|
||
# Updates a zone record in the account. | ||
# | ||
# @see https://developer.dnsimple.com/v2/zones/records/#update | ||
# | ||
# @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard | ||
# @param [String] zone_id the zone name | ||
# @param [Fixnum] record_id the record ID | ||
# @param [Hash] attributes | ||
# @param [Hash] options | ||
# @return [Dnsimple::Response<Dnsimple::Struct::Record>] | ||
# | ||
# @raise [Dnsimple::NotFoundError] | ||
# @raise [Dnsimple::RequestError] | ||
def update_record(account_id, zone_id, record_id, attributes = {}, options = {}) | ||
options = options.merge(attributes) | ||
response = client.patch(Client.versioned("/%s/zones/%s/records/%s" % [account_id, zone_id, record_id]), options) | ||
|
||
Dnsimple::Response.new(response, Struct::Record.new(response["data"])) | ||
end | ||
|
||
# Deletes a zone record from the account. | ||
# | ||
# WARNING: this cannot be undone. | ||
# | ||
# @see https://developer.dnsimple.com/v2/zones/records/#delete | ||
# | ||
# @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard | ||
# @param [String] zone_id the zone name | ||
# @param [Fixnum] record_id the record ID | ||
# @param [Hash] options | ||
# @return [Dnsimple::Response<nil>] | ||
# | ||
# @raise [Dnsimple::NotFoundError] | ||
# @raise [Dnsimple::RequestError] | ||
def delete_record(account_id, zone_id, record_id, options = {}) | ||
response = client.delete(Client.versioned("/%s/zones/%s/records/%s" % [account_id, zone_id, record_id]), options) | ||
|
||
Dnsimple::Response.new(response, nil) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module Dnsimple | ||
module Struct | ||
|
||
class Record < Base | ||
# @return [Fixnum] The record ID in DNSimple. | ||
attr_accessor :id | ||
|
||
# @return [Fixnum] The associated domain ID. | ||
attr_accessor :domain_id | ||
|
||
# @return [Fixnum] The ID of the parent record, if this record is dependent on another record. | ||
attr_accessor :parent_id | ||
|
||
# @return [String] The type of record, in uppercase. | ||
attr_accessor :type | ||
|
||
# @return [String] The record name (without the domain name). | ||
attr_accessor :name | ||
|
||
# @return [String] The plain-text record content. | ||
attr_accessor :content | ||
|
||
# @return [Fixnum] The TTL value. | ||
attr_accessor :ttl | ||
|
||
# @return [Fixnum] The priority value, if the type of record accepts a priority. | ||
attr_accessor :priority | ||
|
||
# @return [Bool] True if this is a system record created by DNSimple. System records are read-only. | ||
attr_accessor :system_record | ||
|
||
# @return [String] When the domain was created in DNSimple. | ||
attr_accessor :created_at | ||
|
||
# @return [String] When the domain was last updated in DNSimple. | ||
attr_accessor :updated_at | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.