Class: Librato::Metrics::Collection
- Inherits:
-
Object
- Object
- Librato::Metrics::Collection
- Defined in:
- lib/librato/metrics/collection.rb
Constant Summary collapse
- MAX_RESULTS =
100
Class Method Summary collapse
-
.paginated_metrics(connection, path, query) ⇒ Object
Aggregates all results of paginated elements, requesting more collections as needed.
Class Method Details
.paginated_metrics(connection, path, query) ⇒ Object
Aggregates all results of paginated elements, requesting more collections as needed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/librato/metrics/collection.rb', line 12 def self.paginated_metrics(connection, path, query) results = [] # expects 200 url = connection.build_url(path, query) response = connection.get(url) parsed = MultiJson.decode(response.body) results = parsed["metrics"] 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 = MultiJson.decode(response.body) results.push(*parsed["metrics"]) query[:offset] += MAX_RESULTS end while query[:offset] < parsed["query"]["found"] results end |