Class: DNSApp::Record
Instance Attribute Summary collapse
-
#content ⇒ Object
content for the record.
-
#created_at ⇒ Object
When the record was created.
-
#domain_id ⇒ Object
domain_id for the record.
-
#id ⇒ Object
id for the record.
-
#name ⇒ Object
name for the record.
-
#prio ⇒ Object
priority for the record.
-
#ttl ⇒ Object
time-to-live for the record.
-
#type ⇒ Object
type for the record Must be one of the following A AAAA NS SOA CNAME TXT SPF SRV MX PTR.
-
#updated_at ⇒ Object
When the record was last updated.
Class Method Summary collapse
-
.all ⇒ Object
Get all the records.
-
.create(options = {}) ⇒ Object
Creates a new record.
-
.find(id) ⇒ Object
Find a specific record by
id
== Example DNSApp::Domain.all.first.find(243) => #<DNSApp::Record:0x101ad5e88 @name=“%d”, @domain_id=131, @ttl=3600, @created_at=Mon Jan 10 15:48:02 UTC 2011, @content=“1.2.3.4”, @type=“A”, @id=1821, @prio=nil, @updated_at=Mon Jan 10 15:55:29 UTC 2011>.
Instance Method Summary collapse
-
#destroy ⇒ Object
(also: #delete)
Deletes the record.
-
#save ⇒ Object
Saves the record.
Methods inherited from Object
check_required_keys, delete, get, #initialize, #parent_id, #parent_id=, post, put
Constructor Details
This class inherits a constructor from DNSApp::Object
Instance Attribute Details
#content ⇒ Object
content for the record
20 21 22 |
# File 'lib/dnsapp/record.rb', line 20 def content @content end |
#created_at ⇒ Object
When the record was created
12 13 14 |
# File 'lib/dnsapp/record.rb', line 12 def created_at @created_at end |
#domain_id ⇒ Object
domain_id for the record
18 19 20 |
# File 'lib/dnsapp/record.rb', line 18 def domain_id @domain_id end |
#name ⇒ Object
name for the record
10 11 12 |
# File 'lib/dnsapp/record.rb', line 10 def name @name end |
#prio ⇒ Object
priority for the record. Only needed for MX and SRV records.
23 24 25 |
# File 'lib/dnsapp/record.rb', line 23 def prio @prio end |
#ttl ⇒ Object
time-to-live for the record
16 17 18 |
# File 'lib/dnsapp/record.rb', line 16 def ttl @ttl end |
#type ⇒ Object
type for the record Must be one of the following A AAAA NS SOA CNAME TXT SPF SRV MX PTR
26 27 28 |
# File 'lib/dnsapp/record.rb', line 26 def type @type end |
#updated_at ⇒ Object
When the record was last updated
14 15 16 |
# File 'lib/dnsapp/record.rb', line 14 def updated_at @updated_at end |
Class Method Details
.all ⇒ Object
Get all the records
31 32 33 34 |
# File 'lib/dnsapp/record.rb', line 31 def all response = get("/domains/#{@@parent_id}/records")["records"] response.collect { |attributes| Record.new attributes } end |
.create(options = {}) ⇒ Object
Creates a new record. options
must contain at least the following: :name, :content, :type, :tll For SRV and MX records :prio can also be specified.
Valid types
A AAAA NS SOA CNAME TXT SPF SRV MX PTR
Example
DNSApp::Domain.all.first.records.create :name => '%d', :content => '1.2.3.4', :type => 'A', :ttl => 3600
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dnsapp/record.rb', line 53 def create(={}) check_required_keys , :name, :content, :type, :ttl r = post("/domains/#{@@parent_id}/records", :query => { "record[name]" => [:name], "record[ttl]" => [:ttl], "record[content]" => [:content], "record[prio]" => [:prio], "record[type]" => [:type] }) r["errors"] and raise StandardError, r["errors"]["error"].to_a.join(", ") if r.code == 201 Record.new r["record"] else raise StandardError, 'Could not create the record' end end |
.find(id) ⇒ Object
Find a specific record by id
Example
DNSApp::Domain.all.first.find(243)
=> #<DNSApp::Record:0x101ad5e88 @name="%d", @domain_id=131, @ttl=3600, @created_at=Mon Jan 10 15:48:02 UTC 2011, @content="1.2.3.4", @type="A", @id=1821, @prio=nil, @updated_at=Mon Jan 10 15:55:29 UTC 2011>
40 41 42 43 44 |
# File 'lib/dnsapp/record.rb', line 40 def find(id) response = get("/domains/#{@@parent_id}/records/#{id}")["record"] response or return nil Record.new response end |
Instance Method Details
#destroy ⇒ Object Also known as: delete
Deletes the record. Returns the deleted record.
Example
r = DNSApp::Domain.all.first.record.first.destroy
=> #<DNSApp::Record:0x101ad5e88 @name="%d", @domain_id=131, @ttl=3600, @created_at=Mon Jan 10 15:48:02 UTC 2011, @content="1.2.3.4", @type="A", @id=1821, @prio=nil, @updated_at=Mon Jan 10 15:55:29 UTC 2011>
96 97 98 99 100 101 102 103 |
# File 'lib/dnsapp/record.rb', line 96 def destroy r = self.class.delete("/domains/#{@@parent_id}/records/#{self.id}") if r.code == 200 self else raise StandardError, 'Could not delete the record' end end |
#save ⇒ Object
Saves the record.
Example
r = DNSApp::Domain.all.first.record.first
=> #<DNSApp::Record:0x101ad5e88 @name="%d", @domain_id=131, @ttl=3600, @created_at=Mon Jan 10 15:48:02 UTC 2011, @content="1.2.3.4", @type="A", @id=1821, @prio=nil, @updated_at=Mon Jan 10 15:55:29 UTC 2011>
r.content = '9.9.9.9'
=> #<DNSApp::Record:0x101ad5e88 @name="%d", @domain_id=131, @ttl=3600, @created_at=Mon Jan 10 15:48:02 UTC 2011, @content="9.9.9.9", @type="A", @id=1821, @prio=nil, @updated_at=Mon Jan 10 17:52:09 UTC 2011>
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/dnsapp/record.rb', line 77 def save r = self.class.put("/domains/#{@@parent_id}/records/#{self.id}", :query => { "record[name]" => self.name, "record[ttl]" => self.ttl, "record[content]" => self.content, "record[prio]" => self.prio, "record[type]" => self.type }) r["errors"] and raise StandardError, r["errors"]["error"].to_a.join(", ") if r.code == 200 self.class.find(self.id) else raise StandardError, 'Could not update the record' end end |