bishl 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ gem "vcr"
14
+ gem "webmock"
15
+ end
16
+
17
+ gem "nokogiri"
18
+ gem "httparty"
19
+ gem "chronic"
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Daniel Schmidt
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,122 @@
1
+ h1. bishl
2
+
3
+ A tiny little ruby wrapper around the XML api of www.bishl.de .
4
+
5
+ h2. Installation
6
+
7
+ Installation via Bundler is easy to setup though it's not offical released.
8
+ Put the following line to your Gemfile:
9
+
10
+ <pre>
11
+ <code>
12
+ gem "bishl", :git => "git://github.com/dsci/bishl.git"
13
+ </code>
14
+ </pre>
15
+
16
+ h2. Implementations
17
+
18
+ *Pure Ruby*
19
+
20
+ For Ruby implementation take a closer look to the RSpec files. Due to the fact that the XML API of the BISHL
21
+ website currently only supports standings for several years, getting involved with the bishl Ruby gem is very
22
+ simple:
23
+
24
+ <pre>
25
+ <code>
26
+ require "rubygems"
27
+ require "bishl"
28
+
29
+ @parser = BISHL.standings(:season => "2010", :cs => "LLA")
30
+ </code>
31
+ </pre>
32
+
33
+ Same for parsing schedule.
34
+
35
+ <pre>
36
+ <code>
37
+ require "rubygems"
38
+ require "bishl"
39
+
40
+ @parser = BISHL.schedule(:season => "2010", :cs => "LLA", :team => 74)
41
+ </code>
42
+ </pre>
43
+
44
+ Note the additional team id.
45
+
46
+ It also gives you the opportunity to fetch the team's logo:
47
+
48
+ <pre>
49
+ <code>
50
+ BISHL.logo_for(:team => 74)
51
+ </code>
52
+ </pre>
53
+
54
+ which returns an url.
55
+
56
+ *Sinatra*
57
+
58
+ In your Sinatra file:
59
+ <pre>
60
+ <code>
61
+ require "rubygems"
62
+ require "bishl"
63
+
64
+ include Bishl::HtmlHelper
65
+ </code>
66
+ </pre>
67
+
68
+ In your View:
69
+
70
+ <pre>
71
+ <code>
72
+ <%=bishl_standings({:season => "2010", :cs => "LLA", :css =>
73
+ {:table_class => "myTable",
74
+ :odd_class => "myOdd",
75
+ :even_class => "myEven"}
76
+ })%>
77
+ </code>
78
+ </pre>
79
+
80
+ *Rails*
81
+
82
+ For rails just include the gem to your Gemfile and and follow the instruction at the Sinatra/View section.
83
+
84
+ h2. Possible combinations for season and league type
85
+
86
+ The creator of the BISHL website (bishl.de), Marian Strüby compiles an overview of possible combinations:
87
+
88
+ season ; cs ; Wettbwerb
89
+ ----------------------------------
90
+ 2005 ; LLB ; Landesliga B
91
+ 2005 ; JGD ; Jugend
92
+ 2005 ; LLA ; Landesliga A
93
+ 2006 ; LLB ; Landesliga B
94
+ 2006 ; LLA ; Landesliga A
95
+ 2007 ; LLA ; Landesliga A
96
+ 2008 ; LLA ; Landesliga A
97
+ 2009 ; LLA ; Landesliga A
98
+ 2010 ; LLA ; Landesliga A
99
+ 2010 ; SL ; Schülerliga
100
+ 2011 ; LLA ; Landesliga A
101
+ 2011 ; 1BLN ; 1. Bundesliga Nord
102
+ 2011 ; RLN ; Regionalliga Nord
103
+ 2011 ; 1DL ; 1. Damenliga
104
+ 2011 ; SL ; Schülerliga
105
+
106
+ Notice, that the bishl Ruby gem forces you to specify the season and cs params.
107
+
108
+
109
+
110
+ h2. Contributing to bishl
111
+
112
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
113
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
114
+ * Fork the project
115
+ * Start a feature/bugfix branch
116
+ * Commit and push until you are happy with your contribution
117
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
118
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
119
+
120
+ h2. Copyright
121
+
122
+ Copyright (c) 2011 Daniel Schmidt. See LICENSE.txt for further details.
data/Rakefile ADDED
@@ -0,0 +1,77 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "bishl"
16
+ gem.homepage = "http://github.com/dsci/bishl"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Ruby wrapper for bishl.de xml api.}
19
+ gem.description = %Q{Ruby wrapper for bishl.de xml api.}
20
+ gem.email = "dsci@code79.net"
21
+ gem.authors = ["Daniel Schmidt"]
22
+ gem.files = [
23
+ ".document",
24
+ ".rspec",
25
+ "Gemfile",
26
+ "LICENSE.txt",
27
+ "README.textile",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "lib/bishl.rb",
31
+ "lib/parser.rb",
32
+ "lib/params_builder.rb",
33
+ "lib/url.rb",
34
+ "lib/errors.rb",
35
+ "lib/schedule_line.rb",
36
+ "lib/schedule_team.rb",
37
+ "lib/html_helper.rb",
38
+ "lib/game.rb",
39
+ "lib/bishl_klass.rb",
40
+ "rails/init.rb",
41
+ "init.rb",
42
+ "spec/spec_helper.rb",
43
+ "spec/params_builder_spec.rb",
44
+ "spec/form_helper_spec.rb",
45
+ "spec/parser_spec.rb",
46
+ "spec/url_spec.rb"
47
+ ]
48
+ gem.add_runtime_dependency "nokogiri"
49
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
50
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
51
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
52
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
53
+ end
54
+ Jeweler::RubygemsDotOrgTasks.new
55
+
56
+ require 'rspec/core'
57
+ require 'rspec/core/rake_task'
58
+ RSpec::Core::RakeTask.new(:spec) do |spec|
59
+ spec.pattern = FileList['spec/**/*_spec.rb']
60
+ end
61
+
62
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
63
+ spec.pattern = 'spec/**/*_spec.rb'
64
+ spec.rcov = true
65
+ end
66
+
67
+ task :default => :spec
68
+
69
+ require 'rake/rdoctask'
70
+ Rake::RDocTask.new do |rdoc|
71
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
72
+
73
+ rdoc.rdoc_dir = 'rdoc'
74
+ rdoc.title = "bishl #{version}"
75
+ rdoc.rdoc_files.include('README*')
76
+ rdoc.rdoc_files.include('lib/**/*.rb')
77
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require (File.dirname(__FILE__) + "/rails/init")
data/lib/bishl.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "rubygems"
2
+ require 'open-uri'
3
+ require "nokogiri"
4
+ require "httparty"
5
+ require "chronic"
6
+
7
+ #Dir[File.expand_path(File.join(File.dirname(__FILE__),'lib','**','*.rb'))].each {|f| require f}
8
+ require File.dirname(__FILE__) + "/errors"
9
+ require File.dirname(__FILE__) + "/params_builder"
10
+ require File.dirname(__FILE__) + "/url"
11
+ require File.dirname(__FILE__) + "/schedule_line"
12
+ require File.dirname(__FILE__) + "/schedule_team"
13
+ require File.dirname(__FILE__) + "/parser"
14
+ require File.dirname(__FILE__) + "/html_helper"
15
+ require File.dirname(__FILE__) + "/game"
16
+ require File.dirname(__FILE__) + "/bishl_klass"
17
+
18
+
19
+
@@ -0,0 +1,54 @@
1
+ class BISHL
2
+
3
+ class << self
4
+
5
+ def schedule(opt={})
6
+ Bishl::Parser.new.parse_schedule(opt)
7
+ end
8
+
9
+ def standings(opt={})
10
+ Bishl::Parser.new.parse_standings(opt)
11
+ end
12
+
13
+
14
+ # opt(:team => 12)
15
+ # opt(:team => 12, :strip => false)
16
+ # opt[:strip] is true by default
17
+ def next_game_for(opt={})
18
+ strip = true
19
+ if opt.has_key?(:strip)
20
+ strip = opt.delete(:strip)
21
+ end
22
+ games = self.schedule(opt)
23
+ result = []
24
+ games.each do |game|
25
+ result << game if game.date >= Time.now
26
+ end
27
+ if strip
28
+ return [result.first] unless result.empty?
29
+ return [] if result.empty?
30
+ else
31
+ result
32
+ end
33
+ end
34
+
35
+ def logo_for(opt={})
36
+ # get url
37
+ url = Bishl::Url.source("logo") + "?teamid=#{opt[:team]}"
38
+ # parse html file for div class "logo"
39
+ doc = Nokogiri.HTML(open(url).read)
40
+ # get the image url from there
41
+ doc.xpath('//div[@class="logo"]/img').each do |found|
42
+ found.attributes.each do |attr|
43
+ if attr.include?("src")
44
+ logo_path = "#{Bishl::Url.base}/#{attr.last.value}"
45
+ logo_path
46
+ return logo_path
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end
data/lib/errors.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Bishl
2
+
3
+ class OptionsNotMetError < StandardError; end
4
+
5
+ end
data/lib/game.rb ADDED
@@ -0,0 +1,11 @@
1
+ module Bishl
2
+ class Game < Struct.new(:startdate,:hometeam,:awayteam,:gameid,:stadium,:goalshome,:goalsaway,:overtime,:shootout,
3
+ :awayteamid,:hometeamid)
4
+
5
+ alias_method :date, :startdate
6
+ alias_method :id, :gameid
7
+ alias_method :awayteam_id, :awayteamid
8
+ alias_method :hometeam_id, :hometeamid
9
+
10
+ end
11
+ end
@@ -0,0 +1,118 @@
1
+ module Bishl
2
+
3
+ module HTMLHelper
4
+ # opt => {:type => :small, :season => "2010", :cs => "LLA", :css =>
5
+ # {:table_class => "myTable", :odd_class => "myOdd",:even_class => "myEven"
6
+ # }
7
+ #
8
+ def bishl_standings(opt={})
9
+ begin
10
+ table_class = ""
11
+ odd_class = ""
12
+ even_class = ""
13
+ type = opt.has_key?(:type) ? opt[:type] : :large
14
+ if opt.has_key?(:css)
15
+ table_class = opt[:css][:table_class] if opt[:css].has_key?(:table_class)
16
+ odd_class = opt[:css][:odd_class] if opt[:css].has_key?(:odd_class)
17
+ even_class = opt[:css][:even_class] if opt[:css].has_key?(:even_class)
18
+ end
19
+
20
+ parser = Bishl::Parser.new
21
+ data = parser.parse_standings(:season => opt[:season], :cs => opt[:cs])
22
+
23
+ return no_data_fetch(table_class) if data.empty?
24
+
25
+ self.send(type, data,table_class,odd_class,even_class)
26
+
27
+
28
+ end
29
+ rescue => e
30
+ no_data_fetch(opt[:table_class])
31
+ end
32
+
33
+ private
34
+
35
+ def css_klass_for_line(opt={})
36
+ opt[:index].to_i.even? ? opt[:even] : opt[:odd]
37
+ end
38
+
39
+ def no_data_fetch(css_klass)
40
+ "<div class=\"#{css_klass}\">No data found</div>"
41
+ end
42
+
43
+ def small(data,table_class,odd_class,even_class)
44
+ head = <<-HTML
45
+ <table class="#{table_class}" border="0" cellpadding="0" cellspacing="0">
46
+ <thead>
47
+ <tr>
48
+ <th>Pos</th>
49
+ <th>Team</th>
50
+ <th>GS</th>
51
+ <th>Pkt</th>
52
+ </tr>
53
+ </thead>
54
+ HTML
55
+ body = "<tbody>"
56
+ data.each do |entry|
57
+ body += <<-HTML
58
+ <tr class="#{css_klass_for_line({:index => entry.position, :even => even_class, :odd => odd_class})}">
59
+ <td>#{entry.position}</td>
60
+ <td>#{entry.team.teamname}</td>
61
+ <td>#{entry.team.gamesplayed}</td>
62
+ <td>#{entry.team.points}</td>
63
+ </tr>
64
+ HTML
65
+ end
66
+ body += "</tbody></table>"
67
+ "#{head}#{body}"
68
+ end
69
+
70
+ def large(data,table_class,odd_class,even_class)
71
+ head = <<-HTML
72
+ <table class="#{table_class}" border="0" cellpadding="0" cellspacing="0">
73
+ <thead>
74
+ <tr>
75
+ <th>Pos</th>
76
+ <th>Team</th>
77
+ <th>GS</th>
78
+ <th>S</th>
79
+ <th>N</th>
80
+ <th>U</th>
81
+ <th>SV</th>
82
+ <th>NV</th>
83
+ <th>SP</th>
84
+ <th>NP</th>
85
+ <th>P</th>
86
+ <th>GT</th>
87
+ <th>TD</th>
88
+ <th>+/-</th>
89
+ </tr>
90
+ </thead>
91
+ HTML
92
+ body = "<tbody>"
93
+ data.each do |entry|
94
+ body += <<-HTML
95
+ <tr class="#{css_klass_for_line({:index => entry.position, :even => even_class, :odd => odd_class})}">
96
+ <td>#{entry.position}</td>
97
+ <td>#{entry.team.teamname}</td>
98
+ <td>#{entry.team.gamesplayed}</td>
99
+ <td>#{entry.team.wins}</td>
100
+ <td>#{entry.team.losses}</td>
101
+ <td>#{entry.team.ties}</td>
102
+ <td>#{entry.team.otwins}</td>
103
+ <td>#{entry.team.otlosses}</td>
104
+ <td>#{entry.team.sowins}</td>
105
+ <td>#{entry.team.solosses}</td>
106
+ <td>#{entry.team.points}</td>
107
+ <td>#{entry.team.goalsfor}</td>
108
+ <td>#{entry.team.goalsagainst}</td>
109
+ <td>#{entry.team.goals_diff}</td>
110
+ </tr>
111
+ HTML
112
+ end
113
+ body += "</tbody></table>"
114
+ "#{head}#{body}"
115
+ end
116
+
117
+ end
118
+ end
@@ -0,0 +1,22 @@
1
+ module Bishl
2
+
3
+ class ParamsBuilder
4
+
5
+ class << self
6
+
7
+ def build_link(options={})
8
+ raise OptionsNotMetError, "season missing" unless options.has_key?(:season)
9
+ raise OptionsNotMetError, "league missing" unless options.has_key?(:cs)
10
+
11
+ url = "?season=#{options[:season]}&cs=#{options[:cs]}"
12
+ if options.has_key?(:team)
13
+ url = "#{url}&team=#{options[:team]}"
14
+ end
15
+ return url
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+ end
data/lib/parser.rb ADDED
@@ -0,0 +1,65 @@
1
+ module Bishl
2
+
3
+ class Parser
4
+
5
+ # opt => {:season => "2010", :cs => "LLA"}
6
+ # Returns an array of schedule_lines
7
+ def parse_standings(opt={})
8
+ begin
9
+ url = ParamsBuilder.build_link(opt)
10
+ xml = fetch(url,"standings")
11
+ data = []
12
+ xml.xpath("//team").each do |inf|
13
+ c = ScheduleLine.new
14
+
15
+ inf.children.each do |child|
16
+ if(child.is_a?(Nokogiri::XML::Element))
17
+ #puts "#{child.name} - #{child.text}"
18
+ #c.create_line({:name => child.name, :text => child.text})
19
+ c.send("create_#{child.name}", child.text)
20
+
21
+ end
22
+
23
+ #c.send("#{child.name.to_s}=",child['data'])
24
+ end
25
+ data << c
26
+
27
+ end
28
+ return data
29
+ rescue => e
30
+ raise e
31
+ end
32
+ end
33
+
34
+ def parse_schedule(opt={})
35
+ begin
36
+ url = ParamsBuilder.build_link(opt)
37
+ xml = fetch(url,"schedule")
38
+ data = []
39
+ xml.xpath("//game").each do |line|
40
+ g = Game.new
41
+ line.children.each do |child|
42
+ #puts child.text if child.name.match(/gameid/)
43
+ if child.name.match(/startdate/)
44
+ g.send("#{child.name}=", Chronic.parse(child.text))
45
+ else
46
+ g.send("#{child.name}=", child.text) if g.respond_to?(child.name.to_sym)
47
+ end
48
+ end
49
+ data << g
50
+ end
51
+ return data
52
+ rescue => e
53
+ raise e
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def fetch(url,type)
60
+ uri = Bishl::Url.source(type) << url
61
+ Nokogiri.XML(open(uri).read)
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,28 @@
1
+ module Bishl
2
+ class ScheduleLine < Struct.new(:position)
3
+
4
+ attr_accessor :team
5
+
6
+ def initialize
7
+ @team = ScheduleTeam.new
8
+ end
9
+
10
+ def method_missing(method, *arguments, &block)
11
+ #puts method.to_s
12
+ match = method.to_s =~/create_/
13
+ #puts match
14
+ if match
15
+ name = method.to_s.split("_")[1]
16
+
17
+ if(name=="position")
18
+ self.send("position=", arguments.pop)
19
+ else
20
+ @team.send("#{name}=", arguments.pop)
21
+ end
22
+ else
23
+ super
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ module Bishl
2
+ class ScheduleTeam < Struct.new(:teamname, :wins,:losses, :ties,:otwins,
3
+ :otlosses,:sowins,:points,:goalsfor,
4
+ :goalsagainst,:gamesplayed,:solosses,
5
+ :schedule)
6
+
7
+ class << self
8
+
9
+ def create(options={})
10
+
11
+ end
12
+
13
+ end
14
+
15
+ def goals_diff
16
+ self.goalsfor.to_i - self.goalsagainst.to_i
17
+ end
18
+
19
+ end
20
+ end
data/lib/url.rb ADDED
@@ -0,0 +1,21 @@
1
+ module Bishl
2
+
3
+ module Url
4
+
5
+ extend self
6
+
7
+ def base
8
+ "http://www.bishl.de"
9
+ end
10
+
11
+ def source(type)
12
+ case type
13
+ when "standings" then "#{base}/rss/standings.xml.php"
14
+ when "schedule" then "#{base}//rss/schedule.xml.php"
15
+ when "logo" then "#{base}//teams.php"
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "bishl"
2
+
3
+ # for rails:
4
+
5
+ unless defined?(ApplicationHelper).nil?
6
+ ApplicationHelper.class_eval do
7
+ ActionView::Base.send :include, BISHL::HTMLHelper
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "FormHelper" do
4
+
5
+ include Bishl::HTMLHelper
6
+
7
+ it "should generate a large html table output" do
8
+ output = bishl_standings(:season => "2010", :cs => "LLA")
9
+ output.should include("<table")
10
+ output.should include("Pos")
11
+ end
12
+
13
+ it "should generate a small html table output" do
14
+ output = bishl_standings(:season => "2010", :cs => "LLA", :type => :small)
15
+ output.should include("Pkt")
16
+ output.should_not include("N")
17
+ end
18
+
19
+ it "should render an info message if no data could be fetched" do
20
+ output = bishl_standings({:season => "2009", :cs => "1BLN", :css => {:table_class => "foo"}})
21
+ output.should == "<div class=\"foo\">No data found</div>"
22
+ end
23
+
24
+ it "should return even css klass variable if position is an even number" do
25
+
26
+ Bishl::HTMLHelper.class_eval do
27
+ public :css_klass_for_line
28
+ end
29
+
30
+ even_class = "even"
31
+ odd_class = "odd"
32
+ result = css_klass_for_line({:index => 2, :even => even_class, :odd => odd_class})
33
+ result.should == even_class
34
+ result2 = css_klass_for_line({:index => 1, :even => even_class, :odd => odd_class})
35
+ result2.should == odd_class
36
+ end
37
+
38
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "ParamsBuilder" do
4
+
5
+ context "for league standings" do
6
+
7
+ it "should build correct link for 2010 and Landesliga" do
8
+ expected = "?season=2010&cs=LLA"
9
+ result = Bishl::ParamsBuilder.build_link({:season => "2010", :cs => "LLA"})
10
+ result.should == expected
11
+ end
12
+
13
+ it "should build correct link for 2011 and 1.Bundesliga Nord" do
14
+ expected = "?season=2011&cs=1BLN"
15
+ result = Bishl::ParamsBuilder.build_link({:season => "2011", :cs => "1BLN"})
16
+ result.should == expected
17
+ end
18
+
19
+ it "should build correct link for 2011 and Landesliga and given Team" do
20
+ expected = "?season=2011&cs=LLA&team=74"
21
+ result = Bishl::ParamsBuilder.build_link({:season => "2011", :cs => "LLA", :team => "74"})
22
+ result.should == expected
23
+ end
24
+
25
+ end
26
+
27
+ context "for league standings" do
28
+
29
+ context "forcing attributes" do
30
+
31
+ it "should raise an OptionsNotMetError" do
32
+
33
+ expect{Bishl::ParamsBuilder.build_link}.to raise_error Bishl::OptionsNotMetError
34
+ expect{Bishl::ParamsBuilder.build_link(:cs => "LLA")}.to raise_error Bishl::OptionsNotMetError
35
+ expect{Bishl::ParamsBuilder.build_link(:season => "2010")}.to raise_error Bishl::OptionsNotMetError
36
+
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+
44
+ end
@@ -0,0 +1,58 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Parser" do
4
+
5
+ subject do
6
+ @parser ||= Bishl::Parser.new
7
+ end
8
+
9
+ it "should parse the standings url" do
10
+ parse = proc{subject.parse_standings(:season => "2010", :cs => "LLA")}
11
+ lambda{ parse.call }.should_not raise_error
12
+ parse.call.should_not be_empty
13
+ end
14
+
15
+ context "schedule" do
16
+ it "parse the schedule for given team" do
17
+ parse = proc {subject.parse_schedule(:season => "2011", :cs => "LLA", :team => "74")}
18
+ lambda{parse.call}.should_not raise_error
19
+ parse.call.first.id.should == 1058.to_s
20
+ parse.call.should have(11).items
21
+ end
22
+
23
+ it "parse the next game for given team" do
24
+ parse = proc {BISHL.next_game_for(:season => "2010", :cs => "LLA", :team => "74")}
25
+ parse.call.should have(0).items
26
+
27
+ parse = proc {BISHL.next_game_for(:season => "2011", :cs => "LLA", :team => "74")}
28
+ parse.call.should have(1).items
29
+ end
30
+
31
+ context "stripped" do
32
+
33
+ it "parse the next game for given team and returns it as a single array" do
34
+ parse = proc {BISHL.next_game_for(:season => "2011", :cs => "LLA", :team => "74")}
35
+ parse.call.should have(1).items
36
+ end
37
+
38
+ end
39
+
40
+ context "not stripped" do
41
+
42
+ it "parse the next game for given team and returns it as an array" do
43
+ parse = proc {BISHL.next_game_for(:season => "2011", :cs => "LLA", :team => "74", :strip => false)}
44
+ parse.call.should_not have(1).items
45
+ end
46
+
47
+ end
48
+
49
+ context "logo" do
50
+ it "fetch for team" do
51
+ parse = BISHL.logo_for(:team => 74)
52
+ expected = "http://www.bishl.de/img/logo/club15.png"
53
+ parse.should == expected
54
+ end
55
+ end
56
+ end
57
+
58
+ end
@@ -0,0 +1,29 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'vcr'
5
+ require "bishl"
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ # configure vcr
12
+ #VCR.config do |c|
13
+ # c.cassette_library_dir = '#{File.dirname(__FILE__)}/fixtures/vcr_cassettes'
14
+ # c.stub_with :webmock # or :fakeweb
15
+ #end
16
+
17
+
18
+
19
+ RSpec.configure do |config|
20
+
21
+ config.before do
22
+ #VCR.use_cassette('synopsis') do
23
+ # Net::HTTP.get_response(URI('http://www.bishl.de/rss/schedule.xml.php?season=2011&cs=LLA'))
24
+ #end
25
+ end
26
+
27
+ end
28
+
29
+
data/spec/url_spec.rb ADDED
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+
4
+ describe "Bishl::Url" do
5
+
6
+ it "should return the url for the bishl xml interface" do
7
+ url = "http://www.bishl.de/rss/standings.xml.php"
8
+ Bishl::Url.source.should == url
9
+ end
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,240 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bishl
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Daniel Schmidt
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-24 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ type: :runtime
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ name: nokogiri
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ prerelease: false
37
+ type: :runtime
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ name: httparty
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ prerelease: false
51
+ type: :runtime
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ name: chronic
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ prerelease: false
65
+ type: :development
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 2
74
+ - 3
75
+ - 0
76
+ version: 2.3.0
77
+ name: rspec
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ prerelease: false
81
+ type: :development
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ hash: 23
88
+ segments:
89
+ - 1
90
+ - 0
91
+ - 0
92
+ version: 1.0.0
93
+ name: bundler
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ prerelease: false
97
+ type: :development
98
+ requirement: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ hash: 7
104
+ segments:
105
+ - 1
106
+ - 5
107
+ - 2
108
+ version: 1.5.2
109
+ name: jeweler
110
+ version_requirements: *id006
111
+ - !ruby/object:Gem::Dependency
112
+ prerelease: false
113
+ type: :development
114
+ requirement: &id007 !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ hash: 3
120
+ segments:
121
+ - 0
122
+ version: "0"
123
+ name: rcov
124
+ version_requirements: *id007
125
+ - !ruby/object:Gem::Dependency
126
+ prerelease: false
127
+ type: :development
128
+ requirement: &id008 !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ hash: 3
134
+ segments:
135
+ - 0
136
+ version: "0"
137
+ name: vcr
138
+ version_requirements: *id008
139
+ - !ruby/object:Gem::Dependency
140
+ prerelease: false
141
+ type: :development
142
+ requirement: &id009 !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ hash: 3
148
+ segments:
149
+ - 0
150
+ version: "0"
151
+ name: webmock
152
+ version_requirements: *id009
153
+ - !ruby/object:Gem::Dependency
154
+ prerelease: false
155
+ type: :runtime
156
+ requirement: &id010 !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ hash: 3
162
+ segments:
163
+ - 0
164
+ version: "0"
165
+ name: nokogiri
166
+ version_requirements: *id010
167
+ description: Ruby wrapper for bishl.de xml api.
168
+ email: dsci@code79.net
169
+ executables: []
170
+
171
+ extensions: []
172
+
173
+ extra_rdoc_files:
174
+ - LICENSE.txt
175
+ - README.textile
176
+ files:
177
+ - .document
178
+ - .rspec
179
+ - Gemfile
180
+ - LICENSE.txt
181
+ - README.textile
182
+ - Rakefile
183
+ - VERSION
184
+ - init.rb
185
+ - lib/bishl.rb
186
+ - lib/bishl_klass.rb
187
+ - lib/errors.rb
188
+ - lib/game.rb
189
+ - lib/html_helper.rb
190
+ - lib/params_builder.rb
191
+ - lib/parser.rb
192
+ - lib/schedule_line.rb
193
+ - lib/schedule_team.rb
194
+ - lib/url.rb
195
+ - rails/init.rb
196
+ - spec/form_helper_spec.rb
197
+ - spec/params_builder_spec.rb
198
+ - spec/parser_spec.rb
199
+ - spec/spec_helper.rb
200
+ - spec/url_spec.rb
201
+ has_rdoc: true
202
+ homepage: http://github.com/dsci/bishl
203
+ licenses:
204
+ - MIT
205
+ post_install_message:
206
+ rdoc_options: []
207
+
208
+ require_paths:
209
+ - lib
210
+ required_ruby_version: !ruby/object:Gem::Requirement
211
+ none: false
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ hash: 3
216
+ segments:
217
+ - 0
218
+ version: "0"
219
+ required_rubygems_version: !ruby/object:Gem::Requirement
220
+ none: false
221
+ requirements:
222
+ - - ">="
223
+ - !ruby/object:Gem::Version
224
+ hash: 3
225
+ segments:
226
+ - 0
227
+ version: "0"
228
+ requirements: []
229
+
230
+ rubyforge_project:
231
+ rubygems_version: 1.6.2
232
+ signing_key:
233
+ specification_version: 3
234
+ summary: Ruby wrapper for bishl.de xml api.
235
+ test_files:
236
+ - spec/form_helper_spec.rb
237
+ - spec/params_builder_spec.rb
238
+ - spec/parser_spec.rb
239
+ - spec/spec_helper.rb
240
+ - spec/url_spec.rb