Class: Oceanarium::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/oceanarium/resources/record.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/oceanarium/resources/record.rb', line 3

def data
  @data
end

#domain_idObject

Returns the value of attribute domain_id.



3
4
5
# File 'lib/oceanarium/resources/record.rb', line 3

def domain_id
  @domain_id
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/oceanarium/resources/record.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/oceanarium/resources/record.rb', line 3

def name
  @name
end

#portObject

Returns the value of attribute port.



3
4
5
# File 'lib/oceanarium/resources/record.rb', line 3

def port
  @port
end

#priorityObject

Returns the value of attribute priority.



3
4
5
# File 'lib/oceanarium/resources/record.rb', line 3

def priority
  @priority
end

#record_typeObject

Returns the value of attribute record_type.



3
4
5
# File 'lib/oceanarium/resources/record.rb', line 3

def record_type
  @record_type
end

#weightObject

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, options={})
  # 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", options)
  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, options={})
  # Same shit there
  @request = Oceanarium::Request.new
  @get = @request.get("/domains/#{domain_id}/records/#{id}/edit/", options)
  if @get.parsed_response['status'] == 'OK'
    @get.parsed_response['record']
  else
    @get.parsed_response['status']
  end
end

Instance Method Details

#destroyObject



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(options={})
  Oceanarium::Record.update(self.id, self.domain_id, options)
end

#new(options = {}) ⇒ Object

User API



31
32
33
# File 'lib/oceanarium/resources/record.rb', line 31

def new(options={})
  Oceanarium::Record.create(self.domain_id, options)
end