class Librato::Metrics::Collection

An internal class used for extracting pagination logic

@api private

Constants

MAX_RESULTS

Public Class Methods

paginated_collection(name, connection, path, query) click to toggle source
# File lib/librato/metrics/collection.rb, line 20
def self.paginated_collection(name, connection, path, query)
  results = []
  # expects 200
  url = connection.build_url(path, query)
  response = connection.get(url)
  parsed = SmartJSON.read(response.body)
  results = parsed[name]
  return results if parsed["query"]["found"] <= MAX_RESULTS
  query[:offset] = MAX_RESULTS
  begin
    # expects 200
    url = connection.build_url(path, query)
    response = connection.get(url)
    parsed = SmartJSON.read(response.body)
    results.push(*parsed[name])
    query[:offset] += MAX_RESULTS
  end while query[:offset] < parsed["query"]["found"]
  results

end
paginated_metrics(connection, path, query) click to toggle source

Aggregates all results of paginated elements, requesting more collections as needed

@param [Excon] connection Connection to Metrics service @param [String] path API uri @param [Hash] query Query options

# File lib/librato/metrics/collection.rb, line 16
def self.paginated_metrics(connection, path, query)
  paginated_collection("metrics", connection, path, query)
end