Class: Dslimple::Client

Inherits:
Dnsimple::Client
  • Object
show all
Defined in:
lib/dslimple/client.rb

Constant Summary collapse

SANDBOX_URL =
'https://api.sandbox.dnsimple.com'
USER_AGENT =
"dslimple v#{Dslimple::VERSION}"

Instance Method Summary collapse

Constructor Details

#initialize(sandbox: false, **options) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
# File 'lib/dslimple/client.rb', line 9

def initialize(sandbox: false, **options)
  options[:base_url] = SANDBOX_URL if sandbox
  options[:user_agent] = USER_AGENT

  options[:access_token] ||= ENV['DNSIMPLE_ACCESS_TOKEN']

  super(options)
end

Instance Method Details

#account_idObject



18
19
20
21
22
23
24
25
26
# File 'lib/dslimple/client.rb', line 18

def 
  return @account_id if instance_variable_defined?(:@account_id)

  whoami = identity.whoami.data
  @account_id = whoami.user&.id
  @account_id = whoami..id if whoami.

  @account_id
end

#all_records(zone) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/dslimple/client.rb', line 48

def all_records(zone)
  zone = zone.name if zone.is_a?(Dslimple::Zone)
  response = zones.list_zone_records(, zone)

  records = []
  while response
    records = records + response.data.map do |record|
      record = Dslimple::Record.new(record)
      record.zone = zone
      record
    end

    response = if response.page < response.total_pages
                 zones.list_zone_records(, zone, page: response.page + 1)
               else
                 nil
               end
  end
  records
end

#all_zones(with_records: false) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dslimple/client.rb', line 28

def all_zones(with_records: false)
  response = zones.list_zones()

  zones = []
  while response
    zones = zones + response.data.map do |zone|
      zone = Dslimple::Zone.new(zone.name)
      zone.records = all_records(zone) if with_records
      zone
    end

    response = if response.page < response.total_pages
                 zones.list_zones(, page: response.page + 1)
               else
                 nil
               end
  end
  zones
end