lita-kegbot 0.2.0 → 0.3.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: dbe0e8c14e5b7b7a03a5c41d347e047a90c4addb
4
- data.tar.gz: 6fc87df5733ba261d0ac1f5cd4f00d71d8d193c5
3
+ metadata.gz: f377744672faacfb1dd8eb24044eeb4051a7f033
4
+ data.tar.gz: d6b41a95f2e133eee66e5767987e550fe6d8dc81
5
5
  SHA512:
6
- metadata.gz: cc63abe6ef50aa448ceb159cf86076c05ead14f010dc717486e73194c874b6d5653c4c6f85364d16f2ccf9e35a159d7d42ccfebc18960dc2fe5eba3237790a00
7
- data.tar.gz: 05b18f5f48934e07824988d76abc2e4a32fef542fdbd905d9fdc8c29e89cc0f3b3564eabe2374c9620300ed5a6952a144f748a3dc25076fd07daa983755d90a6
6
+ metadata.gz: bc8141444f4cbbb04de03fc93990a1c08824d24dcf25c2b737552ba0da0f7dcbfda6f30c29c3f93100b3378665e9e9f709b3f00b591c22d48e31095f8412347b
7
+ data.tar.gz: e784489a0972fb0f3eebd5e7d33ddc01ed11895051349a886e615cbaf0b837186c67a12dbb3fce73b95420bf0e43afbcb51c4de5ddda0410fe4b118227578bf1
@@ -2,25 +2,16 @@ module Lita
2
2
  module Handlers
3
3
  class Kegbot < Handler
4
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+)$/,
5
+ /^(?:kegbot|kb)\s(?:drink|drinks)\slist(\s\d+)*$/,
15
6
  :drink_list,
16
7
  command: true,
17
8
  help: {
18
- t('help.drink_list_N.syntax') => t('help.drink_list_N.desc')
9
+ t('help.drink_list.syntax') => t('help.drink_list.desc')
19
10
  }
20
11
  )
21
12
 
22
13
  route(
23
- /^(?:kegbot|kb)\stap\sstatus$/,
14
+ /^(?:kegbot|kb)\s(?:tap|taps)\sstatus$/,
24
15
  :tap_status_all,
25
16
  command: true,
26
17
  help: {
@@ -29,7 +20,7 @@ module Lita
29
20
  )
30
21
 
31
22
  route(
32
- /^(?:kegbot|kb)\stap\sstatus\s(\d+)$/,
23
+ /^(?:kegbot|kb)\s(?:tap|taps)\sstatus\s(\d+)$/,
33
24
  :tap_status_id,
34
25
  command: true,
35
26
  help: {
@@ -38,7 +29,7 @@ module Lita
38
29
  )
39
30
 
40
31
  route(
41
- /^(?:kegbot|kb)\skeg\sstatus$/,
32
+ /^(?:kegbot|kb)\s(?:keg|kegs)\sstatus$/,
42
33
  :keg_status_all,
43
34
  command: true,
44
35
  help: {
@@ -47,7 +38,7 @@ module Lita
47
38
  )
48
39
 
49
40
  route(
50
- /^(?:kegbot|kb)\skeg\sstatus\s(\d+)$/,
41
+ /^(?:kegbot|kb)\s(?:keg|kegs)\sstatus\s(\d+)$/,
51
42
  :keg_status_id,
52
43
  command: true,
53
44
  help: {
@@ -60,32 +51,20 @@ module Lita
60
51
  config.api_url = nil
61
52
  end
62
53
 
63
- def drink_list_all(response)
64
- result = api_request('get', 'drinks/')
65
- if result && result['objects']
66
- drinks = result['objects']
67
- response.reply(t('drinks.none')) unless drinks.count > 0
68
- drinks.each do |drink|
69
- session = drink['session']
70
- response.reply(t('drinks.info', user: drink['user_id'],
71
- date: session['start_time']))
72
- end
73
- else
74
- response.reply(t('error.request'))
75
- end
76
- end
77
-
78
54
  def drink_list(response)
79
- count = response.matches[0][0].to_i
55
+ count_match = response.matches[0][0]
56
+ count_match ? count = count_match.to_i : count = 5
80
57
  current = 0
81
- result = api_request('get', 'drinks')
82
- if result && result['result'] && result['result']['drinks']
83
- drinks = result['result']['drinks']
58
+ drinks = fetch_drinks
59
+ if drinks
84
60
  response.reply(t('drinks.none')) unless drinks.count > 0
85
61
  drinks.each do |drink|
86
62
  if current < count
63
+ formatted_date = drink['session']['start_time']
64
+ beer = drink['keg']['beverage']['name']
87
65
  response.reply(t('drinks.info', user: drink['user_id'],
88
- date: drink['pour_time']))
66
+ beer: beer,
67
+ date: formatted_date))
89
68
  current += 1
90
69
  end
91
70
  end
@@ -95,9 +74,8 @@ module Lita
95
74
  end
96
75
 
97
76
  def tap_status_all(response)
98
- result = api_request('get', 'taps/')
99
- if result && result['objects']
100
- taps = result['objects']
77
+ taps = fetch_taps
78
+ if taps
101
79
  response.reply(t('taps.none')) unless taps.count > 0
102
80
  taps.each do |tap|
103
81
  response.reply(t('taps.info', id: tap['id'], name: tap['name']))
@@ -108,10 +86,8 @@ module Lita
108
86
  end
109
87
 
110
88
  def tap_status_id(response)
111
- id = response.matches[0][0].to_i
112
- result = api_request('get', "taps/#{id}")
113
- if result && result['object']
114
- tap = result['object']
89
+ tap = fetch_tap(response.matches[0][0].to_i)
90
+ if tap
115
91
  response.reply(t('taps.info', id: tap['id'], name: tap['name']))
116
92
  else
117
93
  response.reply(t('error.request'))
@@ -119,16 +95,18 @@ module Lita
119
95
  end
120
96
 
121
97
  def keg_status_all(response)
122
- result = api_request('get', 'kegs/')
123
- if result && result['objects']
124
- kegs = result['objects']
98
+ kegs = fetch_kegs
99
+ if kegs
125
100
  response.reply(t('kegs.none')) unless kegs.count > 0
126
101
  kegs.each do |keg|
127
- keg['status'] ? status = 'offline' : status = 'online'
128
- response.reply(t('kegs.info', id: keg['id'],
129
- beer: keg['beverage']['name'],
130
- status: status,
131
- pct: keg['percent_full']))
102
+ if keg['online']
103
+ keg['online'] ? status = 'online' : status = 'offline'
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
132
110
  end
133
111
  else
134
112
  response.reply(t('error.request'))
@@ -136,15 +114,14 @@ module Lita
136
114
  end
137
115
 
138
116
  def keg_status_id(response)
139
- id = response.matches[0][0].to_i
140
- result = api_request('get', "kegs/#{id}")
141
- if result && result['object']
142
- keg = result['object']
143
- keg['status'] ? status = 'offline' : status = 'online'
117
+ keg = fetch_keg(response.matches[0][0].to_i)
118
+ if keg
119
+ keg['online'] ? status = 'online' : status = 'offline'
120
+ pct = format('%3.2f', keg['percent_full'])
144
121
  response.reply(t('kegs.info', id: keg['id'],
145
122
  beer: keg['beverage']['name'],
146
123
  status: status,
147
- pct: keg['percent_full']))
124
+ pct: pct))
148
125
  else
149
126
  response.reply(t('error.request'))
150
127
  end
@@ -152,6 +129,31 @@ module Lita
152
129
 
153
130
  private
154
131
 
132
+ def fetch_drinks
133
+ result = api_request('get', 'drinks/')
134
+ result['objects'] if result && result['objects']
135
+ end
136
+
137
+ def fetch_tap(id)
138
+ result = api_request('get', "taps/#{id}")
139
+ result['object'] if result && result['object']
140
+ end
141
+
142
+ def fetch_taps
143
+ result = api_request('get', 'taps/')
144
+ result['objects'] if result && result['objects']
145
+ end
146
+
147
+ def fetch_keg(id)
148
+ result = api_request('get', "kegs/#{id}")
149
+ result['object'] if result && result['object']
150
+ end
151
+
152
+ def fetch_kegs
153
+ result = api_request('get', 'kegs/')
154
+ result['objects'] if result && result['objects']
155
+ end
156
+
155
157
  def api_request(method, path, args = {})
156
158
  if Lita.config.handlers.kegbot.api_key.nil? ||
157
159
  Lita.config.handlers.kegbot.api_url.nil?
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-kegbot'
3
- spec.version = '0.2.0'
3
+ spec.version = '0.3.0'
4
4
  spec.authors = ['Eric Sigler']
5
5
  spec.email = ['me@esigler.com']
6
6
  spec.description = %q{A Kegbot handler for Lita.io}
@@ -3,18 +3,15 @@ en:
3
3
  handlers:
4
4
  kegbot:
5
5
  drinks:
6
- info: "%{user} poured a glass at %{date}"
6
+ info: "%{user} poured a refreshing glass of %{beer} at %{date}"
7
7
  none: No drinks have been poured
8
8
  error:
9
9
  not_implemented: Not implemented yet.
10
10
  request: There was a problem with the Kegbot request
11
11
  help:
12
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
13
+ syntax: (kegbot|kb) drink list [N]
14
+ desc: List last [N] drinks poured, defaults to 5
18
15
  tap_list:
19
16
  syntax: (kegbot|kb) tap list
20
17
  desc: Lists taps
@@ -33,14 +33,14 @@ describe Lita::Handlers::Kegbot, lita_handler: true do
33
33
  File.read('spec/files/keg.json')
34
34
  end
35
35
 
36
- it { routes_command('kegbot drink list').to(:drink_list_all) }
36
+ it { routes_command('kegbot drink list').to(:drink_list) }
37
37
  it { routes_command('kegbot drink list 10').to(:drink_list) }
38
38
  it { routes_command('kegbot tap status').to(:tap_status_all) }
39
39
  it { routes_command('kegbot tap status 1').to(:tap_status_id) }
40
40
  it { routes_command('kegbot keg status').to(:keg_status_all) }
41
41
  it { routes_command('kegbot keg status 1').to(:keg_status_id) }
42
42
 
43
- it { routes_command('kb drink list').to(:drink_list_all) }
43
+ it { routes_command('kb drink list').to(:drink_list) }
44
44
  it { routes_command('kb drink list 10').to(:drink_list) }
45
45
  it { routes_command('kb tap status').to(:tap_status_all) }
46
46
  it { routes_command('kb tap status 1').to(:tap_status_id) }
@@ -79,34 +79,26 @@ describe Lita::Handlers::Kegbot, lita_handler: true do
79
79
  Lita.config.handlers.kegbot.api_url = 'https://example.com'
80
80
  end
81
81
 
82
- describe '#drink_list_all' do
82
+ describe '#drink_list' do
83
83
  it 'shows a list of drinks if there are any' do
84
84
  grab_request('get', 200, drinks)
85
85
  send_command('kegbot drink list')
86
- expect(replies.last).to eq('esigler poured a glass at ' \
87
- '2014-04-14T07:39:01+00:00')
86
+ expect(replies.last).to eq('esigler poured a refreshing glass of ' \
87
+ 'Racer 5 at 2014-04-14T07:39:01+00:00')
88
88
  end
89
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
90
  it 'shows the correct number of drinks if there are that many' do
105
91
  grab_request('get', 200, drinks)
106
92
  send_command('kegbot drink list 1')
107
93
  expect(replies.count).to eq(1)
108
94
  end
109
95
 
96
+ it 'shows an empty list if there arent any' do
97
+ grab_request('get', 200, drinks_empty)
98
+ send_command('kegbot drink list')
99
+ expect(replies.last).to eq('No drinks have been poured')
100
+ end
101
+
110
102
  it 'shows an error if there was a problem with the request' do
111
103
  grab_request('get', 500, nil)
112
104
  send_command('kegbot drink list 2')
@@ -158,7 +150,7 @@ describe Lita::Handlers::Kegbot, lita_handler: true do
158
150
  it 'shows the status of all of the kegs if there are any' do
159
151
  grab_request('get', 200, kegs)
160
152
  send_command('kegbot keg status')
161
- expect(replies.last).to eq('Keg #1: Racer 5, status: online, 100.0% ' \
153
+ expect(replies.last).to eq('Keg #1: Racer 5, status: online, 100.00% ' \
162
154
  'remaining')
163
155
  end
164
156
 
@@ -179,7 +171,7 @@ describe Lita::Handlers::Kegbot, lita_handler: true do
179
171
  it 'shows the status of a specific keg' do
180
172
  grab_request('get', 200, keg)
181
173
  send_command('kegbot keg status 1')
182
- expect(replies.last).to eq('Keg #1: Racer 5, status: online, 100.0% ' \
174
+ expect(replies.last).to eq('Keg #1: Racer 5, status: online, 100.00% ' \
183
175
  'remaining')
184
176
  end
185
177
 
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.2.0
4
+ version: 0.3.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-04-14 00:00:00.000000000 Z
11
+ date: 2014-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita