Class: Librato::Metrics::Collection Private

Inherits:
Object
  • Object
show all
Defined in:
lib/librato/metrics/collection.rb

Overview

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

An internal class used for extracting pagination logic

Constant Summary collapse

MAX_RESULTS =

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

100

Class Method Summary collapse

Class Method Details

.paginated_collection(name, connection, path, query) ⇒ Object

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.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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) ⇒ Object

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.

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



16
17
18
# File 'lib/librato/metrics/collection.rb', line 16

def self.paginated_metrics(connection, path, query)
  paginated_collection("metrics", connection, path, query)
end