Class: Dennis::Zone
- Inherits:
-
Object
- Object
- Dennis::Zone
- Defined in:
- lib/dennis/zone.rb
Class Method Summary collapse
- .all(client, query: nil, view: nil, tags: nil, page: nil, per_page: nil) ⇒ Object
- .all_for_group(client, group, query: nil, view: nil, tags: nil, page: nil, per_page: nil) ⇒ Object
- .create(client, group:, allow_sub_domains_of_zones_in_other_groups: nil, **properties) ⇒ Object
- .create_or_update(client, group:, **properties) ⇒ Object
- .find_by(client, field, value) ⇒ Object
Instance Method Summary collapse
- #always_verified? ⇒ Boolean
- #create_or_update_record(**properties) ⇒ Object
- #create_record(**properties) ⇒ Object
- #created_at ⇒ Object
- #default_ttl ⇒ Object
- #delete ⇒ Object
- #external_reference ⇒ Object
- #group ⇒ Object
- #id ⇒ Object
-
#initialize(client, hash) ⇒ Zone
constructor
A new instance of Zone.
- #name ⇒ Object
- #nameservers_checked_at ⇒ Object
- #nameservers_verified? ⇒ Boolean
- #nameservers_verified_at ⇒ Object
- #record(value, field: :id) ⇒ Object
- #records(**options) ⇒ Object
- #reverse_dns? ⇒ Boolean
- #stale_verification? ⇒ Boolean
- #tags ⇒ Object
- #txt_record_verification_token ⇒ Object
- #txt_record_verified? ⇒ Boolean
- #update(properties) ⇒ Object
- #updated_at ⇒ Object
- #verified? ⇒ Boolean
- #verified_at ⇒ Object
- #verify ⇒ Object
- #verify_nameservers ⇒ Object
Constructor Details
#initialize(client, hash) ⇒ Zone
Returns a new instance of Zone.
80 81 82 83 |
# File 'lib/dennis/zone.rb', line 80 def initialize(client, hash) @client = client @hash = hash end |
Class Method Details
.all(client, query: nil, view: nil, tags: nil, page: nil, per_page: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dennis/zone.rb', line 13 def all(client, query: nil, view: nil, tags: nil, page: nil, per_page: nil) request = client.api.create_request(:get, 'zones') request.arguments[:query] = query if query request.arguments[:view] = view if view request.arguments[:tags] = if request.arguments[:page] = page if page request.arguments[:per_page] = per_page if per_page PaginatedArray.create(request.perform.hash, 'zones') do |hash| new(client, hash) end end |
.all_for_group(client, group, query: nil, view: nil, tags: nil, page: nil, per_page: nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dennis/zone.rb', line 25 def all_for_group(client, group, query: nil, view: nil, tags: nil, page: nil, per_page: nil) request = client.api.create_request(:get, 'groups/:group/zones') request.arguments[:group] = group request.arguments[:query] = query if query request.arguments[:view] = view if view request.arguments[:tags] = if request.arguments[:page] = page if page request.arguments[:per_page] = per_page if per_page PaginatedArray.create(request.perform.hash, 'zones') do |hash| new(client, hash) end end |
.create(client, group:, allow_sub_domains_of_zones_in_other_groups: nil, **properties) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/dennis/zone.rb', line 46 def create(client, group:, allow_sub_domains_of_zones_in_other_groups: nil, **properties) request = client.api.create_request(:post, 'zones') request.arguments[:group] = group request.arguments[:properties] = properties unless allow_sub_domains_of_zones_in_other_groups.nil? request.arguments[:allow_sub_domains_of_zones_in_other_groups] = allow_sub_domains_of_zones_in_other_groups end new(client, request.perform.hash['zone']) rescue ApiaClient::RequestError => e raise GroupNotFoundError if e.code == 'group_not_found' raise ValidationError, e.detail['errors'] if e.code == 'validation_error' raise end |
.create_or_update(client, group:, **properties) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/dennis/zone.rb', line 64 def create_or_update(client, group:, **properties) if properties[:external_reference].nil? raise Dennis::ExternalReferenceRequiredError, 'An external_reference must be provided to use create_or_update' end zone = find_by(client, :external_reference, properties[:external_reference]) if zone.nil? create(client, group: group, **properties) else zone.update(properties) zone end end |
.find_by(client, field, value) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/dennis/zone.rb', line 38 def find_by(client, field, value) request = client.api.create_request(:get, 'zones/:zone') request.arguments[:zone] = { field => value } new(client, request.perform.hash['zone']) rescue ApiaClient::RequestError => e e.code == 'zone_not_found' ? nil : raise end |
Instance Method Details
#always_verified? ⇒ Boolean
121 122 123 |
# File 'lib/dennis/zone.rb', line 121 def always_verified? @hash['always_verified'] end |
#create_or_update_record(**properties) ⇒ Object
170 171 172 |
# File 'lib/dennis/zone.rb', line 170 def create_or_update_record(**properties) Record.create_or_update(@client, id, **properties) end |
#create_record(**properties) ⇒ Object
166 167 168 |
# File 'lib/dennis/zone.rb', line 166 def create_record(**properties) Record.create(@client, zone: { id: id }, **properties) end |
#created_at ⇒ Object
152 153 154 155 156 157 |
# File 'lib/dennis/zone.rb', line 152 def created_at return nil if @hash['created_at'].nil? return @hash['created_at'] if @hash['created_at'].is_a?(Time) Time.at(@hash['created_at']) end |
#default_ttl ⇒ Object
137 138 139 |
# File 'lib/dennis/zone.rb', line 137 def default_ttl @hash['default_ttl'] end |
#delete ⇒ Object
198 199 200 201 202 203 |
# File 'lib/dennis/zone.rb', line 198 def delete req = @client.api.create_request(:delete, 'zones/:zone') req.arguments['zone'] = { id: id } req.perform true end |
#external_reference ⇒ Object
93 94 95 |
# File 'lib/dennis/zone.rb', line 93 def external_reference @hash['external_reference'] end |
#group ⇒ Object
145 146 147 148 149 150 |
# File 'lib/dennis/zone.rb', line 145 def group return @group if @group return nil unless @hash['group'] @group = Group.new(@client, @hash['group']) end |
#id ⇒ Object
85 86 87 |
# File 'lib/dennis/zone.rb', line 85 def id @hash['id'] end |
#name ⇒ Object
89 90 91 |
# File 'lib/dennis/zone.rb', line 89 def name @hash['name'] end |
#nameservers_checked_at ⇒ Object
105 106 107 |
# File 'lib/dennis/zone.rb', line 105 def nameservers_checked_at parse_time(@hash['nameservers_checked_at']) end |
#nameservers_verified? ⇒ Boolean
109 110 111 |
# File 'lib/dennis/zone.rb', line 109 def nameservers_verified? @hash['nameservers_verified'] end |
#nameservers_verified_at ⇒ Object
101 102 103 |
# File 'lib/dennis/zone.rb', line 101 def nameservers_verified_at parse_time(@hash['nameservers_verified_at']) end |
#record(value, field: :id) ⇒ Object
178 179 180 181 182 183 184 |
# File 'lib/dennis/zone.rb', line 178 def record(value, field: :id) record = Record.find_by(@client, field, value) return nil if record.nil? return nil if record.zone.id != id record end |
#records(**options) ⇒ Object
174 175 176 |
# File 'lib/dennis/zone.rb', line 174 def records(**) Record.all(@client, { id: id }, **) end |
#reverse_dns? ⇒ Boolean
129 130 131 |
# File 'lib/dennis/zone.rb', line 129 def reverse_dns? @hash['reverse_dns'] end |
#stale_verification? ⇒ Boolean
133 134 135 |
# File 'lib/dennis/zone.rb', line 133 def stale_verification? @hash['stale_verification'] end |
#tags ⇒ Object
141 142 143 |
# File 'lib/dennis/zone.rb', line 141 def @hash['tags'] end |
#txt_record_verification_token ⇒ Object
97 98 99 |
# File 'lib/dennis/zone.rb', line 97 def txt_record_verification_token @hash['txt_record_verification_token'] end |
#txt_record_verified? ⇒ Boolean
113 114 115 |
# File 'lib/dennis/zone.rb', line 113 def txt_record_verified? @hash['txt_record_verified'] end |
#update(properties) ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/dennis/zone.rb', line 186 def update(properties) req = @client.api.create_request(:patch, 'zones/:zone') req.arguments['zone'] = { id: id } req.arguments['properties'] = properties @hash = req.perform.hash['zone'] true rescue ApiaClient::RequestError => e raise ValidationError, e.detail['errors'] if e.code == 'validation_error' raise end |
#updated_at ⇒ Object
159 160 161 162 163 164 |
# File 'lib/dennis/zone.rb', line 159 def updated_at return nil if @hash['updated_at'].nil? return @hash['updated_at'] if @hash['updated_at'].is_a?(Time) Time.at(@hash['updated_at']) end |
#verified? ⇒ Boolean
117 118 119 |
# File 'lib/dennis/zone.rb', line 117 def verified? @hash['verified'] end |
#verified_at ⇒ Object
125 126 127 |
# File 'lib/dennis/zone.rb', line 125 def verified_at @hash['verified_at'] end |
#verify ⇒ Object
216 217 218 219 220 221 222 223 224 225 |
# File 'lib/dennis/zone.rb', line 216 def verify req = @client.api.create_request(:post, 'zones/:zone/verify') req.arguments['zone'] = { id: id } @hash = req.perform.hash['zone'] verified? rescue ApiaClient::RequestError => e raise unless e.code == 'zone_already_verified' true end |
#verify_nameservers ⇒ Object
205 206 207 208 209 210 211 212 213 214 |
# File 'lib/dennis/zone.rb', line 205 def verify_nameservers req = @client.api.create_request(:post, 'zones/:zone/verify_nameservers') req.arguments['zone'] = { id: id } @hash = req.perform.hash['zone'] verified? rescue ApiaClient::RequestError => e raise unless e.code == 'nameservers_already_verified' true end |