-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c608daa
Showing
11 changed files
with
2,659 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
*.gem | ||
*.rbc | ||
.bundle | ||
.config | ||
.yardoc | ||
Gemfile.lock | ||
InstalledFiles | ||
_yardoc | ||
coverage | ||
doc/ | ||
lib/bundler/man | ||
pkg | ||
rdoc | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
tmp | ||
.idea | ||
lita_config.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
language: ruby | ||
|
||
rvm: | ||
- 2.2.4 | ||
- 2.3.0 | ||
|
||
script: bundle exec rspec -fp spec | ||
|
||
# Travis CI has an outdated version of bundler on older versions of ruby. | ||
# See bundler/bundler#3558 for more information | ||
#before_install: | ||
# - gem update --system | ||
# - gem update bundler | ||
|
||
services: | ||
- redis-server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
source 'https://rubygems.org' | ||
|
||
gemspec | ||
|
||
# For local development and base testing | ||
# gem 'lita-onewheel-beer-base', :github => 'onewheelskyward/lita-onewheel-beer-base', branch: :master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# lita-onewheel-beer-tin-bucket | ||
|
||
[![Build Status](https://travis-ci.org/onewheelskyward/lita-onewheel-beer-tin-bucket.png?branch=master)](https://travis-ci.org/onewheelskyward/lita-onewheel-beer-tin-bucket) | ||
[![Coverage Status](https://coveralls.io/repos/onewheelskyward/lita-onewheel-beer-tin-bucket/badge.png)](https://coveralls.io/r/onewheelskyward/lita-onewheel-beer-tin-bucket) | ||
|
||
Searches Tin Bucket's DigitalPour draft list for data and displays it in IRC. | ||
http://fbpage.digitalpour.com/?companyID=55a59fd25e002c0a205393cc&locationID=1 | ||
|
||
## Installation | ||
|
||
Add lita-onewheel-beer-tin-bucket to your Lita instance's Gemfile: | ||
|
||
``` ruby | ||
gem 'lita-onewheel-beer-tin-bucket' | ||
``` | ||
|
||
## Usage | ||
|
||
tinbucket | ||
|
||
tinbucket 4 | ||
|
||
tinbucket nitro | ||
|
||
tinbucket >(=)5% | ||
|
||
tinbucket <(=)$5 | ||
|
||
tinbucket roulette|random | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
task default: :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'lita' | ||
|
||
Lita.load_locales Dir[File.expand_path( | ||
File.join('..', '..', 'locales', '*.yml'), __FILE__ | ||
)] | ||
|
||
require 'lita/handlers/onewheel_beer_tin_bucket' | ||
|
||
Lita::Handlers::OnewheelBeerTinBucket.template_root File.expand_path( | ||
File.join('..', '..', 'templates'), | ||
__FILE__ | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
require 'rest-client' | ||
require 'nokogiri' | ||
require 'sanitize' | ||
require 'lita-onewheel-beer-base' | ||
|
||
module Lita | ||
module Handlers | ||
class OnewheelBeerTinBucket < OnewheelBeerBase | ||
route /^tinbucket$/i, | ||
:taps_list, | ||
command: true, | ||
help: {'taps' => 'Display the current Tin Bucket taps.'} | ||
|
||
route /^tinbucket ([\w ]+)$/i, | ||
:taps_deets, | ||
command: true, | ||
help: {'taps 4' => 'Display the tap 4 deets, including prices.'} | ||
|
||
route /^tinbucket ([<>=\w.\s]+)%$/i, | ||
:taps_by_abv, | ||
command: true, | ||
help: {'taps >4%' => 'Display beers over 4% ABV.'} | ||
|
||
route /^tinbucket ([<>=\$\w.\s]+)$/i, | ||
:taps_by_price, | ||
command: true, | ||
help: {'taps <$5' => 'Display beers under $5.'} | ||
|
||
route /^tinbucket (roulette|random|rand|ran|ra|r)$/i, | ||
:taps_by_random, | ||
command: true, | ||
help: {'taps roulette' => 'Can\'t decide? Let me do it for you!'} | ||
|
||
route /^tinbucketabvlow$/i, | ||
:taps_low_abv, | ||
command: true, | ||
help: {'tapslow' => 'Show me the lowest abv keg.'} | ||
|
||
route /^tinbucketabvhigh$/i, | ||
:taps_high_abv, | ||
command: true, | ||
help: {'tapslow' => 'Show me the highest abv keg.'} | ||
|
||
def send_response(tap, datum, response) | ||
reply = "tinbucket tap #{tap}) #{get_tap_type_text(datum[:type])}" | ||
# reply += "#{datum[:brewery]} " | ||
reply += "#{datum[:name]} " | ||
# reply += "- #{datum[:desc]}, " | ||
# reply += "Served in a #{datum[1]['glass']} glass. " | ||
# reply += "#{datum[:remaining]}" | ||
reply += "#{datum[:abv]}%, " | ||
reply += "$#{datum[:price].to_s.sub '.0', ''}" | ||
|
||
Lita.logger.info "send_response: Replying with #{reply}" | ||
|
||
response.reply reply | ||
end | ||
|
||
def get_source | ||
Lita.logger.debug 'get_source started' | ||
unless (response = redis.get('page_response')) | ||
Lita.logger.info 'No cached result found, fetching.' | ||
response = RestClient.get('http://tinbucketbar.com/menu') | ||
redis.setex('page_response', 1800, response) | ||
end | ||
parse_response response | ||
end | ||
|
||
# This is the worker bee- decoding the html into our "standard" document. | ||
# Future implementations could simply override this implementation-specific | ||
# code to help this grow more widely. | ||
def parse_response(response) | ||
Lita.logger.debug 'parse_response started.' | ||
gimme_what_you_got = {} | ||
noko = Nokogiri.HTML response | ||
noko.css('table.table tbody tr').each_with_index do |beer_node, index| | ||
# gimme_what_you_got | ||
tap_name = (index + 1).to_s | ||
|
||
brewery = beer_node.css('td')[2].children.to_s | ||
beer_name = beer_node.css('td')[0].children.text.to_s | ||
beer_type = beer_name.match(/\s*-\s*\w+$/).to_s | ||
beer_type.sub! /\s+-\s+/, '' | ||
# beer_desc = get_beer_desc(beer_node) | ||
abv = beer_node.css('td')[4].children.to_s | ||
full_text_search = "#{brewery} #{beer_name.to_s.gsub /(\d+|')/, ''}" # #{beer_desc.to_s.gsub /\d+\.*\d*%*/, ''} | ||
price_node = beer_node.css('td')[1].children.to_s | ||
price = (price_node.sub /\$/, '').to_f | ||
|
||
Lita.logger.debug "Price #{price}" | ||
|
||
gimme_what_you_got[tap_name] = { | ||
# type: tap_type, | ||
# remaining: remaining, | ||
brewery: brewery.to_s, | ||
name: beer_name.to_s, | ||
desc: beer_type.to_s, | ||
abv: abv.to_f, | ||
price: price, | ||
search: full_text_search | ||
} | ||
end | ||
# puts gimme_what_you_got.inspect | ||
|
||
gimme_what_you_got | ||
end | ||
|
||
Lita.register_handler(self) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Gem::Specification.new do |spec| | ||
spec.name = 'lita-onewheel-beer-tin-bucket' | ||
spec.version = '0.0.0' | ||
spec.authors = ['Andrew Kreps'] | ||
spec.email = ['andrew.kreps@gmail.com'] | ||
spec.description = %q{Lita interface to Tin Bucket's listings.} | ||
spec.summary = %q{See above.} | ||
spec.homepage = 'https://github.com/onewheelskyward/lita-onewheel-beer-tin-bucket' | ||
spec.license = 'MIT' | ||
spec.metadata = { 'lita_plugin_type' => 'handler' } | ||
|
||
spec.files = `git ls-files`.split($/) | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | ||
spec.require_paths = ['lib'] | ||
|
||
spec.add_runtime_dependency 'lita', '~> 4.7' | ||
spec.add_runtime_dependency 'rest-client', '~> 1.8' | ||
spec.add_runtime_dependency 'nokogiri', '~> 1.6' | ||
spec.add_runtime_dependency 'sanitize', '~> 4.0' | ||
spec.add_runtime_dependency 'lita-onewheel-beer-base', '>= 2' | ||
|
||
spec.add_development_dependency 'bundler', '~> 1.3' | ||
|
||
# spec.add_development_dependency 'pry-byebug', '~> 3.1' | ||
spec.add_development_dependency 'rake', '~> 10.4' | ||
spec.add_development_dependency 'rack-test', '~> 0.6' | ||
spec.add_development_dependency 'rspec', '~> 3.0' | ||
spec.add_development_dependency 'simplecov', '~> 0.10' | ||
spec.add_development_dependency 'coveralls', '~> 0.8' | ||
end |
Oops, something went wrong.