Class: Dslimple::Client
- Inherits:
-
Dnsimple::Client
- Object
- Dnsimple::Client
- Dslimple::Client
- Defined in:
- lib/dslimple/client.rb
Constant Summary collapse
Instance Method Summary collapse
- #account_id ⇒ Object
- #all_records(zone) ⇒ Object
- #all_zones(with_records: false) ⇒ Object
-
#initialize(sandbox: false, **options) ⇒ Client
constructor
A new instance of Client.
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, **) [:base_url] = SANDBOX_URL if sandbox [:user_agent] = USER_AGENT [:access_token] ||= ENV['DNSIMPLE_ACCESS_TOKEN'] super() end |
Instance Method Details
#account_id ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/dslimple/client.rb', line 18 def account_id return @account_id if instance_variable_defined?(:@account_id) whoami = identity.whoami.data @account_id = whoami.user&.id @account_id = whoami.account.id if whoami.account @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(account_id, 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(account_id, 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(account_id) 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(account_id, page: response.page + 1) else nil end end zones end |