Class: Oceanarium::Record
- Inherits:
-
Object
- Object
- Oceanarium::Record
- Defined in:
- lib/oceanarium/resources/record.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#domain_id ⇒ Object
Returns the value of attribute domain_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#port ⇒ Object
Returns the value of attribute port.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#record_type ⇒ Object
Returns the value of attribute record_type.
-
#weight ⇒ Object
Returns the value of attribute weight.
Class Method Summary collapse
-
.all(domain_id) ⇒ Object
Core API.
- .create(domain_id, options = {}) ⇒ Object
- .destroy(domain_id, id) ⇒ Object
- .find(domain_id, id) ⇒ Object
- .update(id, domain_id, options = {}) ⇒ Object
Instance Method Summary collapse
- #destroy ⇒ Object
- #edit(options = {}) ⇒ Object
-
#initialize(option, api_key, config_id, domain_id = nil) ⇒ Record
constructor
A new instance of Record.
-
#new(options = {}) ⇒ Object
User API.
Constructor Details
#initialize(option, api_key, config_id, domain_id = nil) ⇒ Record
Returns a new instance of Record.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/oceanarium/resources/record.rb', line 5 def initialize(option, api_key, config_id, domain_id = nil) if api_key.nil? || config_id.nil? raise 'No API key/client ID!' else if option.is_a?(Hash) @object = option else @object = Oceanarium::Record.find(option, domain_id) end if @object.nil? self.id = nil else self.id = @object['id'] self.domain_id = @object['domain_id'] self.record_type = @object['record_type'] self.name = @object['name'] self.data = @object['data'] self.priority = @object['priority'] self.port = @object['port'] self.weight = @object['weight'] end end end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/oceanarium/resources/record.rb', line 3 def data @data end |
#domain_id ⇒ Object
Returns the value of attribute domain_id.
3 4 5 |
# File 'lib/oceanarium/resources/record.rb', line 3 def domain_id @domain_id end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/oceanarium/resources/record.rb', line 3 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/oceanarium/resources/record.rb', line 3 def name @name end |
#port ⇒ Object
Returns the value of attribute port.
3 4 5 |
# File 'lib/oceanarium/resources/record.rb', line 3 def port @port end |
#priority ⇒ Object
Returns the value of attribute priority.
3 4 5 |
# File 'lib/oceanarium/resources/record.rb', line 3 def priority @priority end |
#record_type ⇒ Object
Returns the value of attribute record_type.
3 4 5 |
# File 'lib/oceanarium/resources/record.rb', line 3 def record_type @record_type end |
#weight ⇒ Object
Returns the value of attribute weight.
3 4 5 |
# File 'lib/oceanarium/resources/record.rb', line 3 def weight @weight end |
Class Method Details
.all(domain_id) ⇒ Object
Core API
45 46 47 48 49 50 51 |
# File 'lib/oceanarium/resources/record.rb', line 45 def self.all(domain_id) @request = Oceanarium::Request.new @get = @request.get("/domains/#{domain_id}/records") if @get.parsed_response['status'] == 'OK' @get.parsed_response['records'] end end |
.create(domain_id, options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/oceanarium/resources/record.rb', line 61 def self.create(domain_id, ={}) # There is a gotcha: too many params, so we need to pass an Hash with all params. # For example: # # Oceanarium::Record.create(100500, {:record_type => 'A', :data => 'www.example.com', :name => 'example', :priority => 1, :port => 8342, :weight => 1 }) # # Looks a lot overbloated? Yes, I know it :( @request = Oceanarium::Request.new @get = @request.get("/domains/#{domain_id}/records/new", ) if @get.parsed_response['status'] == 'OK' @get.parsed_response['domain_record']['id'] else @get.parsed_response['status'] end end |
.destroy(domain_id, id) ⇒ Object
88 89 90 91 92 |
# File 'lib/oceanarium/resources/record.rb', line 88 def self.destroy(domain_id, id) @request = Oceanarium::Request.new @get = @request.get("/domains/#{domain_id}/records/#{id}/destroy") @get.parsed_response['status'] end |
.find(domain_id, id) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/oceanarium/resources/record.rb', line 53 def self.find(domain_id, id) @request = Oceanarium::Request.new @get = @request.get("/domains/#{domain_id}/records/#{id}/") if @get.parsed_response['status'] == 'OK' @get.parsed_response['record'] end end |
.update(id, domain_id, options = {}) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/oceanarium/resources/record.rb', line 77 def self.update(id, domain_id, ={}) # Same shit there @request = Oceanarium::Request.new @get = @request.get("/domains/#{domain_id}/records/#{id}/edit/", ) if @get.parsed_response['status'] == 'OK' @get.parsed_response['record'] else @get.parsed_response['status'] end end |
Instance Method Details
#destroy ⇒ Object
39 40 41 |
# File 'lib/oceanarium/resources/record.rb', line 39 def destroy Oceanarium::Record.destroy(self.domain_id, self.id) end |
#edit(options = {}) ⇒ Object
35 36 37 |
# File 'lib/oceanarium/resources/record.rb', line 35 def edit(={}) Oceanarium::Record.update(self.id, self.domain_id, ) end |
#new(options = {}) ⇒ Object
User API
31 32 33 |
# File 'lib/oceanarium/resources/record.rb', line 31 def new(={}) Oceanarium::Record.create(self.domain_id, ) end |