librato-metrics 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
@@ -1 +1,4 @@
1
- �ԇ��dIT.���`<���3��e����U�Q����6��f�M;AC�@yCf���V��H�$.��B҄&܈��LʔSOS�����$ƒ5Ak�]�g�M�����ru��D��ؖC1f>��z���ɠ�`�ɥ/U[�aYJ���������I�+~w��sn��*�ď��:Sb�ލ�9�u �>�z����0 V��ο.�Y:0͟�=ʍL��7c�/�N]=�9��^[]3z/���풏'B���[*
1
+ k6A��IM71 �Q-�pE
2
+ '�d�Je�$x�B�6�u��^]�S-2dw�
3
+ r��L�v}�L$��@3r{�Z�Rt��y�R�\�)���X����?M/� ��"k�b��7����x�¡+Y�Z��* �LI)5�����(�� ���p�9��tĬS:�Vpε.��U
4
+ �פ���{��q���D�;��k��&���a�g���M��2�)\Aq%EV�.X�ղ��ʾ嬓: ����;��=���n
@@ -1,5 +1,8 @@
1
1
  ## Changelog
2
2
 
3
+ ### Version 1.3.0
4
+ * Add support for working with sources as a first-class entity
5
+
3
6
  ### Version 1.2.0
4
7
  * Give metric-facing methods more explicit names & deprecate priors
5
8
  * Documentation improvements
data/LICENSE CHANGED
@@ -8,8 +8,8 @@ modification, are permitted provided that the following conditions are met:
8
8
  * Redistributions in binary form must reproduce the above copyright
9
9
  notice, this list of conditions and the following disclaimer in the
10
10
  documentation and/or other materials provided with the distribution.
11
- * Neither the name of Librato, Inc. nor the names of project contributors
12
- may be used to endorse or promote products derived from this software
11
+ * Neither the name of Librato, Inc. nor the names of project contributors
12
+ may be used to endorse or promote products derived from this software
13
13
  without specific prior written permission.
14
14
 
15
15
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
@@ -79,6 +79,7 @@ module Librato
79
79
  :get_metric, :get_measurements, :metrics,
80
80
  :delete_metrics, :update_metric, :update_metrics,
81
81
  :submit,
82
+ :sources, :get_source, :update_source,
82
83
  # Deprecated metrics methods
83
84
  :fetch, :list, :delete, :update
84
85
 
@@ -340,6 +340,53 @@ module Librato
340
340
  end
341
341
  end
342
342
 
343
+ # Update one or more metrics. Note that attributes are specified in
344
+ # their own hash for updating a single metric but are included inline
345
+ # when updating multiple metrics.
346
+ #
347
+ # @deprecated Use #update_metric instead
348
+ alias update update_metric
349
+
350
+ # List sources, optionally limited by a name. See http://dev.librato.com/v1/sources
351
+ # and http://dev.librato.com/v1/get/sources
352
+ #
353
+ # @example Get sources matching "production"
354
+ # Librato::Metrics.sources name: "production"
355
+ #
356
+ # @param [Hash] filter
357
+ def sources(filter = {})
358
+ query = filter[:name] if filter.has_key?(:name)
359
+ path = "sources"
360
+ Collection.paginated_collection("sources", connection, path, query)
361
+ end
362
+
363
+ # Retrieve a single source by name. See http://dev.librato.com/v1/get/sources/:name
364
+ #
365
+ # @example Get the source for a particular EC2 instance from Cloudwatch
366
+ # Librato::Metrics.source "us-east-1b.i-f1bc8c9c"
367
+ #
368
+ # @param String name
369
+ def get_source(name)
370
+ url = connection.build_url("sources/#{name}")
371
+ response = connection.get(url)
372
+ parsed = SmartJSON.read(response.body)
373
+ end
374
+
375
+ # Update a source by name. See http://dev.librato.com/v1/get/sources/:name
376
+ #
377
+ # @example Update the source display name for a particular EC2 instance from Cloudwatch
378
+ # Librato::Metrics.source "us-east-1b.i-f1bc8c9c", display_name: "Production Web 1"
379
+ #
380
+ # @param String name
381
+ # @param Hash options
382
+ def update_source(name, options = {})
383
+ url = "sources/#{name}"
384
+ connection.put do |request|
385
+ request.url connection.build_url(url)
386
+ request.body = SmartJSON.write(options)
387
+ end
388
+ end
389
+
343
390
  private
344
391
 
345
392
  def default_faraday_adapter
@@ -14,12 +14,16 @@ module Librato
14
14
  # @param [String] path API uri
15
15
  # @param [Hash] query Query options
16
16
  def self.paginated_metrics(connection, path, query)
17
+ paginated_collection("metrics", connection, path, query)
18
+ end
19
+
20
+ def self.paginated_collection(name, connection, path, query)
17
21
  results = []
18
22
  # expects 200
19
23
  url = connection.build_url(path, query)
20
24
  response = connection.get(url)
21
25
  parsed = SmartJSON.read(response.body)
22
- results = parsed["metrics"]
26
+ results = parsed[name]
23
27
  return results if parsed["query"]["found"] <= MAX_RESULTS
24
28
  query[:offset] = MAX_RESULTS
25
29
  begin
@@ -27,10 +31,11 @@ module Librato
27
31
  url = connection.build_url(path, query)
28
32
  response = connection.get(url)
29
33
  parsed = SmartJSON.read(response.body)
30
- results.push(*parsed["metrics"])
34
+ results.push(*parsed[name])
31
35
  query[:offset] += MAX_RESULTS
32
36
  end while query[:offset] < parsed["query"]["found"]
33
37
  results
38
+
34
39
  end
35
40
 
36
41
  end
@@ -1,5 +1,5 @@
1
1
  module Librato
2
2
  module Metrics
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
10
10
 
11
11
  s.name = 'librato-metrics'
12
12
  s.version = Librato::Metrics::VERSION
13
+ s.license = 'BSD 3-clause'
13
14
 
14
15
  s.summary = "Ruby wrapper for Librato's Metrics API"
15
16
  s.description = "An easy to use ruby wrapper for Librato's Metrics API"
@@ -310,5 +310,50 @@ module Librato
310
310
  end
311
311
  end
312
312
 
313
+ describe "Sources API" do
314
+ before do
315
+ Metrics.update_source("sources_api_test", display_name: "Sources Api Test")
316
+ end
317
+
318
+ describe "#sources" do
319
+ it "should work" do
320
+ sources = Metrics.sources
321
+ sources.should be_an(Array)
322
+ test_source = sources.detect { |s| s["name"] == "sources_api_test" }
323
+ test_source["display_name"].should == "Sources Api Test"
324
+ end
325
+ end
326
+
327
+ describe "#get_source" do
328
+ it "should work" do
329
+ test_source = Metrics.get_source("sources_api_test")
330
+ test_source["display_name"].should == "Sources Api Test"
331
+ end
332
+ end
333
+
334
+ describe "#update_source" do
335
+ it "should update an existing source" do
336
+ Metrics.update_source("sources_api_test", display_name: "Updated Source Name")
337
+
338
+ test_source = Metrics.get_source("sources_api_test")
339
+ test_source["display_name"].should == "Updated Source Name"
340
+ end
341
+
342
+ it "should create new sources" do
343
+ source_name = "sources_api_test_#{Time.now.to_f}"
344
+ lambda {
345
+ no_source = Metrics.get_source(source_name)
346
+ }.should raise_error(Librato::Metrics::NotFound)
347
+
348
+ Metrics.update_source(source_name, display_name: "New Source")
349
+
350
+ test_source = Metrics.get_source(source_name)
351
+ test_source.should_not be_nil
352
+ test_source["display_name"].should == "New Source"
353
+ end
354
+ end
355
+
356
+ end
357
+
313
358
  end
314
359
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: librato-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -37,7 +37,7 @@ cert_chain:
37
37
  bktaNmhlblFBRjFDSDk2WmNxY0pIMTc5UzJ0SWlLRE04a2VlUklVT1BDM1dU
38
38
  MGZhb2svMgpnQTJvemRyODUxYy9uQT09Ci0tLS0tRU5EIENFUlRJRklDQVRF
39
39
  LS0tLS0K
40
- date: 2013-10-29 00:00:00.000000000 Z
40
+ date: 2013-11-19 00:00:00.000000000 Z
41
41
  dependencies:
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: faraday
@@ -236,7 +236,8 @@ files:
236
236
  - spec/unit/metrics/queue_spec.rb
237
237
  - spec/unit/metrics_spec.rb
238
238
  homepage: https://github.com/librato/librato-metrics
239
- licenses: []
239
+ licenses:
240
+ - BSD 3-clause
240
241
  post_install_message:
241
242
  rdoc_options:
242
243
  - --charset=UTF-8
@@ -250,7 +251,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
250
251
  version: '0'
251
252
  segments:
252
253
  - 0
253
- hash: -3545928183344149228
254
+ hash: 694362489325963939
254
255
  required_rubygems_version: !ruby/object:Gem::Requirement
255
256
  none: false
256
257
  requirements:
metadata.gz.sig CHANGED
Binary file