hopcat-api 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 164bf1c7944defc7412da460e10d99b5ad765dc5
4
+ data.tar.gz: 5ac90074c2a69043ea863c1ce250574a4363d436
5
+ SHA512:
6
+ metadata.gz: 35704707a46551a5c4bb3844d371cc6039e740b07ead0fc5c378cdba61dcf2115edd85e786308145624fba352880c185510d297a347d25a44eaa2f0d52cca13f
7
+ data.tar.gz: 36414ccfcfe96a6b1bb4385085f9ad3f37cf32cc4db2cf8c06ad0f18afa602b912c97fd3cafb669405f60202cd4f090ae23c1a6f125b1057d8bf82d4a4c685f0
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create use ruby-2.0.0-p0@hopcat-api
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0.0"
4
+ # uncomment this line if your project needs to run something other than `rake`:
5
+ # script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ ruby "2.0.0"
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in hopcat-api.gemspec
6
+ gemspec
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hopcat-api (0.0.2)
5
+ nokogiri
6
+ sinatra
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ diff-lcs (1.2.5)
12
+ json (1.8.1)
13
+ mini_portile (0.6.0)
14
+ nokogiri (1.6.3.1)
15
+ mini_portile (= 0.6.0)
16
+ rack (1.5.2)
17
+ rack-protection (1.5.3)
18
+ rack
19
+ rake (10.3.2)
20
+ rspec (3.0.0)
21
+ rspec-core (~> 3.0.0)
22
+ rspec-expectations (~> 3.0.0)
23
+ rspec-mocks (~> 3.0.0)
24
+ rspec-core (3.0.3)
25
+ rspec-support (~> 3.0.0)
26
+ rspec-expectations (3.0.3)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.0.0)
29
+ rspec-mocks (3.0.3)
30
+ rspec-support (~> 3.0.0)
31
+ rspec-support (3.0.3)
32
+ sinatra (1.4.5)
33
+ rack (~> 1.4)
34
+ rack-protection (~> 1.4)
35
+ tilt (~> 1.3, >= 1.3.4)
36
+ tilt (1.4.1)
37
+ travis-lint (2.0.0)
38
+ json
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ bundler (~> 1.5)
45
+ hopcat-api!
46
+ rake
47
+ rspec
48
+ travis-lint
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Chris Chalfant
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ web: bundle exec ruby bin/server.rb -p $PORT
@@ -0,0 +1,31 @@
1
+ # Hopcat::Api
2
+
3
+ [![Build Status](https://travis-ci.org/chalfant/hopcat-api.svg?branch=master)](https://travis-ci.org/chalfant/hopcat-api)
4
+
5
+ TODO: Write a gem description
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'hopcat-api'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install hopcat-api
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( http://github.com/<my-github-username>/hopcat-api/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ require 'hopcat/api'
3
+ require 'json'
4
+
5
+ draft = Hopcat::Api::Draft.new
6
+
7
+ puts JSON.pretty_generate(draft.list)
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ require 'sinatra'
3
+ require 'hopcat/api'
4
+ require 'json'
5
+
6
+ get '/drafts' do
7
+ d = Hopcat::Api::Draft.new
8
+ JSON.generate(d.list)
9
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hopcat/api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hopcat-api"
8
+ spec.version = Hopcat::Api::VERSION
9
+ spec.authors = ["Chris Chalfant"]
10
+ spec.email = ["chalfants@gmail.com"]
11
+ spec.summary = %q{Scrape hopcat's draft list}
12
+ spec.description = %q{Scrape hopcat's draft list}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "travis-lint"
25
+ spec.add_dependency "nokogiri"
26
+ spec.add_dependency "sinatra"
27
+ end
@@ -0,0 +1,2 @@
1
+ require "hopcat/api/version"
2
+ require "hopcat/api/draft"
@@ -0,0 +1,83 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ module Hopcat
5
+ module Api
6
+ class Draft
7
+
8
+ attr_accessor :location
9
+
10
+ def initialize
11
+ @location = 'http://www.hopcat.com/tap/broad-ripple'
12
+ end
13
+
14
+ def list
15
+ results = {
16
+ drafts: []
17
+ }
18
+ item_lists.each do |a_list|
19
+ category = item_list_category(a_list)
20
+ items(a_list).each do |item|
21
+ beer_hash = item_to_hash(item)
22
+ beer_hash[:category] = category
23
+ results[:drafts] << beer_hash
24
+ end
25
+ end
26
+ results
27
+ end
28
+
29
+ def item_lists
30
+ page = Nokogiri::HTML( open(location) )
31
+ page.css('div.view-content div.view-order-beers')
32
+ end
33
+
34
+ def item_list_category(item_list)
35
+ item_list.css('h3')[0].text
36
+ end
37
+
38
+ def items(item_list)
39
+ item_list.css('li.views-row')
40
+ end
41
+
42
+ def item_to_hash(item)
43
+ {
44
+ title: item_title(item),
45
+ brewery: item_brewery(item),
46
+ location: item_location(item),
47
+ abv: item_abv(item),
48
+ style: item_style(item)
49
+ }
50
+ end
51
+
52
+ def item_title(item)
53
+ item.css('div.views-field-title span').text.strip
54
+ end
55
+
56
+ def item_brewery(item)
57
+ item.css('div.views-field-field-brewery div').text.strip
58
+ end
59
+
60
+ def item_location(item)
61
+ item.css('div.views-field-field-city-state-country div').text.strip
62
+ end
63
+
64
+ def item_abv(item)
65
+ item.css('div.views-field-field-beer-abv div').text.gsub(/[()]/,'').strip
66
+ end
67
+
68
+ def strip_nbsp(str)
69
+ nbsp = Nokogiri::HTML("&nbsp;").text
70
+ str.gsub(nbsp, '')
71
+ end
72
+
73
+ def item_style(item)
74
+ style = item.css('div.views-field-body div').text.strip
75
+ style = strip_nbsp(style)
76
+ if style.lines.size > 1
77
+ style = style.lines.first
78
+ end
79
+ style.strip
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,5 @@
1
+ module Hopcat
2
+ module Api
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,91 @@
1
+ describe Hopcat::Api::Draft do
2
+ it { is_expected.to respond_to :list }
3
+ it { is_expected.to respond_to :location }
4
+
5
+ subject(:d) do
6
+ d = Hopcat::Api::Draft.new
7
+ d.location = File.join File.dirname(__FILE__), 'test.html'
8
+ d
9
+ end
10
+
11
+ describe '#list' do
12
+ it 'returns a hash' do
13
+ expect(d.list).to be_a(Hash)
14
+ end
15
+ end
16
+
17
+ describe '#item_lists' do
18
+ it 'returns 9 item_lists' do
19
+ expect(d.item_lists.length).to eq 9
20
+ end
21
+ end
22
+
23
+ describe '#item_list_category' do
24
+ it 'returns "Belgian" for first category' do
25
+ item_list = d.item_lists[0]
26
+ expect(d.item_list_category(item_list)).to eq('Belgian')
27
+ end
28
+
29
+ it 'returns "Pales, IPAs, Imperial IPAs" for second category' do
30
+ item_list = d.item_lists[1]
31
+ expect(d.item_list_category(item_list)).to eq('Pales, IPAs, Imperial IPAs')
32
+ end
33
+ end
34
+
35
+ describe '#items' do
36
+ it 'returns 9 items for first category' do
37
+ item_list = d.item_lists[0]
38
+ expect( d.items(item_list).length ).to eq 9
39
+ end
40
+ end
41
+
42
+ describe '#item_title' do
43
+ it 'returns "Tripel de Ripple – $5"' do
44
+ item = d.items( d.item_lists[0] )[0]
45
+ expect( d.item_title(item) ).to eq "Tripel de Ripple – $5"
46
+ end
47
+ end
48
+
49
+ describe '#item_brewery' do
50
+ it 'returns "Brugge Brasserie"' do
51
+ item = d.items( d.item_lists[0] )[0]
52
+ expect( d.item_brewery(item) ).to eq "Brugge Brasserie"
53
+ end
54
+ end
55
+
56
+ describe '#item_location' do
57
+ it 'returns "Indianapolis, IN"' do
58
+ item = d.items( d.item_lists[0] )[0]
59
+ expect( d.item_location(item) ).to eq "Indianapolis, IN"
60
+ end
61
+ end
62
+
63
+ describe '#item_abv' do
64
+ it 'returns "10%"' do
65
+ item = d.items( d.item_lists[0] )[0]
66
+ expect( d.item_abv(item) ).to eq "10%"
67
+ end
68
+ end
69
+
70
+ describe '#item_style' do
71
+ it 'returns "Belgian-Style Tripel"' do
72
+ item = d.items( d.item_lists[0] )[0]
73
+ expect( d.item_style(item) ).to eq "Belgian-Style Tripel"
74
+ end
75
+ end
76
+
77
+ describe '#item_to_hash' do
78
+ it 'returns the correct hash' do
79
+ item = d.items( d.item_lists[0] )[0]
80
+ expected = {
81
+ title: "Tripel de Ripple – $5",
82
+ brewery: "Brugge Brasserie",
83
+ location: "Indianapolis, IN",
84
+ abv: "10%",
85
+ style: "Belgian-Style Tripel"
86
+ }
87
+ expect( d.item_to_hash(item) ).to eq expected
88
+ end
89
+ end
90
+
91
+ end
@@ -0,0 +1,79 @@
1
+ require 'hopcat/api'
2
+ # This file was generated by the `rspec --init` command. Conventionally, all
3
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
4
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
5
+ # file to always be loaded, without a need to explicitly require it in any files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, make a
11
+ # separate helper file that requires this one and then use it only in the specs
12
+ # that actually need it.
13
+ #
14
+ # The `.rspec` file also contains a few flags that are not defaults but that
15
+ # users commonly want.
16
+ #
17
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
18
+ RSpec.configure do |config|
19
+ # The settings below are suggested to provide a good initial experience
20
+ # with RSpec, but feel free to customize to your heart's content.
21
+ =begin
22
+ # These two settings work together to allow you to limit a spec run
23
+ # to individual examples or groups you care about by tagging them with
24
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
25
+ # get run.
26
+ config.filter_run :focus
27
+ config.run_all_when_everything_filtered = true
28
+
29
+ # Many RSpec users commonly either run the entire suite or an individual
30
+ # file, and it's useful to allow more verbose output when running an
31
+ # individual spec file.
32
+ if config.files_to_run.one?
33
+ # Use the documentation formatter for detailed output,
34
+ # unless a formatter has already been configured
35
+ # (e.g. via a command-line flag).
36
+ config.default_formatter = 'doc'
37
+ end
38
+
39
+ # Print the 10 slowest examples and example groups at the
40
+ # end of the spec run, to help surface which specs are running
41
+ # particularly slow.
42
+ config.profile_examples = 10
43
+
44
+ # Run specs in random order to surface order dependencies. If you find an
45
+ # order dependency and want to debug it, you can fix the order by providing
46
+ # the seed, which is printed after each run.
47
+ # --seed 1234
48
+ config.order = :random
49
+
50
+ # Seed global randomization in this process using the `--seed` CLI option.
51
+ # Setting this allows you to use `--seed` to deterministically reproduce
52
+ # test failures related to randomization by passing the same `--seed` value
53
+ # as the one that triggered the failure.
54
+ Kernel.srand config.seed
55
+
56
+ # rspec-expectations config goes here. You can use an alternate
57
+ # assertion/expectation library such as wrong or the stdlib/minitest
58
+ # assertions if you prefer.
59
+ config.expect_with :rspec do |expectations|
60
+ # Enable only the newer, non-monkey-patching expect syntax.
61
+ # For more details, see:
62
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
63
+ expectations.syntax = :expect
64
+ end
65
+
66
+ # rspec-mocks config goes here. You can use an alternate test double
67
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
68
+ config.mock_with :rspec do |mocks|
69
+ # Enable only the newer, non-monkey-patching expect syntax.
70
+ # For more details, see:
71
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
72
+ mocks.syntax = :expect
73
+
74
+ # Prevents you from mocking or stubbing a method that does not exist on
75
+ # a real object. This is generally recommended.
76
+ mocks.verify_partial_doubles = true
77
+ end
78
+ =end
79
+ end