Class: Porkbun::DNS

Inherits:
Abstract show all
Defined in:
lib/porkbun.rb

Instance Attribute Summary collapse

Attributes inherited from Abstract

#message, #status

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

#parse_response, #success?

Constructor Details

#initialize(options) ⇒ DNS

Returns a new instance of DNS.



44
45
46
47
48
49
50
51
52
# File 'lib/porkbun.rb', line 44

def initialize(options)
  @name = options[:name]
  @content = options[:content]
  @type = options[:type]
  @ttl = options[:ttl] || 600
  @prio = options[:prio]
  @domain = options[:domain]
  @id = options[:id]
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



42
43
44
# File 'lib/porkbun.rb', line 42

def content
  @content
end

#domainObject

Returns the value of attribute domain.



42
43
44
# File 'lib/porkbun.rb', line 42

def domain
  @domain
end

#idObject

Returns the value of attribute id.



42
43
44
# File 'lib/porkbun.rb', line 42

def id
  @id
end

#nameObject

Returns the value of attribute name.



42
43
44
# File 'lib/porkbun.rb', line 42

def name
  @name
end

#notesObject

Returns the value of attribute notes.



42
43
44
# File 'lib/porkbun.rb', line 42

def notes
  @notes
end

#prioObject

Returns the value of attribute prio.



42
43
44
# File 'lib/porkbun.rb', line 42

def prio
  @prio
end

#ttlObject

Returns the value of attribute ttl.



42
43
44
# File 'lib/porkbun.rb', line 42

def ttl
  @ttl
end

#typeObject

Returns the value of attribute type.



42
43
44
# File 'lib/porkbun.rb', line 42

def type
  @type
end

Class Method Details

.create(options) ⇒ Object



54
55
56
57
# File 'lib/porkbun.rb', line 54

def self.create(options)
  record = DNS.new options
  record.create
end

.retrieve(domain, id = nil) ⇒ Object

Raises:



72
73
74
75
76
77
78
79
80
81
# File 'lib/porkbun.rb', line 72

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

#createObject



105
106
107
108
109
110
# File 'lib/porkbun.rb', line 105

def create
  res = Porkbun.porkbun File.join('dns/create', domain), get_options
  parse_response res
  @id = res[:id]
  self
end

#deleteObject

Raises:



83
84
85
86
87
88
89
# File 'lib/porkbun.rb', line 83

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

#editObject

Raises:



59
60
61
62
63
64
65
66
# File 'lib/porkbun.rb', line 59

def edit
  raise Error, 'Need ID to id record' unless id

  res = Porkbun.porkbun File.join('dns/edit', domain, id), get_options
  parse_response res
  @id = res[:id]
  self
end

#saveObject



68
69
70
# File 'lib/porkbun.rb', line 68

def save
  edit
end

#to_sObject



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/porkbun.rb', line 91

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