Class: Dennis::Nameserver
- Inherits:
-
Object
- Object
- Dennis::Nameserver
- Defined in:
- lib/dennis/nameserver.rb
Class Method Summary collapse
- .all(client) ⇒ Object
- .create(client, name:, server: nil) ⇒ Object
- .find_by(client, field, value) ⇒ Object
Instance Method Summary collapse
- #created_at ⇒ Object
- #delete ⇒ Object
- #id ⇒ Object
-
#initialize(client, hash) ⇒ Nameserver
constructor
A new instance of Nameserver.
- #name ⇒ Object
- #server ⇒ Object
- #update(properties) ⇒ Object
- #updated_at ⇒ Object
Constructor Details
#initialize(client, hash) ⇒ Nameserver
Returns a new instance of Nameserver.
33 34 35 36 |
# File 'lib/dennis/nameserver.rb', line 33 def initialize(client, hash) @client = client @hash = hash end |
Class Method Details
.all(client) ⇒ Object
8 9 10 11 |
# File 'lib/dennis/nameserver.rb', line 8 def all(client) nameservers = client.api.perform(:get, 'nameservers') nameservers.hash['nameservers'].map { |hash| new(client, hash) } end |
.create(client, name:, server: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/dennis/nameserver.rb', line 21 def create(client, name:, server: nil) request = client.api.create_request(:post, 'nameservers') request.arguments[:properties] = { name: name, server: server } new(client, request.perform.hash['nameserver']) rescue ApiaClient::RequestError => e raise ValidationError, e.detail['errors'] if e.code == 'validation_error' raise end |
.find_by(client, field, value) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/dennis/nameserver.rb', line 13 def find_by(client, field, value) request = client.api.create_request(:get, 'nameservers/:nameserver') request.arguments[:nameserver] = { field => value } new(client, request.perform.hash['nameserver']) rescue ApiaClient::RequestError => e e.code == 'nameserver_not_found' ? nil : raise end |
Instance Method Details
#created_at ⇒ Object
50 51 52 53 54 55 |
# File 'lib/dennis/nameserver.rb', line 50 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
76 77 78 79 80 81 |
# File 'lib/dennis/nameserver.rb', line 76 def delete req = @client.api.create_request(:delete, 'nameservers/:nameserver') req.arguments['nameserver'] = { id: id } req.perform true end |
#id ⇒ Object
38 39 40 |
# File 'lib/dennis/nameserver.rb', line 38 def id @hash['id'] end |
#name ⇒ Object
42 43 44 |
# File 'lib/dennis/nameserver.rb', line 42 def name @hash['name'] end |
#server ⇒ Object
46 47 48 |
# File 'lib/dennis/nameserver.rb', line 46 def server @hash['server'] end |
#update(properties) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/dennis/nameserver.rb', line 64 def update(properties) req = @client.api.create_request(:patch, 'nameservers/:nameserver') req.arguments['nameserver'] = { id: id } req.arguments['properties'] = properties @hash = req.perform.hash['nameserver'] true rescue ApiaClient::RequestError => e raise ValidationError, e.detail['errors'] if e.code == 'validation_error' raise end |
#updated_at ⇒ Object
57 58 59 60 61 62 |
# File 'lib/dennis/nameserver.rb', line 57 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 |