Class: Dennis::Group
- Inherits:
-
Object
- Object
- Dennis::Group
- Defined in:
- lib/dennis/group.rb
Class Method Summary collapse
- .all(client, page: nil, per_page: nil) ⇒ Object
- .create(client, name:, external_reference: nil) ⇒ Object
- .find_by(client, field, value) ⇒ Object
Instance Method Summary collapse
- #create_or_update_zone(**properties) ⇒ Object
- #create_zone(**properties) ⇒ Object
- #created_at ⇒ Object
- #delete ⇒ Object
- #external_reference ⇒ Object
- #id ⇒ Object
-
#initialize(client, hash) ⇒ Group
constructor
A new instance of Group.
- #name ⇒ Object
- #nameservers ⇒ Object
- #tagged_records(tags) ⇒ Object
- #update(properties) ⇒ Object
- #updated_at ⇒ Object
- #zone(id, field: :id) ⇒ Object
- #zones(**options) ⇒ Object
Constructor Details
#initialize(client, hash) ⇒ Group
Returns a new instance of Group.
40 41 42 43 |
# File 'lib/dennis/group.rb', line 40 def initialize(client, hash) @client = client @hash = hash end |
Class Method Details
.all(client, page: nil, per_page: nil) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/dennis/group.rb', line 11 def all(client, page: nil, per_page: nil) request = client.api.create_request(:get, 'groups') request.arguments[:page] = page if page request.arguments[:per_page] = per_page if per_page PaginatedArray.create(request.perform.hash, 'groups') do |hash| new(client, hash) end end |
.create(client, name:, external_reference: nil) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/dennis/group.rb', line 28 def create(client, name:, external_reference: nil) request = client.api.create_request(:post, 'groups') request.arguments[:properties] = { name: name, external_reference: external_reference } Group.new(client, request.perform.hash['group']) rescue ApiaClient::RequestError => e raise ValidationError, e.detail['errors'] if e.code == 'validation_error' raise end |
.find_by(client, field, value) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/dennis/group.rb', line 20 def find_by(client, field, value) request = client.api.create_request(:get, 'groups/:group') request.arguments[:group] = { field => value } Group.new(client, request.perform.hash['group']) rescue ApiaClient::RequestError => e e.code == 'group_not_found' ? nil : raise end |
Instance Method Details
#create_or_update_zone(**properties) ⇒ Object
81 82 83 |
# File 'lib/dennis/group.rb', line 81 def create_or_update_zone(**properties) Zone.create_or_update(@client, group: { id: id }, **properties) end |
#create_zone(**properties) ⇒ Object
77 78 79 |
# File 'lib/dennis/group.rb', line 77 def create_zone(**properties) Zone.create(@client, group: { id: id }, **properties) end |
#created_at ⇒ Object
57 58 59 60 61 62 |
# File 'lib/dennis/group.rb', line 57 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 |
#delete ⇒ Object
113 114 115 116 117 118 |
# File 'lib/dennis/group.rb', line 113 def delete req = @client.api.create_request(:delete, 'groups/:group') req.arguments['group'] = { id: id } req.perform true end |
#external_reference ⇒ Object
53 54 55 |
# File 'lib/dennis/group.rb', line 53 def external_reference @hash['external_reference'] end |
#id ⇒ Object
45 46 47 |
# File 'lib/dennis/group.rb', line 45 def id @hash['id'] end |
#name ⇒ Object
49 50 51 |
# File 'lib/dennis/group.rb', line 49 def name @hash['name'] end |
#nameservers ⇒ Object
71 72 73 74 75 |
# File 'lib/dennis/group.rb', line 71 def nameservers @nameservers ||= @hash['nameservers'].map do |hash| Nameserver.new(@client, hash) end end |
#tagged_records(tags) ⇒ Object
97 98 99 |
# File 'lib/dennis/group.rb', line 97 def tagged_records() Record.all_by_tag(@client, , group: { id: id }) end |
#update(properties) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/dennis/group.rb', line 101 def update(properties) req = @client.api.create_request(:patch, 'groups/:group') req.arguments['group'] = { id: id } req.arguments['properties'] = properties @hash = req.perform.hash['group'] true rescue ApiaClient::RequestError => e raise ValidationError, e.detail['errors'] if e.code == 'validation_error' raise end |
#updated_at ⇒ Object
64 65 66 67 68 69 |
# File 'lib/dennis/group.rb', line 64 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 |
#zone(id, field: :id) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/dennis/group.rb', line 89 def zone(id, field: :id) zone = Zone.find_by(@client, field, id) return nil if zone.nil? return nil if zone.group.id != self.id zone end |
#zones(**options) ⇒ Object
85 86 87 |
# File 'lib/dennis/group.rb', line 85 def zones(**) Zone.all_for_group(@client, { id: id }, **) end |