lita-libratoo 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a0cea0645edd9219f2a7bdf5f8f1bf351f4deb30
4
- data.tar.gz: 8522dfcf0e5ee1a1ef4c408202a60c9195833e74
3
+ metadata.gz: 641821ba24a20cbbf66cb240ad8a2b820d4a5a39
4
+ data.tar.gz: f445a0003b17f61c080c7e14e6a7b896cfef9313
5
5
  SHA512:
6
- metadata.gz: fa204f2e611853bfdb3db7c1585896282a84923f975b7110ad50f0834acc536b5965c36062f4e2ce8fcdec36778ee911159784679275fb43f6fcb12b3676543e
7
- data.tar.gz: 8ed83fbcadc5eaff137344b9849e200fcd94256fb94d48cdbdc2328746093ffbb140fe8e6b29511e86a094448a9b9dd28d39081aed54bdc34ae96cfbcf396bc4
6
+ metadata.gz: 9baa4cd5c0b0910c7e14f4ee6db2e4326300bfd32613c29156c0f501b69756ca0d6bd0a2a9efc02f33ee91367dd444d4f26d067d5a03dc0f111c04318ff234cb
7
+ data.tar.gz: f0029a05d3ab3a37d93390a82e2257fe6b02fead29b58fc2dce7514a53d92ae5ba7dc8e8a69ae00c6a0ee454b3f49ff3419bac96b60cce100987dfd0f51acf8d
@@ -19,12 +19,7 @@ module Lita
19
19
  metrics = Librato::Metrics.metrics.map{|v| v["name"] }
20
20
  response_text = metrics.grep(/#{arguments[1]}/i).join(', ')
21
21
  response_text = "No results" if response_text.empty?
22
- if response_text.length > 400 && !response.message.source.private_message
23
- response.reply "Large result set. Sending you a direct message."
24
- return response.reply_privately response_text
25
- else
26
- return response.reply response_text
27
- end
22
+ return reply_or_whisper_long response, response_text
28
23
  end
29
24
 
30
25
  metric, options = arguments[0].to_sym, arguments[1..-1]
@@ -45,12 +40,39 @@ module Lita
45
40
  response_text = results.map{|k,v| "#{k}: #{v.join ', '}" }.join "\n"
46
41
  end
47
42
 
48
- if response_text.length > 400 && !response.message.source.private_message
49
- return response.reply "Large result set. Sending you a direct message."
50
- return response.reply_privately response_text
43
+ reply_or_whisper_long response, response_text
44
+ rescue Exception => e
45
+ reply_or_whisper_long response, e.message
46
+ end
47
+
48
+ route(/^librato sum\s(.+)/, :librato_sum, command: true, help: {
49
+ "librato sum [metric] [options]" =>
50
+ "example: 'lita librato sum payments_controller.stripe.success start_time: 2016-03-11-02:00'"
51
+ })
52
+
53
+ def librato_sum(response)
54
+ Librato::Metrics.authenticate config.email, config.api_key
55
+
56
+ arguments = response.matches[0][0].delete(':').split
57
+
58
+ metric, options = arguments[0].to_sym, arguments[1..-1]
59
+ options = symbolize_keys Hash[*options]
60
+ options = { resolution: 1 }.merge options
61
+ if options.key?(:start_time) && !options[:start_time].is_a?(Numeric)
62
+ options[:start_time] = DateTime.parse(options[:start_time]).to_time.to_i
63
+ end
64
+
65
+ results = Librato::Metrics.get_composite %Q[sum(s("#{metric}", "*", {function: "sum"}))], options
66
+
67
+ if results["measurements"].any?
68
+ response_text = results["measurements"][0]["series"].reduce(0){|c,e| c + e["value"] }
51
69
  else
52
- return response.reply response_text
70
+ response_text = "No results"
53
71
  end
72
+
73
+ reply_or_whisper_long response, response_text
74
+ rescue Exception => e
75
+ reply_or_whisper_long response, e.message
54
76
  end
55
77
 
56
78
  route(/^librato search\s(.+)/, :librato_search, command: true, help: {
@@ -65,12 +87,9 @@ module Lita
65
87
  metrics = Librato::Metrics.metrics.map{|v| v["name"] }
66
88
  response_text = metrics.grep(/#{search}/i).join(', ')
67
89
  response_text = "No results" if response_text.empty?
68
- if response_text.length > 400 && !response.message.source.private_message
69
- response.reply "Large result set. Sending you a direct message."
70
- return response.reply_privately response_text
71
- else
72
- return response.reply response_text
73
- end
90
+ reply_or_whisper_long response, response_text
91
+ rescue Exception => e
92
+ reply_or_whisper_long response, e.message
74
93
  end
75
94
 
76
95
  def symbolize_keys(hash)
@@ -78,6 +97,18 @@ module Lita
78
97
  end
79
98
 
80
99
  Lita.register_handler(self)
100
+
101
+ private
102
+
103
+ def reply_or_whisper_long(response, response_text)
104
+ response_text = response_text.to_s
105
+ if response_text.length > 400 && !response.message.source.private_message
106
+ response.reply "Large result set. Sending you a direct message."
107
+ response.reply_privately response_text
108
+ else
109
+ response.reply response_text
110
+ end
111
+ end
81
112
  end
82
113
  end
83
114
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-libratoo"
3
- spec.version = "0.1.2"
3
+ spec.version = "0.1.3"
4
4
  spec.authors = ["Eric Boehs"]
5
5
  spec.email = ["ericboehs@gmail.com"]
6
6
  spec.description = "Query librato metrics from Lita"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-libratoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Boehs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-11 00:00:00.000000000 Z
11
+ date: 2016-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita