williamhill 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,148 @@
1
+ require 'spec_helper'
2
+
3
+ describe WilliamHill do
4
+ subject { WilliamHill.new(43) }
5
+
6
+ describe :methods do
7
+ describe :get_sports do
8
+ before :all do
9
+ stub_request(:any, /.*/).to_return(:body => mock_output("sports.xml"))
10
+ @sports = WilliamHill.get_sports
11
+ end
12
+
13
+ it "should return a hash" do
14
+ @sports.class.should == Hash
15
+ end
16
+
17
+ it "should return the correct number of sports" do
18
+ @sports.count.should == 80
19
+ end
20
+
21
+ it "should return the correct sports" do
22
+ @sports.keys.should == ["American Football", "American Football Specials", "Baseball", "European Basketball", "International Cricket", "UK Domestic Cricket", "Darts", "Darts Specials", "UK Football", "International Football", "European Major Leagues", "Other League Football", "UEFA Club Competitions", "Football Specials", "Football - Virtual", "Golf Majors", "Mens Golf", "Golf Specials", "Greyhounds - Live", "Greyhound Hurdles - Virtual", "Greyhounds - Virtual", "Greyhounds - Trap Challenge", "Greyhounds - Antepost", "Greyhounds - Specials", "Horse Racing - Live", "Horse Racing Sprint - Virtual", "Horse National Hunt - Virtual", "Horse Racing - Antepost", "Horse Racing - Tote Pools", "Horse Racing - Specials", "NHL", "International Ice Hockey", "European Ice Hockey", "Formula 1", "Motor", "Speedway", "NASCAR", "Rally", "Moto GP", "Archery", "Athletics", "Badminton", "Beach Volleyball", "Boxing", "UFC / MMA", "Canoeing", "Cycling", "Cycling - Virtual", "Diving", "Equestrian", "Fencing", "GAA Football", "Gymnastics", "Handball", "Hockey", "GAA Hurling", "Judo", "Rowing", "Shooting", "Swimming", "Sync Swimming", "Table Tennis", "Triathlon", "Volleyball", "Water Polo", "Weightlifting", "Wrestling", "Yachting/Sailing", "Politics", "Rugby League", "Rugby Union", "Snooker", "TV Specials", "Other Specials", "Weather Specials", "Grand Slam Tennis", "Mens Tennis", "Womens Tennis", "Challenger Tennis", "Tennis Specials"]
23
+ end
24
+
25
+ it "should return the correct ids" do
26
+ @sports.values.should == ["19", "380", "15", "273", "42", "9", "335", "384", "1", "36", "46", "274", "275", "276", "436", "8", "40", "385", "3", "438", "330", "280", "17", "386", "2", "439", "442", "13", "38", "323", "32", "401", "283", "5", "412", "419", "285", "25", "420", "339", "295", "296", "342", "10", "402", "343", "301", "437", "344", "302", "345", "348", "22", "303", "304", "349", "350", "357", "358", "318", "360", "319", "362", "320", "321", "363", "364", "322", "52", "325", "7", "334", "37", "294", "293", "45", "43", "308", "424", "392"]
27
+ end
28
+ end
29
+
30
+ describe "instance methods" do
31
+ describe "with real requests" do
32
+ before :all do
33
+ WebMock.allow_net_connect!
34
+ sport_id = WilliamHill.get_sports.values.first
35
+ @william_hill = WilliamHill.new(sport_id)
36
+ end
37
+
38
+ describe :get_competitions do
39
+ it "should return the correct type" do
40
+ @william_hill.get_competitions.class.should == Array
41
+ end
42
+ end
43
+
44
+ describe :get_markets do
45
+ it "should return the correct type" do
46
+ @william_hill.get_markets.class.should == Array
47
+ end
48
+ end
49
+
50
+ describe :get_participants do
51
+ it "should return the correct type" do
52
+ market = @william_hill.get_markets.first
53
+ @william_hill.get_participants(market).class.should == Array
54
+ end
55
+ end
56
+
57
+ describe :get_full_markets do
58
+ it "should return the correct type" do
59
+ @william_hill.get_full_markets.class.should == Array
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "with stubbed requests" do
65
+ describe :get_competitions do
66
+ before :all do
67
+ stub_request(:any, /.*/).to_return(:body => mock_output("events.xml"))
68
+ @events = subject.get_competitions
69
+ end
70
+
71
+ it "should return an Array" do
72
+ @events.class.should == Array
73
+ end
74
+
75
+ it "should return the correct number of events" do
76
+ @events.count.should == 2
77
+ end
78
+
79
+ it "should return the correct events" do
80
+ @events.should == ["Olympics - Women's Basketball", "Olympics - Men's Basketball"]
81
+ end
82
+ end
83
+
84
+ describe :get_markets do
85
+ context "markets from all events" do
86
+ before :all do
87
+ stub_request(:any, /.*/).to_return(:body => mock_output("events.xml"))
88
+ @markets = subject.get_markets
89
+ end
90
+
91
+ it "should return the correct number of markets" do
92
+ @markets.count.should == 14
93
+ end
94
+ end
95
+
96
+ context "markets from a given event" do
97
+ before :all do
98
+ stub_request(:any, /.*/).to_return(:body => mock_output("events.xml"))
99
+ @markets = subject.get_markets(subject.get_competitions.first)
100
+ end
101
+
102
+ it "should return the correct markets" do
103
+ @markets.should == ["China v Czech Republic - Money Line", "Russia v Canada - Money Line", "Canada v Russia - Money Line", "Turkey v Angola - Money Line", "USA v Croatia - Money Line", "France v Brazil - Money Line", "Brazil v France - Money Line", "Australia v Great Britain - Money Line"]
104
+ end
105
+ end
106
+ end
107
+
108
+ describe :get_participants do
109
+ before :all do
110
+ stub_request(:any, /.*/).to_return(:body => mock_output("events.xml"))
111
+ @participants = subject.get_participants(subject.get_markets.first)
112
+ end
113
+
114
+ it "should return a hash with the odds" do
115
+ @participants.should == [{:name=>"China", :odds=>"2.15"}, {:name=>"Czech Republic", :odds=>"1.62"}]
116
+ end
117
+ end
118
+
119
+ describe :get_full_markets do
120
+ before :all do
121
+ stub_request(:any, /.*/).to_return(:body => mock_output("events.xml"))
122
+ @full_markets = subject.get_full_markets
123
+ end
124
+
125
+ it "should parse correctly the id" do
126
+ @full_markets.last[:id].should == "39371471"
127
+ end
128
+
129
+ it "should parse correctly the name" do
130
+ @full_markets.last[:name].should == "Argentina v Lithuania - Money Line"
131
+ end
132
+
133
+ it "should parse correctly the participants" do
134
+ @full_markets.last[:participants].should == [{:id=>"165143361", :name=>"Lithuania", :odds=>"2.25"}, {:id=>"165143364", :name=>"Argentina", :odds=>"1.57"}]
135
+ end
136
+
137
+ it "should parse correctly the time" do
138
+ @full_markets.last[:time].should == "2012-07-29 21:15:00 UTC".to_time
139
+ end
140
+
141
+ it "should parse correctly the bet limit time" do
142
+ @full_markets.last[:bet_limit_time].should == "2012-07-29 21:15:00 UTC".to_time
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/williamhill/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Cristian Planas"]
6
+ gem.email = ["me@cristianplanas.com"]
7
+ gem.description = %q{A Ruby wrapper for the William Hill API}
8
+ gem.summary = %q{A Ruby wrapper for the William Hill API}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "williamhill"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Williamhill::VERSION
17
+
18
+ gem.add_runtime_dependency 'nokogiri'
19
+ gem.add_runtime_dependency 'activesupport'
20
+ gem.add_development_dependency 'rspec'
21
+ gem.add_development_dependency 'webmock'
22
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: williamhill
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Cristian Planas
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-10-07 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nokogiri
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: activesupport
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: webmock
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ type: :development
58
+ version_requirements: *id004
59
+ description: A Ruby wrapper for the William Hill API
60
+ email:
61
+ - me@cristianplanas.com
62
+ executables: []
63
+
64
+ extensions: []
65
+
66
+ extra_rdoc_files: []
67
+
68
+ files:
69
+ - .gitignore
70
+ - .rspec
71
+ - Gemfile
72
+ - LICENSE
73
+ - README.md
74
+ - Rakefile
75
+ - lib/williamhill.rb
76
+ - lib/williamhill/version.rb
77
+ - lib/williamhill/williamhill.rb
78
+ - spec/spec_helper.rb
79
+ - spec/support/aux_methods.rb
80
+ - spec/support/events.xml
81
+ - spec/support/sports.xml
82
+ - spec/william_hill_spec.rb
83
+ - williamhill.gemspec
84
+ homepage: ""
85
+ licenses: []
86
+
87
+ post_install_message:
88
+ rdoc_options: []
89
+
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ requirements: []
105
+
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.15
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: A Ruby wrapper for the William Hill API
111
+ test_files:
112
+ - spec/spec_helper.rb
113
+ - spec/support/aux_methods.rb
114
+ - spec/support/events.xml
115
+ - spec/support/sports.xml
116
+ - spec/william_hill_spec.rb