lita-onewheel-beer-wayfinder 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.travis.yml +16 -0
- data/Gemfile +6 -0
- data/README.md +30 -0
- data/Rakefile +6 -0
- data/lib/lita/handlers/onewheel_beer_wayfinder.rb +124 -0
- data/lib/lita-onewheel-beer-wayfinder.rb +3 -0
- data/lita-onewheel-beer-wayfinder.gemspec +31 -0
- data/spec/fixtures/wayfinder.html +4178 -0
- data/spec/lita/handlers/onewheel_beer_wayfinder_spec.rb +92 -0
- data/spec/spec_helper.rb +14 -0
- metadata +213 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 20a3744d7dc61b44c337da329511bf97f5649ccb
|
4
|
+
data.tar.gz: 2fd65c43aaa7d9fa6474e60a03f5f2716eff6fce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e98188602867bf38445e9b128ae1ccc46a3feecc7788b2f61cae5c47a3d4ca0311220ec040244b039fa060dffc32f828b169bd9858f0ff8d04eb31643be02ae2
|
7
|
+
data.tar.gz: f30555a7bfa832e57f1fbec0c1f5ad857edd522bf6572913907e0f96423ce66dc30044c0a1515d08fb05e44783f3a5e8399200ef9c84098d0c15949c17737b5d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
rvm:
|
4
|
+
- 2.2.6
|
5
|
+
- 2.3.3
|
6
|
+
|
7
|
+
script: bundle exec rspec -fp spec
|
8
|
+
|
9
|
+
# Travis CI has an outdated version of bundler on older versions of ruby.
|
10
|
+
# See bundler/bundler#3558 for more information
|
11
|
+
#before_install:
|
12
|
+
# - gem update --system
|
13
|
+
# - gem update bundler
|
14
|
+
|
15
|
+
services:
|
16
|
+
- redis-server
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# lita-onewheel-apex-bar
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/onewheelskyward/lita-onewheel-apex-bar.png?branch=master)](https://travis-ci.org/onewheelskyward/lita-onewheel-apex-bar)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/onewheelskyward/lita-onewheel-apex-bar/badge.png)](https://coveralls.io/r/onewheelskyward/lita-onewheel-apex-bar)
|
5
|
+
|
6
|
+
Searches Apex Bar's draft list for data and displays it in IRC.
|
7
|
+
http://apexbar.com/menu
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add lita-onewheel-apex-bar to your Lita instance's Gemfile:
|
12
|
+
|
13
|
+
``` ruby
|
14
|
+
gem 'lita-onewheel-apex-bar'
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
apex
|
20
|
+
|
21
|
+
apex 4
|
22
|
+
|
23
|
+
apex nitro
|
24
|
+
|
25
|
+
apex >(=)5%
|
26
|
+
|
27
|
+
apex <(=)$5
|
28
|
+
|
29
|
+
apex roulette|random
|
30
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'sanitize'
|
4
|
+
require 'lita-onewheel-beer-base'
|
5
|
+
|
6
|
+
module Lita
|
7
|
+
module Handlers
|
8
|
+
class OnewheelBeerWayfinder < OnewheelBeerBase
|
9
|
+
route /^wayfinder$/i,
|
10
|
+
:taps_list,
|
11
|
+
command: true,
|
12
|
+
help: {'wayfinder' => 'Display the current Wayfinder Bar taps.'}
|
13
|
+
|
14
|
+
route /^wayfinder ([\w ]+)$/i,
|
15
|
+
:taps_deets,
|
16
|
+
command: true,
|
17
|
+
help: {'wayfinder 4' => 'Display the Wayfinder tap 4 deets, including prices.'}
|
18
|
+
|
19
|
+
route /^wayfinder ([<>=\w.\s]+)%$/i,
|
20
|
+
:taps_by_abv,
|
21
|
+
command: true,
|
22
|
+
help: {'wayfinder >4%' => 'Display Wayfinder beers over 4% ABV.'}
|
23
|
+
|
24
|
+
route /^wayfinder ([<>=\$\w.\s]+)$/i,
|
25
|
+
:taps_by_price,
|
26
|
+
command: true,
|
27
|
+
help: {'wayfinder <$5' => 'Display Wayfinder beers under $5.'}
|
28
|
+
|
29
|
+
route /^wayfinder (roulette|random|rand|ran|ra|r)$/i,
|
30
|
+
:taps_by_random,
|
31
|
+
command: true,
|
32
|
+
help: {'wayfinder roulette' => 'Can\'t decide what to drink at Wayfinder? Let me do it for you!'}
|
33
|
+
|
34
|
+
route /^wayfinderabvlow$/i,
|
35
|
+
:taps_low_abv,
|
36
|
+
command: true,
|
37
|
+
help: {'wayfinderabvlow' => 'Show me the lowest Wayfinder abv keg.'}
|
38
|
+
|
39
|
+
route /^wayfinderabvhigh$/i,
|
40
|
+
:taps_high_abv,
|
41
|
+
command: true,
|
42
|
+
help: {'wayfinderabvhigh' => 'Show me the highest Wayfinder abv keg.'}
|
43
|
+
|
44
|
+
def send_response(tap, datum, response)
|
45
|
+
reply = "Wayfinder tap #{tap}) #{get_tap_type_text(datum[:type])}"
|
46
|
+
# reply += "#{datum[:brewery]} "
|
47
|
+
reply += "#{datum[:name]} "
|
48
|
+
reply += "- #{datum[:desc]}, "
|
49
|
+
# reply += "Served in a #{datum[1]['glass']} glass. "
|
50
|
+
# reply += "#{datum[:remaining]}"
|
51
|
+
reply += "#{datum[:abv]}%, "
|
52
|
+
# reply += "$#{datum[:price].to_s.sub '.0', ''}"
|
53
|
+
|
54
|
+
Lita.logger.info "send_response: Replying with #{reply}"
|
55
|
+
|
56
|
+
response.reply reply
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_source
|
60
|
+
Lita.logger.debug 'get_source started'
|
61
|
+
unless (response = redis.get('page_response'))
|
62
|
+
Lita.logger.info 'No cached result found, fetching.'
|
63
|
+
response = RestClient.get('http://www.wayfinder.beer/')
|
64
|
+
redis.setex('page_response', 1800, response)
|
65
|
+
end
|
66
|
+
parse_response response
|
67
|
+
end
|
68
|
+
|
69
|
+
# This is the worker bee- decoding the html into our "standard" document.
|
70
|
+
# Future implementations could simply override this implementation-specific
|
71
|
+
# code to help this grow more widely.
|
72
|
+
def parse_response(response)
|
73
|
+
Lita.logger.debug 'parse_response started.'
|
74
|
+
gimme_what_you_got = {}
|
75
|
+
noko = Nokogiri.HTML response
|
76
|
+
noko.css('div.menus div.menu-item').each_with_index do |beer_node, index|
|
77
|
+
# gimme_what_you_got
|
78
|
+
tap_name = (index + 1).to_s
|
79
|
+
|
80
|
+
brewery = 'Wayfinder'
|
81
|
+
beer_name = beer_node.css('.menu-item-title').text.to_s.strip
|
82
|
+
|
83
|
+
beer_type = beer_node.css('.menu-item-title').children[1].to_s.strip
|
84
|
+
|
85
|
+
beer_desc = beer_node.css('.menu-item-description').text
|
86
|
+
|
87
|
+
abv_node = /\d+\.\d+\%/.match(beer_node.css('div.menu-item-option').text)
|
88
|
+
if abv_node
|
89
|
+
abv = abv_node[0]
|
90
|
+
abv.sub! /\%/, ''
|
91
|
+
end
|
92
|
+
|
93
|
+
ibu_node = /IBU \d+/.match(beer_node.css('div.menu-item-option').text)
|
94
|
+
if ibu_node
|
95
|
+
ibu = ibu_node[0]
|
96
|
+
ibu.sub! /IBU /, ''
|
97
|
+
end
|
98
|
+
|
99
|
+
full_text_search = "#{brewery} #{beer_name.to_s.gsub /(\d+|')/, ''}" # #{beer_desc.to_s.gsub /\d+\.*\d*%*/, ''}
|
100
|
+
|
101
|
+
# price_node = beer_node.css('td')[1].children.to_s
|
102
|
+
# price = (price_node.sub /\$/, '').to_f
|
103
|
+
|
104
|
+
gimme_what_you_got[tap_name] = {
|
105
|
+
# type: tap_type,
|
106
|
+
# remaining: remaining,
|
107
|
+
brewery: brewery.to_s,
|
108
|
+
name: beer_name.to_s,
|
109
|
+
desc: beer_type.to_s,
|
110
|
+
abv: abv.to_f,
|
111
|
+
ibu: ibu.to_i,
|
112
|
+
desc: beer_desc.to_s,
|
113
|
+
# price: price,
|
114
|
+
search: full_text_search
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
gimme_what_you_got
|
119
|
+
end
|
120
|
+
|
121
|
+
Lita.register_handler(self)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'lita-onewheel-beer-wayfinder'
|
3
|
+
spec.version = '0.0.0'
|
4
|
+
spec.authors = ['Andrew Kreps']
|
5
|
+
spec.email = ['andrew.kreps@gmail.com']
|
6
|
+
spec.description = %q{Lita interface to Wafinder's Barlistings.}
|
7
|
+
spec.summary = %q{See above.}
|
8
|
+
spec.homepage = 'https://github.com/onewheelskyward/lita-onewheel-beer-wayfinder'
|
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', '~> 4'
|
18
|
+
spec.add_runtime_dependency 'rest-client', '~> 1.8'
|
19
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.6'
|
20
|
+
spec.add_runtime_dependency 'sanitize', '~> 4.0'
|
21
|
+
spec.add_runtime_dependency 'lita-onewheel-beer-base', '~> 2'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
|
+
|
25
|
+
# spec.add_development_dependency 'pry-byebug', '~> 3.1'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.4'
|
27
|
+
spec.add_development_dependency 'rack-test', '~> 0.6'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
spec.add_development_dependency 'simplecov', '~> 0.10'
|
30
|
+
spec.add_development_dependency 'coveralls', '~> 0.8'
|
31
|
+
end
|