Class: Porkbun::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/porkbun/models/record.rb

Class Method Summary collapse

Methods inherited from Object

#initialize, #to_ostruct

Constructor Details

This class inherits a constructor from Porkbun::Object

Class Method Details

.create(domain:, type:, content:, **options) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/porkbun/models/record.rb', line 21

def create(domain:, type:, content:, **options)
  body = {
    type: type,
    content: content,
  }.merge(options)
  response = Client.post_request("dns/create/#{domain}", body: body)
  Record.new(id: response.body["id"]) if response.body["status"] == "SUCCESS"
end

.delete(domain:, id:) ⇒ Object



47
48
49
50
# File 'lib/porkbun/models/record.rb', line 47

def delete(domain:, id:)
  response = Client.post_request("dns/delete/#{domain}/#{id}", body: {})
  response.body["status"] == "SUCCESS"
end

.delete_by_subdomain(domain:, type:, subdomain:) ⇒ Object



52
53
54
55
# File 'lib/porkbun/models/record.rb', line 52

def delete_by_subdomain(domain:, type:, subdomain:)
  response = Client.post_request("dns/deleteByNameType/#{domain}/#{type}/#{subdomain}", body: {})
  response.body["status"] == "SUCCESS"
end

.list(domain:) ⇒ Object



6
7
8
9
# File 'lib/porkbun/models/record.rb', line 6

def list(domain:)
  response = Client.post_request("dns/retrieve/#{domain}", body: {})
  Collection.from_response(response, type: Record, key: "records")
end

.list_by_type(domain:, type:, subdomain:) ⇒ Object



11
12
13
14
# File 'lib/porkbun/models/record.rb', line 11

def list_by_type(domain:, type:, subdomain:)
  response = Client.post_request("dns/retrieveByNameType/#{domain}/#{type}/#{subdomain}", body: {})
  Collection.from_response(response, type: Record, key: "records")
end

.retrieve(domain:, id:) ⇒ Object



16
17
18
19
# File 'lib/porkbun/models/record.rb', line 16

def retrieve(domain:, id:)
  response = Client.post_request("dns/retrieve/#{domain}/#{id}", body: {})
  Record.new(response.body["records"][0])
end

.update(domain:, id:, type:, content:, **options) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/porkbun/models/record.rb', line 30

def update(domain:, id:, type:, content:, **options)
  body = {
    type: type,
    content: content,
  }.merge(options)
  response = Client.post_request("dns/edit/#{domain}/#{id}", body: body)
  response.body["status"] == "SUCCESS"
end

.update_by_subdomain(domain:, type:, subdomain:, content:, **options) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/porkbun/models/record.rb', line 39

def update_by_subdomain(domain:, type:, subdomain:, content:, **options)
  body = {
    content: content,
  }.merge(options)
  response = Client.post_request("dns/editByNameType/#{domain}/#{type}/#{subdomain}", body: body)
  response.body["status"] == "SUCCESS"
end