opentsdb-consumer 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3946790fd8040a154653d58d3729179da5300548
4
- data.tar.gz: efb1a9798819da7e28133d7d95f82227a36cad36
3
+ metadata.gz: a78304f73686cf40a865ef0546337c5b11a69847
4
+ data.tar.gz: f216a7b347b229066c52ab2dd04d5a9ef272ffad
5
5
  SHA512:
6
- metadata.gz: 7cccd3f3fa6cdb099815724d4640301c21cc2e9e623c89274b6c18ff71095dc2a3ee387f90e92af030935c4682b5b19c6f2038ae1bd6a0831d6c6e4db8f50f17
7
- data.tar.gz: 60d00471c835408a5cf13b3f3b3fbc45c135614801d12abcb664f7aa986dbac5df8cd9e7d21ef7f86b5d90bfc1531e88f85417c4eadce0f844388ec308da9de8
6
+ metadata.gz: 853a0322f569c5efc7818d1a2ea2e03b6903059cce7707a0f13dad2ba6e3de41b69a23957c310f2fec7e51831b8e51b60bc42824d6a1c42731ae89579451721d
7
+ data.tar.gz: cb611732fbd5b61b6cb53cd7afa54d7feb48a5c71079baa552728a6777ff12550058857fd0b59bfb20b5bd9283a005f50f27baa804ab7d5e3cd0d8805e863298
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -11,12 +11,23 @@ module OpenTSDBConsumer
11
11
 
12
12
  def self.build(response)
13
13
  results = response.map { |h| new(h) }
14
- results.length > 1 ? results : results.first
14
+ case results.length
15
+ when 0
16
+ new('dps' => [])
17
+ when 1
18
+ results.first
19
+ else
20
+ results
21
+ end
15
22
  end
16
23
 
17
24
  def latest_value
18
25
  datapoint = datapoints.max_by { |timestamp, _| timestamp }
19
26
  datapoint.last if datapoint
20
27
  end
28
+
29
+ def empty?
30
+ datapoints.nil? || datapoints.empty?
31
+ end
21
32
  end
22
33
  end
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: opentsdb-consumer 0.3.0 ruby lib
5
+ # stub: opentsdb-consumer 0.4.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "opentsdb-consumer"
9
- s.version = "0.3.0"
9
+ s.version = "0.4.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Philippe H\u{e4}ssig"]
14
- s.date = "2015-12-07"
14
+ s.date = "2016-01-13"
15
15
  s.description = "Client library to consume metrics from OpenTSDB"
16
16
  s.email = "phil@nine.ch"
17
17
  s.executables = ["opentsdb-consumer"]
@@ -29,6 +29,14 @@ RSpec.describe OpenTSDBConsumer::Result do
29
29
  expect(results.first).to be_a OpenTSDBConsumer::Result
30
30
  expect(results.last).to be_a OpenTSDBConsumer::Result
31
31
  end
32
+
33
+ it 'returns an empty result object when there is no data' do
34
+ response = []
35
+ result = described_class.build(response)
36
+ expect(result).to be_a OpenTSDBConsumer::Result
37
+ expect(result.datapoints).to be_an Array
38
+ expect(result.datapoints).to be_empty
39
+ end
32
40
  end
33
41
 
34
42
  describe '#latest_value' do
@@ -42,4 +50,21 @@ RSpec.describe OpenTSDBConsumer::Result do
42
50
  expect(result.latest_value).to be_nil
43
51
  end
44
52
  end
53
+
54
+ describe '#empty?' do
55
+ it 'returns false when there is data' do
56
+ result = described_class.new 'dps' => [{}]
57
+ expect(result).to_not be_empty
58
+ end
59
+
60
+ it 'returns true when there is no data' do
61
+ result = described_class.new 'dps' => []
62
+ expect(result).to be_empty
63
+ end
64
+
65
+ it 'returns true when the datapoints are nil' do
66
+ result = described_class.new 'dps' => nil
67
+ expect(result).to be_empty
68
+ end
69
+ end
45
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentsdb-consumer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philippe Hässig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-07 00:00:00.000000000 Z
11
+ date: 2016-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon