Class: Porkbun::DNS
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#prio ⇒ Object
Returns the value of attribute prio.
-
#ttl ⇒ Object
Returns the value of attribute ttl.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from Abstract
Class Method Summary collapse
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
- #edit ⇒ Object
-
#initialize(options) ⇒ DNS
constructor
A new instance of DNS.
- #save ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Methods inherited from Abstract
Constructor Details
#initialize(options) ⇒ DNS
Returns a new instance of DNS.
47 48 49 50 51 52 53 54 55 |
# File 'lib/porkbun.rb', line 47 def initialize() @name = [:name] @content = [:content] @type = [:type] @ttl = [:ttl] || 600 @prio = [:prio] @domain = [:domain] @id = [:id] end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
45 46 47 |
# File 'lib/porkbun.rb', line 45 def content @content end |
#domain ⇒ Object
Returns the value of attribute domain.
45 46 47 |
# File 'lib/porkbun.rb', line 45 def domain @domain end |
#id ⇒ Object
Returns the value of attribute id.
45 46 47 |
# File 'lib/porkbun.rb', line 45 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
45 46 47 |
# File 'lib/porkbun.rb', line 45 def name @name end |
#notes ⇒ Object
Returns the value of attribute notes.
45 46 47 |
# File 'lib/porkbun.rb', line 45 def notes @notes end |
#prio ⇒ Object
Returns the value of attribute prio.
45 46 47 |
# File 'lib/porkbun.rb', line 45 def prio @prio end |
#ttl ⇒ Object
Returns the value of attribute ttl.
45 46 47 |
# File 'lib/porkbun.rb', line 45 def ttl @ttl end |
#type ⇒ Object
Returns the value of attribute type.
45 46 47 |
# File 'lib/porkbun.rb', line 45 def type @type end |
Class Method Details
.create(options) ⇒ Object
57 58 59 60 |
# File 'lib/porkbun.rb', line 57 def self.create() record = DNS.new record.create end |
.retrieve(domain, id = nil) ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/porkbun.rb', line 75 def self.retrieve(domain, id = nil) raise Error, 'need domain' unless domain res = Porkbun.porkbun File.join('dns/retrieve', domain, id || '').chomp('/') return Error.new(res[:message]) if res[:status] == 'ERROR' res[:records].map do |record| DNS.new record.merge(domain:) end end |
Instance Method Details
#create ⇒ Object
120 121 122 123 124 125 |
# File 'lib/porkbun.rb', line 120 def create res = Porkbun.porkbun File.join('dns/create', domain), parse_response res @id = res[:id] self end |
#delete ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/porkbun.rb', line 86 def delete raise Error, 'Need ID to delete record' unless id res = Porkbun.porkbun File.join('dns/delete', domain, id) parse_response res self end |
#edit ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/porkbun.rb', line 62 def edit raise Error, 'Need ID to id record' unless id res = Porkbun.porkbun File.join('dns/edit', domain, id), parse_response res @id = res[:id] self end |
#save ⇒ Object
71 72 73 |
# File 'lib/porkbun.rb', line 71 def save edit end |
#to_h ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/porkbun.rb', line 108 def to_h { name: name, content: content, type: type, ttl: ttl, prio: prio, domain: domain, id: id } end |
#to_s ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/porkbun.rb', line 94 def to_s content_str = case type when /TXT|SPF/ "\"#{content}\"" when /MX|CNAME|NS/ "#{content}." else String(content) end prio_str = prio == '0' ? '' : prio "#{name}. #{ttl} IN #{type} #{prio_str} #{content_str}".tr_s(' ', ' ') end |