lita-onewheel-beer-wework 0.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7458525108d874df189dfda5852e74d383cb540
4
- data.tar.gz: af8c0349ea10191090d6c7905f42ab4ac123b765
3
+ metadata.gz: dbb5d83948e34954e3362634fb4eb164def1738c
4
+ data.tar.gz: 8a54bd817965a9392ba78a9cce1631ff42c78834
5
5
  SHA512:
6
- metadata.gz: 2ae42ef32ed6a725bad8fd2d80b277c32718ba6e3c9445c560a32b293a9734b81271ee0fe52631aa72ab2b400a58d4f7cb83ec70759deab57fcc408291614d27
7
- data.tar.gz: fa52024e24bd1b5bfd38187d21ae155ad1920676dbe43c7c1193eb951b10ad2d1f48c8c55a9f1bab68047f1b62354ef7074240bc4eec05f47c3a247c23e47132
6
+ metadata.gz: 103d1a396161050c51ac0c3aecc38e2cdc62b97ffc1fdf4d1dc6d3e18167187715661e8551098d3a64d9d87101b99561bf2d08146d139e891d803df4a4d4aab6
7
+ data.tar.gz: 39292bdb13b8c5bbeb392ac7f44601a4bd855cc363ab5580d249fc26880014e2dfe91effaa8c63838f09a5cda48028dcaa19f33e44d9235fb80c5f30e1b70f9f
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .idea
19
+ lita_config.rb
@@ -1,48 +1,65 @@
1
+ require 'json'
2
+
1
3
  module Lita
2
4
  module Handlers
3
5
  class OnewheelBeerWework < Handler
4
- REDIS_KEY = 'onewheel-doc'
6
+ REDIS_KEY = 'onewheel-beer-wework'
7
+ LOCATIONS = %w(1fs 1fn 2fs 2fn 3fn)
5
8
 
6
9
  route /^wework\s+([\w\/+_-]+)\s+(.*)$/i,
7
- :command_add_key,
10
+ :command_add_beer,
8
11
  command: true,
9
12
  help: {'!wework 2fS Beer' => 'Add a beer to 2fS'}
10
13
  route /^wework$/i,
11
- :command_list_keys,
14
+ :command_list_beers,
12
15
  command: true,
13
16
  help: {'!wework ' => 'list all beers'}
14
17
  route /^wework\s+(\w+)$/i,
15
- :command_fetch_key,
18
+ :command_fetch_beer,
16
19
  command: true,
17
20
  help: {'!wework 2fS ' => 'fetch the beer for 2fS'}
18
21
 
19
- def command_add_key(response)
22
+ def command_add_beer(response)
20
23
  key = response.matches[0][0].downcase
21
- unless %w(1fs 1fn 2fs 2fn 3fn).include? key
24
+ unless LOCATIONS.include? key
22
25
  Lita.logger.info "#{key} was not found in the floors array."
23
26
  return
24
27
  end
25
- key = key[0..1] + key[-1].upcase
26
- value = response.matches[0][1]
28
+ beer_name = response.matches[0][1]
29
+ key = key[0..1] + key[-1].downcase
30
+ value = {
31
+ name: beer_name,
32
+ user: response.user.name,
33
+ time: Time.now
34
+ }.to_json
27
35
  redis.hset(REDIS_KEY, key, value)
28
- response.reply "Logged #{value} at #{key}!"
36
+ response.reply "Logged #{beer_name} at #{key}!"
29
37
  end
30
38
 
31
- def command_fetch_key(response)
39
+ def command_fetch_beer(response)
32
40
  key = response.matches[0][0]
33
41
 
34
- reply = get_values_that_start_with_key(key)
35
- response.reply reply
42
+ values = get_values_that_start_with_key(key)
43
+ values.each do |keg|
44
+ floor_id, keg_name = get_floor_and_keg_name(keg)
45
+ response.reply "#{floor_id}: #{keg_name}"
46
+ end
36
47
  end
37
48
 
38
- def command_list_keys(response)
39
- replies = []
49
+ def get_floor_and_keg_name(keg)
50
+ floor_id = keg.keys[0]
51
+ keg_meta = JSON.parse(keg[floor_id])
52
+ return floor_id, keg_meta['name']
53
+ end
40
54
 
41
- all = redis.hgetall(REDIS_KEY)
42
- all.each do |key, val|
43
- replies.push format_key_val_response(key, val)
55
+ def command_list_beers(response)
56
+ test = redis.hgetall(REDIS_KEY)
57
+ LOCATIONS.each do |floor|
58
+ if (data = redis.hget(REDIS_KEY, floor))
59
+ floor, keg_name = get_floor_and_keg_name(floor => data)
60
+ response.reply "#{floor}: #{keg_name}"
61
+ end
44
62
  end
45
- response.reply replies.join ", "
46
63
  end
47
64
 
48
65
  def get_values_that_start_with_key(key)
@@ -50,14 +67,10 @@ module Lita
50
67
  all = redis.hgetall(REDIS_KEY)
51
68
  all.each do |all_key, all_val|
52
69
  if all_key =~ /^#{key}/i
53
- values.push format_key_val_response(all_key, all_val)
70
+ values.push all_key => all_val
54
71
  end
55
72
  end
56
- reply = values.join ", "
57
- end
58
-
59
- def format_key_val_response(all_key, all_val)
60
- "#{all_key}: #{all_val}"
73
+ values
61
74
  end
62
75
  end
63
76
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-onewheel-beer-wework'
3
- spec.version = '0.0.0'
3
+ spec.version = '1.0.0'
4
4
  spec.authors = ['Andrew Kreps']
5
5
  spec.email = ['andrew.kreps@gmail.com']
6
6
  spec.description = 'Basic key/value store for wework beers.'
@@ -6,19 +6,25 @@ describe Lita::Handlers::OnewheelBeerWework, lita_handler: true do
6
6
 
7
7
  it 'sets a beer' do
8
8
  send_command 'wework 2fs Breakfast Stout'
9
- expect(replies.last).to eq('Logged Breakfast Stout at 2fS!')
9
+ expect(replies.last).to eq('Logged Breakfast Stout at 2fs!')
10
+ end
11
+
12
+ it 'doesn\'t set a beer' do
13
+ send_command 'wework 9fF Breakfast Stout'
14
+ expect(replies.last).to eq(nil)
10
15
  end
11
16
 
12
17
  it 'gets a beer' do
13
18
  send_command 'wework 2fs Breakfast Stout'
14
19
  send_command 'wework 2fs'
15
- expect(replies.last).to eq('2fS: Breakfast Stout')
20
+ expect(replies.last).to eq('2fs: Breakfast Stout')
16
21
  end
17
22
 
18
- it 'lists documents' do
23
+ it 'lists beers' do
19
24
  send_command 'wework 2fs one'
20
25
  send_command 'wework 2fN two'
21
26
  send_command 'wework'
22
- expect(replies.last).to eq("2fS: one, 2fN: two")
27
+ expect(replies[2]).to eq('2fs: one')
28
+ expect(replies.last).to eq('2fn: two')
23
29
  end
24
30
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'simplecov'
2
2
  require 'coveralls'
3
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
3
+ SimpleCov.formatters = [
4
4
  SimpleCov::Formatter::HTMLFormatter,
5
5
  Coveralls::SimpleCov::Formatter
6
6
  ]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-onewheel-beer-wework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kreps
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-22 00:00:00.000000000 Z
11
+ date: 2016-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita