Class: Freenom::Dns

Inherits:
Object
  • Object
show all
Defined in:
lib/freenom/dns.rb,
lib/freenom/dns/version.rb

Constant Summary collapse

VERSION =
'0.1.5'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username:, password:, domain:) ⇒ Dns

Returns a new instance of Dns.



13
14
15
16
17
# File 'lib/freenom/dns.rb', line 13

def initialize(username:, password:, domain:)
  @username = username
  @password = password
  @domain = domain
end

Instance Attribute Details

#domainObject

Returns the value of attribute domain.



11
12
13
# File 'lib/freenom/dns.rb', line 11

def domain
  @domain
end

#passwordObject

Returns the value of attribute password.



11
12
13
# File 'lib/freenom/dns.rb', line 11

def password
  @password
end

#usernameObject

Returns the value of attribute username.



11
12
13
# File 'lib/freenom/dns.rb', line 11

def username
  @username
end

Instance Method Details

#create_record!(name:, type:, time_to_live:, target:) ⇒ Object



28
29
30
31
32
# File 'lib/freenom/dns.rb', line 28

def create_record!(name:, type:, time_to_live:, target:)
  Freenom::Authenticator.new(username: @username, password: @password).run
  Freenom::DNSRecordCreator.new(domain: @domain)
                           .run(name: name, type: type, time_to_live: time_to_live, target: target)
end

#delete_record!(record) ⇒ Object



34
35
36
37
# File 'lib/freenom/dns.rb', line 34

def delete_record!(record)
  Freenom::Authenticator.new(username: @username, password: @password).run
  Freenom::DNSRecordDeleter.new(domain: @domain).run(record: record)
end

#exist_record?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/freenom/dns.rb', line 24

def exist_record?(options = {})
  records.any? { |record| record.match?(options) }
end

#recordsObject



19
20
21
22
# File 'lib/freenom/dns.rb', line 19

def records
  Freenom::Authenticator.new(username: @username, password: @password).run
  Freenom::DNSRecordsFetcher.new(domain: @domain).run
end