Class: Dnsimple::Client::ClientService

Inherits:
Object
  • Object
show all
Defined in:
lib/dnsimple/client/clients.rb

Overview

Struct

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ClientService

Returns a new instance of ClientService.



83
84
85
# File 'lib/dnsimple/client/clients.rb', line 83

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientDnsimple::Client (readonly)

Returns:



81
82
83
# File 'lib/dnsimple/client/clients.rb', line 81

def client
  @client
end

Instance Method Details

#paginate(method, *args) ⇒ Dnsimple::CollectionResponse

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Internal helper that loops over a paginated response and returns all the records in the collection.

Parameters:

  • method (Symbol)

    The client method to execute

  • args (Array)

    The args to call the method with

Returns:



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/dnsimple/client/clients.rb', line 94

def paginate(method, *args)
  current_page = 0
  total_pages = nil
  collection = []
  options = args.pop
  response = nil

  loop do
    current_page += 1
    query = Extra.deep_merge(options, query: { page: current_page, per_page: 100 })

    response = send(method, *(args + [query]))
    total_pages ||= response.total_pages
    collection.concat(response.data)
    break unless current_page < total_pages
  end

  CollectionResponse.new(response.http_response, collection)
end