lita-kegbot 0.1.0
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 +7 -0
- data/.gitignore +17 -0
- data/.rubocop.yml +11 -0
- data/.travis.yml +8 -0
- data/Gemfile +3 -0
- data/LICENSE +19 -0
- data/README.md +55 -0
- data/Rakefile +8 -0
- data/lib/lita-kegbot.rb +7 -0
- data/lib/lita/handlers/kegbot.rb +190 -0
- data/lita-kegbot.gemspec +25 -0
- data/locales/en.yml +41 -0
- data/spec/files/drinks.json +33 -0
- data/spec/files/drinks_empty.json +10 -0
- data/spec/files/keg.json +53 -0
- data/spec/files/kegs.json +28 -0
- data/spec/files/kegs_empty.json +5 -0
- data/spec/files/tap.json +23 -0
- data/spec/files/taps.json +27 -0
- data/spec/files/taps_empty.json +6 -0
- data/spec/lita/handlers/kegbot_spec.rb +198 -0
- data/spec/spec_helper.rb +10 -0
- metadata +174 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2d74d86f47568b6cb26fcf32d1b250235c3c44bf
|
4
|
+
data.tar.gz: 1d7dd6489c04d0c019c7afeea3d51e00a1cc0a57
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9515ff91fa64205be86cb7034b91f93d8ef26b0e8b648cbf3840237742da40d2cd250dba87eadba053078b91d85a2d48c7cb8bc83b3326cd4f2a13d4bb0f444b
|
7
|
+
data.tar.gz: 91f8be5a3e132ba2c9c90e0a3cfa37d1a80bd093e6ce3750081f6ee7473696ea376525a4dc3ab221eb2a73a29f9f7fe75bb4d3889d21da1a24def886e81ee214
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Eric Sigler
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# lita-kegbot
|
2
|
+
|
3
|
+
[](https://travis-ci.org/esigler/lita-kegbot)
|
4
|
+
[](https://tldrlegal.com/license/mit-license)
|
5
|
+
[](https://rubygems.org/gems/lita-kegbot)
|
6
|
+
[](https://coveralls.io/r/esigler/lita-kegbot)
|
7
|
+
[](https://codeclimate.com/github/esigler/lita-kegbot)
|
8
|
+
[](https://gemnasium.com/esigler/lita-kegbot)
|
9
|
+
|
10
|
+
A Kegbot (https://kegbot.org) handler for checking what's on tap, how much is left, etc.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add lita-kegbot to your Lita instance's Gemfile:
|
15
|
+
|
16
|
+
``` ruby
|
17
|
+
gem "lita-kegbot"
|
18
|
+
```
|
19
|
+
|
20
|
+
## Configuration
|
21
|
+
|
22
|
+
Add the following variables to your Lita config file:
|
23
|
+
|
24
|
+
``` ruby
|
25
|
+
config.handlers.kegbot.api_key = '_your_key_here_'
|
26
|
+
config.handlers.kegbot.api_url = 'https://kegbot.example.com'
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
### Drinks
|
32
|
+
|
33
|
+
```
|
34
|
+
kegbot drink list - List last 5 drinks poured
|
35
|
+
kegbot drink list <N> - List last <N> drinks poured
|
36
|
+
```
|
37
|
+
|
38
|
+
### Taps
|
39
|
+
|
40
|
+
```
|
41
|
+
kegbot tap status - Shows status of all taps
|
42
|
+
kegbot tap status <id> - Shows status of tap <id>
|
43
|
+
```
|
44
|
+
|
45
|
+
### Kegs
|
46
|
+
|
47
|
+
```
|
48
|
+
kegbot keg status - Shows status of all kegs
|
49
|
+
kegbot keg status <id> - Shows status of keg <id>
|
50
|
+
```
|
51
|
+
|
52
|
+
## License
|
53
|
+
|
54
|
+
[MIT](http://opensource.org/licenses/MIT)
|
55
|
+
|
data/Rakefile
ADDED
data/lib/lita-kegbot.rb
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
module Lita
|
2
|
+
module Handlers
|
3
|
+
class Kegbot < Handler
|
4
|
+
route(
|
5
|
+
/^(?:kegbot|kb)\sdrink\slist$/,
|
6
|
+
:drink_list_all,
|
7
|
+
command: true,
|
8
|
+
help: {
|
9
|
+
t('help.drink_list.syntax') => t('help.drink_list.desc')
|
10
|
+
}
|
11
|
+
)
|
12
|
+
|
13
|
+
route(
|
14
|
+
/^(?:kegbot|kb)\sdrink\slist\s(\d+)$/,
|
15
|
+
:drink_list,
|
16
|
+
command: true,
|
17
|
+
help: {
|
18
|
+
t('help.drink_list_N.syntax') => t('help.drink_list_N.desc')
|
19
|
+
}
|
20
|
+
)
|
21
|
+
|
22
|
+
route(
|
23
|
+
/^(?:kegbot|kb)\stap\sstatus$/,
|
24
|
+
:tap_status_all,
|
25
|
+
command: true,
|
26
|
+
help: {
|
27
|
+
t('help.tap_status.syntax') => t('help.tap_status.desc')
|
28
|
+
}
|
29
|
+
)
|
30
|
+
|
31
|
+
route(
|
32
|
+
/^(?:kegbot|kb)\stap\sstatus\s(\d+)$/,
|
33
|
+
:tap_status_id,
|
34
|
+
command: true,
|
35
|
+
help: {
|
36
|
+
t('help.tap_status_id.syntax') => t('help.tap_status_id.desc')
|
37
|
+
}
|
38
|
+
)
|
39
|
+
|
40
|
+
route(
|
41
|
+
/^(?:kegbot|kb)\skeg\sstatus$/,
|
42
|
+
:keg_status_all,
|
43
|
+
command: true,
|
44
|
+
help: {
|
45
|
+
t('help.keg_status.syntax') => t('help.keg_status.desc')
|
46
|
+
}
|
47
|
+
)
|
48
|
+
|
49
|
+
route(
|
50
|
+
/^(?:kegbot|kb)\skeg\sstatus\s(\d+)$/,
|
51
|
+
:keg_status_id,
|
52
|
+
command: true,
|
53
|
+
help: {
|
54
|
+
t('help.keg_status_id.syntax') => t('help.keg_status_id.desc')
|
55
|
+
}
|
56
|
+
)
|
57
|
+
|
58
|
+
def self.default_config(config)
|
59
|
+
config.api_key = nil
|
60
|
+
config.api_url = nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def drink_list_all(response)
|
64
|
+
result = api_request('get', 'drinks/')
|
65
|
+
if result && result['result'] && result['result']['drinks']
|
66
|
+
drinks = result['result']['drinks']
|
67
|
+
response.reply(t('drinks.none')) unless drinks.count > 0
|
68
|
+
drinks.each do |drink|
|
69
|
+
response.reply(t('drinks.info', user: drink['user_id'],
|
70
|
+
date: drink['pour_time']))
|
71
|
+
end
|
72
|
+
else
|
73
|
+
response.reply(t('error.request'))
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def drink_list(response)
|
78
|
+
count = response.matches[0][0].to_i
|
79
|
+
current = 0
|
80
|
+
result = api_request('get', 'drinks')
|
81
|
+
if result && result['result'] && result['result']['drinks']
|
82
|
+
drinks = result['result']['drinks']
|
83
|
+
response.reply(t('drinks.none')) unless drinks.count > 0
|
84
|
+
drinks.each do |drink|
|
85
|
+
if current < count
|
86
|
+
response.reply(t('drinks.info', user: drink['user_id'],
|
87
|
+
date: drink['pour_time']))
|
88
|
+
current += 1
|
89
|
+
end
|
90
|
+
end
|
91
|
+
else
|
92
|
+
response.reply(t('error.request'))
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def tap_status_all(response)
|
97
|
+
result = api_request('get', 'taps/')
|
98
|
+
if result && result['result'] && result['result']['taps']
|
99
|
+
taps = result['result']['taps']
|
100
|
+
response.reply(t('taps.none')) unless taps.count > 0
|
101
|
+
taps.each do |tap|
|
102
|
+
pct = format('%3.2f', (tap['keg']['percent_full'] * 100))
|
103
|
+
response.reply(t('taps.info', id: tap['tap']['id'],
|
104
|
+
desc: tap['keg']['description'],
|
105
|
+
pct: pct))
|
106
|
+
end
|
107
|
+
else
|
108
|
+
response.reply(t('error.request'))
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def tap_status_id(response)
|
113
|
+
id = response.matches[0][0].to_i
|
114
|
+
result = api_request('get', "taps/#{id}")
|
115
|
+
if result && result['result'] && result['result']['tap']
|
116
|
+
tap = result['result']['tap']
|
117
|
+
keg = result['result']['keg']
|
118
|
+
pct = format('%3.2f', (keg['percent_full'] * 100))
|
119
|
+
response.reply(t('taps.info', id: tap['id'],
|
120
|
+
desc: keg['description'],
|
121
|
+
pct: pct))
|
122
|
+
else
|
123
|
+
response.reply(t('error.request'))
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def keg_status_all(response)
|
128
|
+
result = api_request('get', 'kegs/')
|
129
|
+
if result && result['result'] && result['result']['kegs']
|
130
|
+
kegs = result['result']['kegs']
|
131
|
+
response.reply(t('kegs.none')) unless kegs.count > 0
|
132
|
+
kegs.each do |keg|
|
133
|
+
pct = format('%3.2f', (keg['percent_full'] * 100))
|
134
|
+
response.reply(t('kegs.info', id: keg['id'],
|
135
|
+
desc: keg['description'],
|
136
|
+
status: keg['status'],
|
137
|
+
pct: pct))
|
138
|
+
end
|
139
|
+
else
|
140
|
+
response.reply(t('error.request'))
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def keg_status_id(response)
|
145
|
+
id = response.matches[0][0].to_i
|
146
|
+
result = api_request('get', "kegs/#{id}")
|
147
|
+
if result && result['result'] && result['result']['keg']
|
148
|
+
keg = result['result']['keg']
|
149
|
+
pct = format('%3.2f', (keg['percent_full'] * 100))
|
150
|
+
response.reply(t('kegs.info', id: keg['id'],
|
151
|
+
desc: keg['description'],
|
152
|
+
status: keg['status'],
|
153
|
+
pct: pct))
|
154
|
+
else
|
155
|
+
response.reply(t('error.request'))
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
private
|
160
|
+
|
161
|
+
def api_request(method, path, args = {})
|
162
|
+
if Lita.config.handlers.kegbot.api_key.nil? ||
|
163
|
+
Lita.config.handlers.kegbot.api_url.nil?
|
164
|
+
Lita.logger.error('Missing API key or Page ID for Kegbot')
|
165
|
+
fail 'Missing config'
|
166
|
+
end
|
167
|
+
|
168
|
+
url = "#{Lita.config.handlers.kegbot.api_url}/api/#{path}"
|
169
|
+
|
170
|
+
http_response = http.send(method) do |req|
|
171
|
+
req.url url, args
|
172
|
+
req.headers['X-Kegbot-Api-Key'] = \
|
173
|
+
Lita.config.handlers.kegbot.api_key
|
174
|
+
end
|
175
|
+
|
176
|
+
if http_response.status == 200 ||
|
177
|
+
http_response.status == 201
|
178
|
+
MultiJson.load(http_response.body)
|
179
|
+
else
|
180
|
+
Lita.logger.error("HTTP #{method} for #{url} with #{args} " \
|
181
|
+
"returned #{http_response.status}")
|
182
|
+
Lita.logger.error(http_response.body)
|
183
|
+
nil
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
Lita.register_handler(Kegbot)
|
189
|
+
end
|
190
|
+
end
|
data/lita-kegbot.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'lita-kegbot'
|
3
|
+
spec.version = '0.1.0'
|
4
|
+
spec.authors = ['Eric Sigler']
|
5
|
+
spec.email = ['me@esigler.com']
|
6
|
+
spec.description = %q{A Kegbot handler for Lita.io}
|
7
|
+
spec.summary = %q{A Kegbot handler for Lita.io}
|
8
|
+
spec.homepage = 'https://github.com/esigler/lita-kegbot'
|
9
|
+
spec.license = 'MIT'
|
10
|
+
spec.metadata = { 'lita_plugin_type' => 'handler' }
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split($/)
|
13
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
|
+
spec.require_paths = ['lib']
|
16
|
+
|
17
|
+
spec.add_runtime_dependency 'lita', '>= 3.0'
|
18
|
+
|
19
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
20
|
+
spec.add_development_dependency 'rake'
|
21
|
+
spec.add_development_dependency 'rspec', '>= 3.0.0.beta2'
|
22
|
+
spec.add_development_dependency 'rubocop'
|
23
|
+
spec.add_development_dependency 'simplecov'
|
24
|
+
spec.add_development_dependency 'coveralls'
|
25
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
en:
|
2
|
+
lita:
|
3
|
+
handlers:
|
4
|
+
kegbot:
|
5
|
+
drinks:
|
6
|
+
info: "%{user} poured a glass at %{date}"
|
7
|
+
none: No drinks have been poured
|
8
|
+
error:
|
9
|
+
not_implemented: Not implemented yet.
|
10
|
+
request: There was a problem with the Kegbot request
|
11
|
+
help:
|
12
|
+
drink_list:
|
13
|
+
syntax: (kegbot|kb) drink list
|
14
|
+
desc: List last 5 drinks poured
|
15
|
+
drink_list_N:
|
16
|
+
syntax: (kegbot|kb) drink list <N>
|
17
|
+
desc: List last <N> drinks poured
|
18
|
+
tap_list:
|
19
|
+
syntax: (kegbot|kb) tap list
|
20
|
+
desc: Lists taps
|
21
|
+
tap_status:
|
22
|
+
syntax: (kegbot|kb) tap status
|
23
|
+
desc: Shows status of all taps
|
24
|
+
tap_status_id:
|
25
|
+
syntax: (kegbot|kb) tap status <id>
|
26
|
+
desc: Shows status of tap <id>
|
27
|
+
keg_list:
|
28
|
+
syntax: (kegbot|kb) keg list
|
29
|
+
desc: Lists kegs (this includes kegs that are no longer connected)
|
30
|
+
keg_status:
|
31
|
+
syntax: (kegbot|kb) keg status
|
32
|
+
desc: Shows status of all kegs
|
33
|
+
keg_status_id:
|
34
|
+
syntax: (kegbot|kb) keg status <id>
|
35
|
+
desc: Shows status of keg <id>
|
36
|
+
kegs:
|
37
|
+
info: "Keg #%{id}: %{desc}, status: %{status}, %{pct}% remaining"
|
38
|
+
none: No kegs have been configured
|
39
|
+
taps:
|
40
|
+
info: "Tap #%{id}: %{desc}, %{pct}% remaining"
|
41
|
+
none: No taps have been configured
|
@@ -0,0 +1,33 @@
|
|
1
|
+
{
|
2
|
+
"result": {
|
3
|
+
"paging": {
|
4
|
+
"total": 2716,
|
5
|
+
"limit": 100,
|
6
|
+
"pos": 2000
|
7
|
+
},
|
8
|
+
"drinks": [
|
9
|
+
{
|
10
|
+
"volume_ml": 490.24793744200002,
|
11
|
+
"user_id": "capn",
|
12
|
+
"ticks": 1321,
|
13
|
+
"session_id": "386",
|
14
|
+
"is_valid": true,
|
15
|
+
"pour_time": "2009-10-03T17:13:16",
|
16
|
+
"duration": 15,
|
17
|
+
"keg_id": 13,
|
18
|
+
"id": 2000
|
19
|
+
},
|
20
|
+
{
|
21
|
+
"volume_ml": 451.651582034,
|
22
|
+
"user_id": "boysdontcall",
|
23
|
+
"ticks": 1217,
|
24
|
+
"session_id": "386",
|
25
|
+
"is_valid": true,
|
26
|
+
"pour_time": "2009-10-03T17:12:27",
|
27
|
+
"duration": 14,
|
28
|
+
"keg_id": 13,
|
29
|
+
"id": 1999
|
30
|
+
}
|
31
|
+
]
|
32
|
+
}
|
33
|
+
}
|
data/spec/files/keg.json
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
{
|
2
|
+
"result": {
|
3
|
+
"keg": {
|
4
|
+
"status": "offline",
|
5
|
+
"volume_ml_remain": 590.74554188041657,
|
6
|
+
"finished_time": "2009-10-17T19:34:06",
|
7
|
+
"description": "Racer 5",
|
8
|
+
"type_id": "50ad52bc-35fb-4441-a5bf-f56a55608057",
|
9
|
+
"started_time": "2009-09-06T14:46:00",
|
10
|
+
"size_id": 1,
|
11
|
+
"percent_full": 0.010068330147789123,
|
12
|
+
"id": 13
|
13
|
+
},
|
14
|
+
"type": {
|
15
|
+
"name": "Racer 5",
|
16
|
+
"style_id": "8afc60f5-2ee0-40a2-a53a-39c6f43ed4bf",
|
17
|
+
"calories_oz": 12.5,
|
18
|
+
"abv": 7.2000000000000002,
|
19
|
+
"brewer_id": "4360bae4-5522-4fca-8e3a-0edebfc457a5",
|
20
|
+
"id": "50ad52bc-35fb-4441-a5bf-f56a55608057"
|
21
|
+
},
|
22
|
+
"size": {
|
23
|
+
"volume_ml": 58673.636363636397,
|
24
|
+
"id": 1,
|
25
|
+
"name": "15.5 gallon keg"
|
26
|
+
},
|
27
|
+
"drinks": [
|
28
|
+
{
|
29
|
+
"volume_ml": 55.667820300000002,
|
30
|
+
"user_id": "scarfjerk",
|
31
|
+
"ticks": 150,
|
32
|
+
"session_id": "390",
|
33
|
+
"is_valid": true,
|
34
|
+
"pour_time": "2009-10-17T19:34:06",
|
35
|
+
"duration": 7,
|
36
|
+
"keg_id": 13,
|
37
|
+
"id": 2054
|
38
|
+
},
|
39
|
+
{
|
40
|
+
"volume_ml": 441.63137438000001,
|
41
|
+
"user_id": null,
|
42
|
+
"ticks": 1190,
|
43
|
+
"session_id": "390",
|
44
|
+
"is_valid": true,
|
45
|
+
"user": null,
|
46
|
+
"pour_time": "2009-10-17T19:02:55",
|
47
|
+
"duration": 11,
|
48
|
+
"keg_id": 13,
|
49
|
+
"id": 2053
|
50
|
+
}
|
51
|
+
]
|
52
|
+
}
|
53
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
{
|
2
|
+
"result": {
|
3
|
+
"kegs": [
|
4
|
+
{
|
5
|
+
"status": "online",
|
6
|
+
"volume_ml_remain": 299.24664065039542,
|
7
|
+
"finished_time": "2010-06-11T23:25:16",
|
8
|
+
"description": "Celebrating the World Cup, and international relations, with a beer that's part Austria / part Berkeley.",
|
9
|
+
"type_id": "20bd3f32-75eb-11df-80f2-00304833977c",
|
10
|
+
"started_time": "2010-06-11T23:25:16",
|
11
|
+
"size_id": 1,
|
12
|
+
"percent_full": 0.0051001891001911156,
|
13
|
+
"id": 17
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"status": "offline",
|
17
|
+
"volume_ml_remain": -13363.120936177656,
|
18
|
+
"finished_time": "2010-05-29T13:01:20",
|
19
|
+
"description": "Racer 5",
|
20
|
+
"type_id": "e29a5d90-6b5c-11df-bcbc-00304833977c",
|
21
|
+
"started_time": "2010-05-29T13:01:20",
|
22
|
+
"size_id": 1,
|
23
|
+
"percent_full": -0.22775341302110927,
|
24
|
+
"id": 16
|
25
|
+
}
|
26
|
+
]
|
27
|
+
}
|
28
|
+
}
|
data/spec/files/tap.json
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
{
|
2
|
+
"result": {
|
3
|
+
"keg": {
|
4
|
+
"status": "online",
|
5
|
+
"volume_ml_remain": 299.24664065039542,
|
6
|
+
"finished_time": "2010-06-11T23:25:16",
|
7
|
+
"description": "Racer 5",
|
8
|
+
"type_id": "20bd3f32-75eb-11df-80f2-00304833977c",
|
9
|
+
"started_time": "2010-06-11T23:25:16",
|
10
|
+
"size_id": 1,
|
11
|
+
"percent_full": 0.0051001891001911156,
|
12
|
+
"id": 17
|
13
|
+
},
|
14
|
+
"tap": {
|
15
|
+
"meter_name": "kegboard.flow0",
|
16
|
+
"name": "main tap",
|
17
|
+
"ml_per_tick": 0.37111880200000003,
|
18
|
+
"thermo_sensor_id": "1",
|
19
|
+
"current_keg_id": 17,
|
20
|
+
"id": "1"
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"result": {
|
3
|
+
"taps": [
|
4
|
+
{
|
5
|
+
"keg": {
|
6
|
+
"status": "online",
|
7
|
+
"volume_ml_remain": 299.24664065039542,
|
8
|
+
"finished_time": "2010-06-11T23:25:16",
|
9
|
+
"description": "Racer 5",
|
10
|
+
"type_id": "20bd3f32-75eb-11df-80f2-00304833977c",
|
11
|
+
"started_time": "2010-06-11T23:25:16",
|
12
|
+
"size_id": 1,
|
13
|
+
"percent_full": 0.0051001891001911156,
|
14
|
+
"id": 17
|
15
|
+
},
|
16
|
+
"tap": {
|
17
|
+
"meter_name": "kegboard.flow0",
|
18
|
+
"name": "main tap",
|
19
|
+
"ml_per_tick": 0.37111880200000003,
|
20
|
+
"thermo_sensor_id": "1",
|
21
|
+
"current_keg_id": 17,
|
22
|
+
"id": "1"
|
23
|
+
}
|
24
|
+
}
|
25
|
+
]
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,198 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lita::Handlers::Kegbot, lita_handler: true do
|
4
|
+
let(:drinks) do
|
5
|
+
File.read('spec/files/drinks.json')
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:drinks_empty) do
|
9
|
+
File.read('spec/files/drinks_empty.json')
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:taps) do
|
13
|
+
File.read('spec/files/taps.json')
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:taps_empty) do
|
17
|
+
File.read('spec/files/taps_empty.json')
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:tap) do
|
21
|
+
File.read('spec/files/tap.json')
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:kegs) do
|
25
|
+
File.read('spec/files/kegs.json')
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:kegs_empty) do
|
29
|
+
File.read('spec/files/kegs_empty.json')
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:keg) do
|
33
|
+
File.read('spec/files/keg.json')
|
34
|
+
end
|
35
|
+
|
36
|
+
it { routes_command('kegbot drink list').to(:drink_list_all) }
|
37
|
+
it { routes_command('kegbot drink list 10').to(:drink_list) }
|
38
|
+
it { routes_command('kegbot tap status').to(:tap_status_all) }
|
39
|
+
it { routes_command('kegbot tap status 1').to(:tap_status_id) }
|
40
|
+
it { routes_command('kegbot keg status').to(:keg_status_all) }
|
41
|
+
it { routes_command('kegbot keg status 1').to(:keg_status_id) }
|
42
|
+
|
43
|
+
it { routes_command('kb drink list').to(:drink_list_all) }
|
44
|
+
it { routes_command('kb drink list 10').to(:drink_list) }
|
45
|
+
it { routes_command('kb tap status').to(:tap_status_all) }
|
46
|
+
it { routes_command('kb tap status 1').to(:tap_status_id) }
|
47
|
+
it { routes_command('kb keg status').to(:keg_status_all) }
|
48
|
+
it { routes_command('kb keg status 1').to(:keg_status_id) }
|
49
|
+
|
50
|
+
def grab_request(method, status, body)
|
51
|
+
response = double('Faraday::Response', status: status, body: body)
|
52
|
+
expect_any_instance_of(Faraday::Connection).to \
|
53
|
+
receive(method.to_sym).and_return(response)
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'without valid config' do
|
57
|
+
before do
|
58
|
+
Lita.config.handlers.kegbot.api_key = nil
|
59
|
+
Lita.config.handlers.kegbot.api_url = nil
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '.default_config' do
|
63
|
+
it 'sets api_key to nil' do
|
64
|
+
expect(Lita.config.handlers.kegbot.api_key).to be_nil
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'sets api_url to nil' do
|
68
|
+
expect(Lita.config.handlers.kegbot.api_url).to be_nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should error out on any command' do
|
73
|
+
expect { send_command('kb tap status') }.to raise_error('Missing config')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
before do
|
78
|
+
Lita.config.handlers.kegbot.api_key = 'foo'
|
79
|
+
Lita.config.handlers.kegbot.api_url = 'https://example.com'
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#drink_list_all' do
|
83
|
+
it 'shows a list of drinks if there are any' do
|
84
|
+
grab_request('get', 200, drinks)
|
85
|
+
send_command('kegbot drink list')
|
86
|
+
expect(replies.last).to eq('boysdontcall poured a glass at ' \
|
87
|
+
'2009-10-03T17:12:27')
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'shows an empty list if there arent any' do
|
91
|
+
grab_request('get', 200, drinks_empty)
|
92
|
+
send_command('kegbot drink list')
|
93
|
+
expect(replies.last).to eq('No drinks have been poured')
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'shows an error if there was a problem with the request' do
|
97
|
+
grab_request('get', 500, nil)
|
98
|
+
send_command('kegbot drink list')
|
99
|
+
expect(replies.last).to eq('There was a problem with the Kegbot request')
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe '#drink_list' do
|
104
|
+
it 'shows the correct number of drinks if there are that many' do
|
105
|
+
grab_request('get', 200, drinks)
|
106
|
+
send_command('kegbot drink list 1')
|
107
|
+
expect(replies.count).to eq(1)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'shows an error if there was a problem with the request' do
|
111
|
+
grab_request('get', 500, nil)
|
112
|
+
send_command('kegbot drink list 2')
|
113
|
+
expect(replies.last).to eq('There was a problem with the Kegbot request')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '#tap_status_all' do
|
118
|
+
it 'shows the status of all of the taps if there are any' do
|
119
|
+
grab_request('get', 200, taps)
|
120
|
+
send_command('kegbot tap status')
|
121
|
+
expect(replies.last).to eq('Tap #1: Racer 5, 0.51% remaining')
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'shows an empty list if there arent any' do
|
125
|
+
grab_request('get', 200, taps_empty)
|
126
|
+
send_command('kegbot tap status')
|
127
|
+
expect(replies.last).to eq('No taps have been configured')
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'shows an error if there was a problem with the request' do
|
131
|
+
grab_request('get', 500, nil)
|
132
|
+
send_command('kegbot tap status')
|
133
|
+
expect(replies.last).to eq('There was a problem with the Kegbot request')
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '#tap_status_id' do
|
138
|
+
it 'shows the status of a specific tap' do
|
139
|
+
grab_request('get', 200, tap)
|
140
|
+
send_command('kegbot tap status 1')
|
141
|
+
expect(replies.last).to eq('Tap #1: Racer 5, 0.51% remaining')
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'shows a warning if that tap does not exist' do
|
145
|
+
grab_request('get', 404, nil)
|
146
|
+
send_command('kegbot tap status 1')
|
147
|
+
expect(replies.last).to eq('There was a problem with the Kegbot request')
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'shows an error if there was a problem with the request' do
|
151
|
+
grab_request('get', 500, nil)
|
152
|
+
send_command('kegbot tap status 1')
|
153
|
+
expect(replies.last).to eq('There was a problem with the Kegbot request')
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe '#keg_status_all' do
|
158
|
+
it 'shows the status of all of the kegs if there are any' do
|
159
|
+
grab_request('get', 200, kegs)
|
160
|
+
send_command('kegbot keg status')
|
161
|
+
expect(replies.last).to eq('Keg #16: Racer 5, status: offline, ' \
|
162
|
+
'-22.78% remaining')
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'shows an empty list if there arent any' do
|
166
|
+
grab_request('get', 200, kegs_empty)
|
167
|
+
send_command('kegbot keg status')
|
168
|
+
expect(replies.last).to eq('No kegs have been configured')
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'shows an error if there was a problem with the request' do
|
172
|
+
grab_request('get', 500, nil)
|
173
|
+
send_command('kegbot keg status')
|
174
|
+
expect(replies.last).to eq('There was a problem with the Kegbot request')
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe '#keg_status_id' do
|
179
|
+
it 'shows the status of a specific keg' do
|
180
|
+
grab_request('get', 200, keg)
|
181
|
+
send_command('kegbot keg status 1')
|
182
|
+
expect(replies.last).to eq('Keg #13: Racer 5, status: offline, ' \
|
183
|
+
'1.01% remaining')
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'shows a warning if that keg does not exist' do
|
187
|
+
grab_request('get', 404, nil)
|
188
|
+
send_command('kegbot keg status 1')
|
189
|
+
expect(replies.last).to eq('There was a problem with the Kegbot request')
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'shows an error if there was a problem with the request' do
|
193
|
+
grab_request('get', 500, nil)
|
194
|
+
send_command('kegbot keg status 1')
|
195
|
+
expect(replies.last).to eq('There was a problem with the Kegbot request')
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
4
|
+
SimpleCov::Formatter::HTMLFormatter,
|
5
|
+
Coveralls::SimpleCov::Formatter
|
6
|
+
]
|
7
|
+
SimpleCov.start { add_filter '/spec/' }
|
8
|
+
|
9
|
+
require 'lita-kegbot'
|
10
|
+
require 'lita/rspec'
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-kegbot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Sigler
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: lita
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0.beta2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.0.beta2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coveralls
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: A Kegbot handler for Lita.io
|
112
|
+
email:
|
113
|
+
- me@esigler.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rubocop.yml"
|
120
|
+
- ".travis.yml"
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- lib/lita-kegbot.rb
|
126
|
+
- lib/lita/handlers/kegbot.rb
|
127
|
+
- lita-kegbot.gemspec
|
128
|
+
- locales/en.yml
|
129
|
+
- spec/files/drinks.json
|
130
|
+
- spec/files/drinks_empty.json
|
131
|
+
- spec/files/keg.json
|
132
|
+
- spec/files/kegs.json
|
133
|
+
- spec/files/kegs_empty.json
|
134
|
+
- spec/files/tap.json
|
135
|
+
- spec/files/taps.json
|
136
|
+
- spec/files/taps_empty.json
|
137
|
+
- spec/lita/handlers/kegbot_spec.rb
|
138
|
+
- spec/spec_helper.rb
|
139
|
+
homepage: https://github.com/esigler/lita-kegbot
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata:
|
143
|
+
lita_plugin_type: handler
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.2.2
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: A Kegbot handler for Lita.io
|
164
|
+
test_files:
|
165
|
+
- spec/files/drinks.json
|
166
|
+
- spec/files/drinks_empty.json
|
167
|
+
- spec/files/keg.json
|
168
|
+
- spec/files/kegs.json
|
169
|
+
- spec/files/kegs_empty.json
|
170
|
+
- spec/files/tap.json
|
171
|
+
- spec/files/taps.json
|
172
|
+
- spec/files/taps_empty.json
|
173
|
+
- spec/lita/handlers/kegbot_spec.rb
|
174
|
+
- spec/spec_helper.rb
|