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.



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

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.



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

def content
  @content
end

#domainObject

Returns the value of attribute domain.



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

def domain
  @domain
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#notesObject

Returns the value of attribute notes.



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

def notes
  @notes
end

#prioObject

Returns the value of attribute prio.



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

def prio
  @prio
end

#ttlObject

Returns the value of attribute ttl.



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

def ttl
  @ttl
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Class Method Details

.create(options) ⇒ Object



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

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

.retrieve(domain, id = nil) ⇒ Object

Raises:



64
65
66
67
68
69
70
71
# File 'lib/porkbun.rb', line 64

def self.retrieve(domain, id = nil)
  raise Error, 'need domain' unless domain

  res = Porkbun.porkbun File.join('dns/retrieve', domain, id || '').chomp('/')
  res[:records].map do |record|
    DNS.new record.merge(domain:)
  end
end

Instance Method Details

#createObject



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

def create
  res = Porkbun.porkbun File.join('dns/create', domain), {
    name:,
    content:,
    type:,
    ttl:
  }
  parse_response res
  @id = res[:id]
  self
end

#deleteObject

Raises:



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

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:



60
61
62
# File 'lib/porkbun.rb', line 60

def edit
  raise Error, 'need id to edit' unless @id
end