lita-kegbot 0.3.0 → 1.0.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 +4 -4
- data/.rubocop.yml +5 -6
- data/.travis.yml +1 -1
- data/CONTRIBUTING.md +9 -0
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/Rakefile +2 -2
- data/lib/lita/handlers/kegbot.rb +52 -78
- data/lita-kegbot.gemspec +8 -8
- data/spec/lita/handlers/kegbot_spec.rb +10 -34
- data/spec/spec_helper.rb +2 -0
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 351fd2596c187b9739412825dd59ed3d4528b0a7
|
4
|
+
data.tar.gz: 5b177d8c0d54a17fca2c3aedf8d4258f52fa5620
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98efc4a96b7d2bdb0e60a0c3fb830b75aeb9b679ad5ee75b1ba4d03829d43aff7210cb38b728616b9903f29d0ce104e445225d83c8ca21e2e85915b2139ed6b1
|
7
|
+
data.tar.gz: d458e6d9377e2a85561b39dd370fec4441323b244662d6f3095348a43b53ae6fdf42d5d71ccd957d2cf36e108312be61671cf39b8b8acb9f1fd41be6058dbeaa
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
Pull requests are awesome! Pull requests with tests are even more awesome!
|
2
|
+
|
3
|
+
## Quick steps
|
4
|
+
|
5
|
+
1. Fork the repo.
|
6
|
+
2. Run the tests: `bundle && rake`
|
7
|
+
3. Add a test for your change. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, it needs a test!
|
8
|
+
4. Make the test pass.
|
9
|
+
5. Push to your fork and submit a pull request.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
[](https://codeclimate.com/github/esigler/lita-kegbot)
|
8
8
|
[](https://gemnasium.com/esigler/lita-kegbot)
|
9
9
|
|
10
|
-
A Kegbot
|
10
|
+
A [Kegbot](https://kegbot.org) plugin for [Lita](https://github.com/jimmycuadra/lita).
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
data/Rakefile
CHANGED
data/lib/lita/handlers/kegbot.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
module Lita
|
2
2
|
module Handlers
|
3
3
|
class Kegbot < Handler
|
4
|
+
config :api_key, required: true
|
5
|
+
config :api_url, required: true
|
6
|
+
|
4
7
|
route(
|
5
|
-
/^(?:kegbot|kb)\s(?:drink|drinks)\slist(
|
8
|
+
/^(?:kegbot|kb)\s(?:drink|drinks)\slist(?<c>\s\d+)?$/,
|
6
9
|
:drink_list,
|
7
10
|
command: true,
|
8
11
|
help: {
|
@@ -46,89 +49,70 @@ module Lita
|
|
46
49
|
}
|
47
50
|
)
|
48
51
|
|
49
|
-
|
50
|
-
config.api_key = nil
|
51
|
-
config.api_url = nil
|
52
|
-
end
|
53
|
-
|
52
|
+
# rubocop:disable Metrics/AbcSize
|
54
53
|
def drink_list(response)
|
55
|
-
|
56
|
-
count_match ? count = count_match.to_i : count = 5
|
57
|
-
current = 0
|
54
|
+
count = response.match_data['c'] ? response.match_data['c'].to_i : 5
|
58
55
|
drinks = fetch_drinks
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
response.reply(t('drinks.info', user: drink['user_id'],
|
66
|
-
beer: beer,
|
67
|
-
date: formatted_date))
|
68
|
-
current += 1
|
69
|
-
end
|
70
|
-
end
|
71
|
-
else
|
72
|
-
response.reply(t('error.request'))
|
56
|
+
|
57
|
+
return response.reply(t('error.request')) unless drinks
|
58
|
+
return response.reply(t('drinks.none')) unless drinks.count > 0
|
59
|
+
|
60
|
+
count.times do |i|
|
61
|
+
response.reply(format_drink(drinks[i])) if drinks[i]
|
73
62
|
end
|
74
63
|
end
|
64
|
+
# rubocop:enable Metrics/AbcSize
|
75
65
|
|
76
66
|
def tap_status_all(response)
|
77
67
|
taps = fetch_taps
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
83
|
-
else
|
84
|
-
response.reply(t('error.request'))
|
68
|
+
return response.reply(t('error.request')) unless taps
|
69
|
+
return response.reply(t('taps.none')) unless taps.count > 0
|
70
|
+
taps.each do |tap|
|
71
|
+
response.reply(t('taps.info', id: tap['id'], name: tap['name']))
|
85
72
|
end
|
86
73
|
end
|
87
74
|
|
88
75
|
def tap_status_id(response)
|
89
76
|
tap = fetch_tap(response.matches[0][0].to_i)
|
90
|
-
|
91
|
-
|
92
|
-
else
|
93
|
-
response.reply(t('error.request'))
|
94
|
-
end
|
77
|
+
return response.reply(t('error.request')) unless tap
|
78
|
+
response.reply(t('taps.info', id: tap['id'], name: tap['name']))
|
95
79
|
end
|
96
80
|
|
97
81
|
def keg_status_all(response)
|
98
82
|
kegs = fetch_kegs
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
pct = format('%3.2f', keg['percent_full'])
|
105
|
-
response.reply(t('kegs.info', id: keg['id'],
|
106
|
-
beer: keg['beverage']['name'],
|
107
|
-
status: status,
|
108
|
-
pct: pct))
|
109
|
-
end
|
110
|
-
end
|
111
|
-
else
|
112
|
-
response.reply(t('error.request'))
|
83
|
+
return response.reply(t('error.request')) unless kegs
|
84
|
+
return response.reply(t('kegs.none')) unless kegs.count > 0
|
85
|
+
kegs.each do |keg|
|
86
|
+
next unless keg['online']
|
87
|
+
response.reply(format_keg(keg))
|
113
88
|
end
|
114
89
|
end
|
115
90
|
|
116
91
|
def keg_status_id(response)
|
117
92
|
keg = fetch_keg(response.matches[0][0].to_i)
|
118
|
-
|
119
|
-
|
120
|
-
pct = format('%3.2f', keg['percent_full'])
|
121
|
-
response.reply(t('kegs.info', id: keg['id'],
|
122
|
-
beer: keg['beverage']['name'],
|
123
|
-
status: status,
|
124
|
-
pct: pct))
|
125
|
-
else
|
126
|
-
response.reply(t('error.request'))
|
127
|
-
end
|
93
|
+
return response.reply(t('error.request')) unless keg
|
94
|
+
response.reply(format_keg(keg))
|
128
95
|
end
|
129
96
|
|
130
97
|
private
|
131
98
|
|
99
|
+
def format_drink(drink)
|
100
|
+
formatted_date = drink['session']['start_time']
|
101
|
+
beer = drink['keg']['beverage']['name']
|
102
|
+
t('drinks.info', user: drink['user_id'],
|
103
|
+
beer: beer,
|
104
|
+
date: formatted_date)
|
105
|
+
end
|
106
|
+
|
107
|
+
def format_keg(keg)
|
108
|
+
keg['online'] ? status = 'online' : status = 'offline'
|
109
|
+
pct = format('%3.2f', keg['percent_full'])
|
110
|
+
t('kegs.info', id: keg['id'],
|
111
|
+
beer: keg['beverage']['name'],
|
112
|
+
status: status,
|
113
|
+
pct: pct)
|
114
|
+
end
|
115
|
+
|
132
116
|
def fetch_drinks
|
133
117
|
result = api_request('get', 'drinks/')
|
134
118
|
result['objects'] if result && result['objects']
|
@@ -154,31 +138,21 @@ module Lita
|
|
154
138
|
result['objects'] if result && result['objects']
|
155
139
|
end
|
156
140
|
|
141
|
+
# rubocop:disable Metrics/AbcSize
|
157
142
|
def api_request(method, path, args = {})
|
158
|
-
if Lita.config.handlers.kegbot.api_key.nil? ||
|
159
|
-
Lita.config.handlers.kegbot.api_url.nil?
|
160
|
-
Lita.logger.error('Missing API key or Page ID for Kegbot')
|
161
|
-
fail 'Missing config'
|
162
|
-
end
|
163
|
-
|
164
|
-
url = "#{Lita.config.handlers.kegbot.api_url}/api/#{path}"
|
165
|
-
|
166
143
|
http_response = http.send(method) do |req|
|
167
|
-
req.url
|
168
|
-
req.headers['X-Kegbot-Api-Key'] =
|
169
|
-
Lita.config.handlers.kegbot.api_key
|
144
|
+
req.url "#{config.api_url}/api/#{path}", args
|
145
|
+
req.headers['X-Kegbot-Api-Key'] = config.api_key
|
170
146
|
end
|
171
147
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
else
|
176
|
-
Lita.logger.error("HTTP #{method} for #{url} with #{args} " \
|
177
|
-
"returned #{http_response.status}")
|
178
|
-
Lita.logger.error(http_response.body)
|
179
|
-
nil
|
148
|
+
unless http_response.status == 200 || http_response.status == 201
|
149
|
+
log.error("#{method}:#{path}:#{args}:#{http_response.status}")
|
150
|
+
return nil
|
180
151
|
end
|
152
|
+
|
153
|
+
MultiJson.load(http_response.body)
|
181
154
|
end
|
155
|
+
# rubocop:enable Metrics/AbcSize
|
182
156
|
end
|
183
157
|
|
184
158
|
Lita.register_handler(Kegbot)
|
data/lita-kegbot.gemspec
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'lita-kegbot'
|
3
|
-
spec.version = '0.
|
3
|
+
spec.version = '1.0.0'
|
4
4
|
spec.authors = ['Eric Sigler']
|
5
5
|
spec.email = ['me@esigler.com']
|
6
|
-
spec.description =
|
7
|
-
spec.summary =
|
6
|
+
spec.description = 'A Kegbot plugin for Lita'
|
7
|
+
spec.summary = 'A Kegbot plugin for Lita'
|
8
8
|
spec.homepage = 'https://github.com/esigler/lita-kegbot'
|
9
9
|
spec.license = 'MIT'
|
10
10
|
spec.metadata = { 'lita_plugin_type' => 'handler' }
|
11
11
|
|
12
|
-
spec.files = `git ls-files`.split(
|
13
|
-
spec.executables = spec.files.grep(
|
14
|
-
spec.test_files = spec.files.grep(
|
12
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
13
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
15
15
|
spec.require_paths = ['lib']
|
16
16
|
|
17
|
-
spec.add_runtime_dependency 'lita', '>=
|
17
|
+
spec.add_runtime_dependency 'lita', '>= 4.0'
|
18
18
|
|
19
19
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
20
20
|
spec.add_development_dependency 'rake'
|
21
|
-
spec.add_development_dependency 'rspec', '>= 3.0.0
|
21
|
+
spec.add_development_dependency 'rspec', '>= 3.0.0'
|
22
22
|
spec.add_development_dependency 'rubocop'
|
23
23
|
spec.add_development_dependency 'simplecov'
|
24
24
|
spec.add_development_dependency 'coveralls'
|
@@ -33,19 +33,16 @@ describe Lita::Handlers::Kegbot, lita_handler: true do
|
|
33
33
|
File.read('spec/files/keg.json')
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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) }
|
36
|
+
%w(kegbot kb).each do |name|
|
37
|
+
it do
|
38
|
+
is_expected.to route_command("#{name} drink list").to(:drink_list)
|
39
|
+
is_expected.to route_command("#{name} drink list 10").to(:drink_list)
|
40
|
+
is_expected.to route_command("#{name} tap status").to(:tap_status_all)
|
41
|
+
is_expected.to route_command("#{name} tap status 1").to(:tap_status_id)
|
42
|
+
is_expected.to route_command("#{name} keg status").to(:keg_status_all)
|
43
|
+
is_expected.to route_command("#{name} keg status 1").to(:keg_status_id)
|
44
|
+
end
|
45
|
+
end
|
49
46
|
|
50
47
|
def grab_request(method, status, body)
|
51
48
|
response = double('Faraday::Response', status: status, body: body)
|
@@ -53,27 +50,6 @@ describe Lita::Handlers::Kegbot, lita_handler: true do
|
|
53
50
|
receive(method.to_sym).and_return(response)
|
54
51
|
end
|
55
52
|
|
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
53
|
before do
|
78
54
|
Lita.config.handlers.kegbot.api_key = 'foo'
|
79
55
|
Lita.config.handlers.kegbot.api_url = 'https://example.com'
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-kegbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Sigler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.0.0
|
61
|
+
version: 3.0.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 3.0.0
|
68
|
+
version: 3.0.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rubocop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
-
description: A Kegbot
|
111
|
+
description: A Kegbot plugin for Lita
|
112
112
|
email:
|
113
113
|
- me@esigler.com
|
114
114
|
executables: []
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- ".gitignore"
|
119
119
|
- ".rubocop.yml"
|
120
120
|
- ".travis.yml"
|
121
|
+
- CONTRIBUTING.md
|
121
122
|
- Gemfile
|
122
123
|
- LICENSE
|
123
124
|
- README.md
|
@@ -162,7 +163,7 @@ rubyforge_project:
|
|
162
163
|
rubygems_version: 2.2.2
|
163
164
|
signing_key:
|
164
165
|
specification_version: 4
|
165
|
-
summary: A Kegbot
|
166
|
+
summary: A Kegbot plugin for Lita
|
166
167
|
test_files:
|
167
168
|
- spec/files/drinks.json
|
168
169
|
- spec/files/drinks_empty.json
|