/
zones_records.rb
164 lines (152 loc) · 6.8 KB
/
zones_records.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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", page: 2)
#
# @example List records for the zone "example.com", provide sorting policy
# client.zones.records(1010, "example.com", sort: "type:asc")
#
# @example List records for the zone "example.com", provide filtering policy
# client.zones.records(1010, "example.com", sort: "type:asc")
#
# @param [Fixnum] account_id the account ID
# @param [String] zone_id the zone name
# @param [Hash] options the filtering and sorting options
# @option options [Integer] :page current page (pagination)
# @option options [Integer] :per_page number of entries to return (pagination)
# @option options [String] :sort sorting policy
# @option options [Hash] :filter filtering policy
# @return [Dnsimple::PaginatedResponse<Dnsimple::Struct::Record>]
#
# @raise [Dnsimple::NotFoundError]
# @raise [Dnsimple::RequestError]
def records(account_id, zone_id, options = {})
response = client.get(Client.versioned("/%s/zones/%s/records" % [account_id, zone_id]), Options::ListOptions.new(options))
Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Record.new(r) })
end
alias list records
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
#
# @example List all records for the zone "example.com"
# client.zones.all_records(1010, "example.com")
#
# @param [Fixnum] account_id the account ID
# @param [String] zone_id the zone name
# @param [Hash] options the filtering and sorting options
# @option options [Integer] :page current page (pagination)
# @option options [Integer] :per_page number of entries to return (pagination)
# @option options [String] :sort sorting policy
# @option options [Hash] :filter filtering policy
# @return [Dnsimple::CollectionResponse<Dnsimple::Struct::Record>]
#
# @raise [Dnsimple::NotFoundError]
# @raise [Dnsimple::RequestError]
def all_records(account_id, zone_id, options = {})
paginate(:records, account_id, zone_id, options)
end
alias all all_records
# Creates a zone record in the account.
#
# @see https://developer.dnsimple.com/v2/zones/records/#create
#
# @example Create a URL record in zone "example.com"
# client.zones.create_record(1010, "example.com", name: "www", type: "url", content: "example.com")
#
# @param [Fixnum] account_id the account ID
# @param [String] zone_id the zone name
# @param [Hash] attributes
# @param [Hash] options
# @return [Dnsimple::Response<Dnsimple::Struct::Record>]
#
# @raise [Dnsimple::NotFoundError]
# @raise [Dnsimple::RequestError]
def create_record(account_id, zone_id, attributes, options = {})
Extra.validate_mandatory_attributes(attributes, [:type, :name, :content])
response = client.post(Client.versioned("/%s/zones/%s/records" % [account_id, zone_id]), attributes, options)
Dnsimple::Response.new(response, Struct::Record.new(response["data"]))
end
alias create create_record
# Gets a zone record from the account.
#
# @see https://developer.dnsimple.com/v2/zones/records/#get
#
# @example Get record 123 in zone "example.com"
# client.zones.record(1010, "example.com", 123)
#
# @param [Fixnum] account_id the account ID
# @param [String] zone_id the zone name
# @param [Fixnum] record_id the record ID
# @param [Hash] options
# @return [Dnsimple::Response<Dnsimple::Struct::Record>]
#
# @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
#
# @example Update the TTL to 600 of record 123 in zone "example.com"
# client.zones.update_record(1010, "example.com", 123, ttl: 600)
#
# @param [Fixnum] account_id the account ID
# @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 = {})
response = client.patch(Client.versioned("/%s/zones/%s/records/%s" % [account_id, zone_id, record_id]), attributes, options)
Dnsimple::Response.new(response, Struct::Record.new(response["data"]))
end
alias update update_record
# Deletes a zone record from the account.
#
# WARNING: this cannot be undone.
#
# @see https://developer.dnsimple.com/v2/zones/records/#delete
#
# @example Delete record 123 in zone "example.com"
# client.zones.delete_record(1010, "example.com", 123)
#
# @param [Fixnum] account_id the account ID
# @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]), nil, options)
Dnsimple::Response.new(response, nil)
end
alias delete delete_record
end
end
end