Class: Njalla::V1::Domain

Inherits:
Object
  • Object
show all
Defined in:
lib/njalla/v1/domain.rb

Overview

Implement domain method APIv1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, domain:) ⇒ Domain

Returns a new instance of Domain.

Parameters:



18
19
20
21
# File 'lib/njalla/v1/domain.rb', line 18

def initialize(client:, domain:)
  @client = client
  @domain = domain
end

Instance Attribute Details

#clientNjalla::V1::Client (readonly)

Returns:



12
13
14
# File 'lib/njalla/v1/domain.rb', line 12

def client
  @client
end

#domainString (readonly)

Returns:

  • (String)


14
15
16
# File 'lib/njalla/v1/domain.rb', line 14

def domain
  @domain
end

Instance Method Details

#add_record(content:, name: '@', ttl: 60, type: 'A') ⇒ Njalla::V1::Schemas::Record

Adds a record

Parameters:

  • content (String)
  • name (String) (defaults to: '@')
  • type (String) (defaults to: 'A')
  • ttl (Integer) (defaults to: 60)

Returns:



30
31
32
33
34
# File 'lib/njalla/v1/domain.rb', line 30

def add_record(content:, name: '@', ttl: 60, type: 'A')
  record = Schemas::AddRecord.new.call(domain: domain, content: content, name: name, type: type, ttl: ttl)

  Schemas::Record.new.call(**client.post('add-record', record).dig('result'))
end

#remove_record(id:) ⇒ Boolean

Remove a record by its ID

Parameters:

  • :id (String, Integer)

Returns:

  • (Boolean)


40
41
42
43
44
45
# File 'lib/njalla/v1/domain.rb', line 40

def remove_record(id:)
  record = Schemas::RemoveRecord.new.call(domain: domain, id: id)
  result = client.post('remove-record', record).dig('result')

  !result.nil? && result.empty?
end