mind_meld 0.1.7 → 0.1.8

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: abbb5393c6f319e896e4f0b13ae040ed085255ca
4
- data.tar.gz: d76a86d3865b2277663c9a6b2a35d01dd6d98cf7
3
+ metadata.gz: 8b65926d587a38937db8b38dc47129d2120c19da
4
+ data.tar.gz: 7d65035319bd87c469feb34d71f70c4504cb573a
5
5
  SHA512:
6
- metadata.gz: c3800bfe361a6520b76d87acb11093afdf18115a92bf86ee3cf42136563a883bdef6cfdda1f4c6af80a430199cfd934c44a07d16a70c6f73e050f70299832a3a
7
- data.tar.gz: 5179039aeb0d2ca6e2472e7921bf06adf8fe29399d364a54648b8d5535c814cd5a37d44a02e3a743ddf2d4df595adf1c9e36e3cd883cbf806543384d10d21f3f
6
+ metadata.gz: a7fcf44f794d90cd9b198ffcd7543bedd81b0fb531d1721b605406d85ec3d905824b1f150ff3d4d302cd99bb82f5034535dee056718dc3b28592e8788ec0c9e4
7
+ data.tar.gz: fd0dd50a69678a7fa6ee9ab5defadc56a817f97ec556834d40098586d312787020d63434debdd6c03abb45228f3c34a2187aaa103f41435123908d0251f67585
data/bin/mind_meld CHANGED
@@ -78,7 +78,7 @@ when 'action'
78
78
  opts[:connection].create_action( opts[:options].to_h )
79
79
 
80
80
  when 'details'
81
- opts = Parser.parse 'device', ARGV
81
+ opts = Parser.parse 'details', ARGV
82
82
  dd = opts[:connection].device_details(view: 'simple')
83
83
  puts "Id: #{dd['id']}"
84
84
  puts "Name: #{dd['name']}"
data/lib/mind_meld.rb CHANGED
@@ -18,13 +18,39 @@ class MindMeld
18
18
  @http.verify_mode = options[:verify_mode] if options.key?(:verify_mode)
19
19
  end
20
20
  end
21
+
22
+ @statistics = []
21
23
  end
22
24
 
23
25
  def devices
24
26
  request :get, 'devices'
25
27
  end
26
28
 
29
+ def add_statistics data
30
+ data = [ data ] if ! data.is_a? Array
31
+
32
+ verify_statistics_arguments data
33
+ @statistics.concat data
34
+ end
35
+
36
+ def flush_statistics
37
+ response = request :post, 'device_statistics/upload', { data: @statistics }
38
+ @statistics = [] if ! response.has_key? :error
39
+ response
40
+ end
41
+
27
42
  private
43
+ def verify_statistics_arguments data
44
+ data.each do |d|
45
+ if ! d.has_key? :timestamp
46
+ d[:timestamp] = Time.now
47
+ end
48
+ [:device_id, :label, :value].each do |key|
49
+ raise ArgumentError, "Missing #{key}" if ! d.has_key? key
50
+ end
51
+ end
52
+ end
53
+
28
54
  def request type, call, params = {}
29
55
  if @http
30
56
  begin
@@ -43,7 +69,9 @@ class MindMeld
43
69
  )
44
70
  end
45
71
  # Allow for 'array with indifferent access'
46
- { reply: JSON.parse(response.body) }.with_indifferent_access[:reply]
72
+ reply = { reply: JSON.parse(response.body) }.with_indifferent_access[:reply]
73
+ reply[:error] = "Status: #{response.code}" if ! response.kind_of? Net::HTTPSuccess
74
+ reply
47
75
  rescue => e
48
76
  { error: e.message }.with_indifferent_access
49
77
  end
@@ -73,4 +73,18 @@ class MindMeld::Device < MindMeld
73
73
  @device_details
74
74
  end
75
75
  end
76
+
77
+ def add_statistics data
78
+ if ! data.is_a? Array
79
+ data = [ data ]
80
+ end
81
+
82
+ id = self.id
83
+ data.each do |d|
84
+ d[:device_id] = id if ! d[:device_id]
85
+ end
86
+
87
+ super data
88
+ end
89
+
76
90
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mind_meld
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Haig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-05 00:00:00.000000000 Z
11
+ date: 2016-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport