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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f377744672faacfb1dd8eb24044eeb4051a7f033
4
- data.tar.gz: d6b41a95f2e133eee66e5767987e550fe6d8dc81
3
+ metadata.gz: 351fd2596c187b9739412825dd59ed3d4528b0a7
4
+ data.tar.gz: 5b177d8c0d54a17fca2c3aedf8d4258f52fa5620
5
5
  SHA512:
6
- metadata.gz: bc8141444f4cbbb04de03fc93990a1c08824d24dcf25c2b737552ba0da0f7dcbfda6f30c29c3f93100b3378665e9e9f709b3f00b591c22d48e31095f8412347b
7
- data.tar.gz: e784489a0972fb0f3eebd5e7d33ddc01ed11895051349a886e615cbaf0b837186c67a12dbb3fce73b95420bf0e43afbcb51c4de5ddda0410fe4b118227578bf1
6
+ metadata.gz: 98efc4a96b7d2bdb0e60a0c3fb830b75aeb9b679ad5ee75b1ba4d03829d43aff7210cb38b728616b9903f29d0ce104e445225d83c8ca21e2e85915b2139ed6b1
7
+ data.tar.gz: d458e6d9377e2a85561b39dd370fec4441323b244662d6f3095348a43b53ae6fdf42d5d71ccd957d2cf36e108312be61671cf39b8b8acb9f1fd41be6058dbeaa
@@ -1,11 +1,10 @@
1
1
  ClassLength:
2
- Max: 300
2
+ Max: 130
3
3
 
4
4
  Documentation:
5
- Enabled: false
5
+ Exclude:
6
+ - lib/lita/handlers/kegbot.rb
6
7
 
7
8
  FileName:
8
- Enabled: false
9
-
10
- MethodLength:
11
- Max: 20
9
+ Exclude:
10
+ - lib/lita-kegbot.rb
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
3
+ - 2.1
4
4
  script: bundle exec rake
5
5
  before_install:
6
6
  - gem update --system
@@ -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
@@ -1,3 +1,3 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Code Climate](https://img.shields.io/codeclimate/github/esigler/lita-kegbot.svg)](https://codeclimate.com/github/esigler/lita-kegbot)
8
8
  [![Gemnasium](https://img.shields.io/gemnasium/esigler/lita-kegbot.svg)](https://gemnasium.com/esigler/lita-kegbot)
9
9
 
10
- A Kegbot (https://kegbot.org) handler for checking what's on tap, how much is left, etc.
10
+ A [Kegbot](https://kegbot.org) plugin for [Lita](https://github.com/jimmycuadra/lita).
11
11
 
12
12
  ## Installation
13
13
 
data/Rakefile CHANGED
@@ -3,6 +3,6 @@ require 'rspec/core/rake_task'
3
3
  require 'rubocop/rake_task'
4
4
 
5
5
  RSpec::Core::RakeTask.new(:spec)
6
- Rubocop::RakeTask.new(:rubocop)
6
+ RuboCop::RakeTask.new(:rubocop)
7
7
 
8
- task default: [ :spec, :rubocop ]
8
+ task default: [:spec, :rubocop]
@@ -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(\s\d+)*$/,
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
- def self.default_config(config)
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
- count_match = response.matches[0][0]
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
- if drinks
60
- response.reply(t('drinks.none')) unless drinks.count > 0
61
- drinks.each do |drink|
62
- if current < count
63
- formatted_date = drink['session']['start_time']
64
- beer = drink['keg']['beverage']['name']
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
- if taps
79
- response.reply(t('taps.none')) unless taps.count > 0
80
- taps.each do |tap|
81
- response.reply(t('taps.info', id: tap['id'], name: tap['name']))
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
- if tap
91
- response.reply(t('taps.info', id: tap['id'], name: tap['name']))
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
- if kegs
100
- response.reply(t('kegs.none')) unless kegs.count > 0
101
- kegs.each do |keg|
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
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
- if keg
119
- keg['online'] ? status = 'online' : status = 'offline'
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 url, args
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
- if http_response.status == 200 ||
173
- http_response.status == 201
174
- MultiJson.load(http_response.body)
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)
@@ -1,24 +1,24 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-kegbot'
3
- spec.version = '0.3.0'
3
+ spec.version = '1.0.0'
4
4
  spec.authors = ['Eric Sigler']
5
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}
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(%r{^bin/}) { |f| File.basename(f) }
14
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
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', '>= 3.0'
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.beta2'
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
- it { routes_command('kegbot drink list').to(:drink_list) }
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) }
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) }
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'
@@ -8,3 +8,5 @@ SimpleCov.start { add_filter '/spec/' }
8
8
 
9
9
  require 'lita-kegbot'
10
10
  require 'lita/rspec'
11
+
12
+ Lita.version_3_compatibility_mode = false
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.3.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-04-15 00:00:00.000000000 Z
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: '3.0'
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: '3.0'
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.beta2
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.beta2
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 handler for Lita.io
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 handler for Lita.io
166
+ summary: A Kegbot plugin for Lita
166
167
  test_files:
167
168
  - spec/files/drinks.json
168
169
  - spec/files/drinks_empty.json