openfooty 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
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.md ADDED
@@ -0,0 +1,45 @@
1
+ # Openfooty
2
+
3
+ This is a Ruby wrapper for the [Openfooty API](http://www.footytube.com/openfooty/karma.php).
4
+
5
+ ## Installation
6
+
7
+ As a gem:
8
+
9
+ sudo gem install openfooty
10
+
11
+ As a plugin (in your Rails directory:
12
+
13
+ script/plugin install git://github.com/phuphighter/openfooty.git
14
+
15
+ ## Get a Openfooty API key
16
+
17
+ Sign up for a Openfooty API key: [http://www.footytube.com/openfooty/signup.php](http://www.footytube.com/openfooty/signup.php)
18
+
19
+ ## Usage
20
+
21
+ ### Configure
22
+
23
+ >> Openfooty.api_key = "your_api_key" or Openfooty::Client.new(:api_key => "your_api_key")
24
+
25
+ ### or in an initializer
26
+
27
+ >> Openfooty.configure do |config|
28
+ >> config.api_key = 'your_api_key'
29
+ >> end
30
+
31
+ #### Examples
32
+
33
+ >> openfooty = Openfooty::Client.new
34
+ >> openfooty.team("getSquad", :team_id => 2281)
35
+ => {"openfooty"=>{"players"=>{"player"=>[{"position"=>"", "cdata"=>"B. Bradley", "id"=>"130156"}, {"position"=>"Goalkeeper", "cdata"=>"B. Guzan", "id"=>"6912"}, {"position"=>"Goalkeeper", "cdata"=>"M. Hahnemann", "id"=>"629"}, {"position"=>"Goalkeeper", "cdata"=>"T. Howard", "id"=>"632"}, {"position"=>"Defender", "cdata"=>"C. Bocanegra", "id"=>"643"}, {"position"=>"Defender", "cdata"=>"J. Bornstein", "id"=>"6906"}, {"position"=>"Defender", "cdata"=>"S. Cherundolo", "id"=>"104666"}, {"position"=>"Defender", "cdata"=>"J. DeMerit", "id"=>"2541"}, {"position"=>"Defender", "cdata"=>"C. Goodson", "id"=>"7261"}, {"position"=>"Defender", "cdata"=>"C. Marshall", "id"=>"7214"}, {"position"=>"Defender", "cdata"=>"O. Onyewu", "id"=>"655"}, {"position"=>"Defender", "cdata"=>"H. Pearce", "id"=>"16404"}, {"position"=>"Defender", "cdata"=>"J. Spector", "id"=>"2712"}, {"position"=>"Midfielder", "cdata"=>"D. Beasley", "id"=>"659"}, {"position"=>"Midfielder", "cdata"=>"A. Bedoya", "id"=>"76707"}, {"position"=>"Midfielder", "cdata"=>"M. Bradley", "id"=>"2304"}, {"position"=>"Midfielder", "cdata"=>"R. Clark", "id"=>"10049"}, {"position"=>"Midfielder", "cdata"=>"C. Dempsey", "id"=>"664"}, {"position"=>"Midfielder", "cdata"=>"L. Donovan", "id"=>"666"}, {"position"=>"Midfielder", "cdata"=>"M. Edu", "id"=>"7452"}, {"position"=>"Midfielder", "cdata"=>"B. Feilhaber", "id"=>"2008"}, {"position"=>"Midfielder", "cdata"=>"S. Holden", "id"=>"7305"}, {"position"=>"Midfielder", "cdata"=>"S. Kljestan", "id"=>"6915"}, {"position"=>"Midfielder", "cdata"=>"R. Rogers", "id"=>"7226"}, {"position"=>"Midfielder", "cdata"=>"J. Torres", "id"=>"14359"}, {"position"=>"Attacker", "cdata"=>"J. Altidore", "id"=>"7422"}, {"position"=>"Attacker", "cdata"=>"E. Buddle", "id"=>"7445"}, {"position"=>"Attacker", "cdata"=>"B. Ching", "id"=>"673"}, {"position"=>"Attacker", "cdata"=>"R. Findley", "id"=>"7345"}, {"position"=>"Attacker", "cdata"=>"H. Gómez", "id"=>"6937"}, {"position"=>"Attacker", "cdata"=>"E. Johnson", "id"=>"674"}], "team_id"=>"2281"}, "response"=>{"status"=>"ok"}, "version"=>"1.0"}}
36
+
37
+ >> openfooty.match("getStats", :match_id => 781532)
38
+ => {"openfooty"=>{"version"=>"1.0", "match"=>{"home_team"=>{"name"=>{"cdata"=>"Everton"}, "goals"=>{"goal"=>{"player_name"=>"D. Bilyaletdinov", "time"=>90, "player_id"=>6472, "type"=>"normal"}, "count"=>1}, "cards"=>{"count"=>0}, "assists"=>{"count"=>1, "assist"=>{"player_name"=>"J. Heitinga", "time"=>90, "player_id"=>17}}, "id"=>"674", "lineup"=>{"player"=>[{"cdata"=>"T. Howard", "id"=>632}, {"cdata"=>"L. Baines", "id"=>2672}, {"cdata"=>"P. Jagielka", "id"=>2600}, {"cdata"=>"T. Hibbert", "id"=>2868}, {"cdata"=>"S. Distin", "id"=>2846}, {"cdata"=>"M. Arteta", "id"=>2876}, {"cdata"=>"S. Pienaar", "id"=>1960}, {"cdata"=>"L. Osman", "id"=>2880}, {"cdata"=>"J. Rodwell", "id"=>23173}, {"cdata"=>"V. Anichebe", "id"=>2886}, {"cdata"=>"L. Saha", "id"=>552}], "substitution"=>[{"cdata"=>"A. Yakubu for J. Rodwell (55)", "player_id_on"=>"2839", "player_id_off"=>"23173"}, {"cdata"=>"D. Bilyaletdinov for V. Anichebe (66)", "player_id_on"=>"6472", "player_id_off"=>"2886"}, {"cdata"=>"J. Heitinga for M. Arteta (84)", "player_id_on"=>"17", "player_id_off"=>"2876"}]}}, "winner"=>{"cdata"=>"674"}, "date"=>{"cdata"=>"2010-05-09 15:00:00"}, "away_team"=>{"name"=>{"cdata"=>"Portsmouth"}, "goals"=>{"count"=>0}, "cards"=>{"count"=>0}, "assists"=>{"count"=>0}, "id"=>"673", "lineup"=>{"player"=>[{"cdata"=>"J. Ashdown", "id"=>2638}, {"cdata"=>"M. Wilson", "id"=>22852}, {"cdata"=>"A. Mokoena", "id"=>2687}, {"cdata"=>"Ricardo Rocha", "id"=>4531}, {"cdata"=>"A. Vanden Borre", "id"=>4585}, {"cdata"=>"S. Finnan", "id"=>2966}, {"cdata"=>"Bouba Diop", "id"=>2751}, {"cdata"=>"H. Mullins", "id"=>2722}, {"cdata"=>"K. Boateng", "id"=>1870}, {"cdata"=>"F. Piquionne", "id"=>1328}, {"cdata"=>"J. Utaka", "id"=>1471}], "substitution"=>[{"cdata"=>"J. O'Hara for M. Wilson (45)", "player_id_on"=>"5888", "player_id_off"=>"22852"}, {"cdata"=>"T. Ben Haim for A. Mokoena (66)", "player_id_on"=>"2625", "player_id_off"=>"2687"}, {"cdata"=>"A. Basinas for F. Piquionne (77)", "player_id_on"=>"3605", "player_id_off"=>"1328"}]}}, "status"=>{"cdata"=>"Played"}, "score"=>{"cdata"=>"1-0"}, "ht_score"=>{"cdata"=>"0-0"}}}}
39
+
40
+
41
+ ## Copyright
42
+
43
+ Contact me if you have any suggestions and feel free to fork it!
44
+
45
+ Copyright (c) 2009 Johnny Khai Nguyen, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ # require "mg"
2
+ #
3
+ # MG.new("openfooty.gemspec")
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = "openfooty"
9
+ gem.summary = %Q{Ruby wrapper for the Openfooty API}
10
+ gem.description = %Q{Ruby wrapper for the Openfooy API}
11
+ gem.email = "johnnyn@gmail.com"
12
+ gem.homepage = "http://github.com/phuphighter/openfooty"
13
+ gem.authors = ["Johnny Khai Nguyen"]
14
+
15
+ gem.add_dependency('httparty', '>= 0.5.0')
16
+ gem.add_dependency('hashie', '>= 0.1.3')
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
+ end
22
+
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:test) do |test|
25
+ test.ruby_opts = ['-rubygems'] if defined? Gem
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/*_test.rb'
28
+ end
29
+
30
+ desc "Run tests"
31
+ task :default => :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ # Include hook code here
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
data/lib/openfooty.rb ADDED
@@ -0,0 +1,38 @@
1
+ # Openfooty
2
+ gem 'httparty'
3
+ require 'httparty'
4
+ require 'hashie'
5
+
6
+ directory = File.expand_path(File.dirname(__FILE__))
7
+
8
+ Hash.send :include, Hashie::HashExtensions
9
+
10
+ module Openfooty
11
+
12
+ # create config/initializers/openfooty.rb
13
+ #
14
+ # Openfooty.configure do |config|
15
+ # config.api_key = 'api_key'
16
+ # end
17
+ # client = Openfooty::Client.new
18
+ #
19
+ # or
20
+ #
21
+ # Openfooty.api_key = 'api_key'
22
+ #
23
+ # or
24
+ #
25
+ # Openfooty::Client.new(:api_key => 'api_key', :api_type => 'api_type')
26
+
27
+ def self.configure
28
+ yield self
29
+ true
30
+ end
31
+
32
+ class << self
33
+ attr_accessor :api_key
34
+ end
35
+
36
+ end
37
+
38
+ require File.join(directory, 'openfooty', 'client')
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :openfooty do
3
+ # # Task goes here
4
+ # end
data/test/helper.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ require 'redgreen'
6
+ require 'matchy'
7
+ require 'fakeweb'
8
+
9
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
11
+ require 'openfooty'
12
+
13
+ # Set the default allow_net_connect option--usually you'll want this off.
14
+ # You don't usually want your test suite to make HTTP connections, do you?
15
+
16
+ class Test::Unit::TestCase
17
+ end
18
+
19
+ FakeWeb.allow_net_connect = false
20
+
21
+ def fixture_file(filename)
22
+ return '' if filename == ''
23
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
24
+ File.read(file_path)
25
+ end
26
+
27
+ def openfooty_url(url, options={})
28
+ url =~ /^http/ ? url : "http://api.openfooty.org/1.0#{url}"
29
+ end
30
+
31
+ def stub_get(url, filename, options={})
32
+ opts = {:body => fixture_file(filename)}.merge(options)
33
+
34
+ FakeWeb.register_uri(:get, openfooty_url(url), opts)
35
+ end
@@ -0,0 +1,35 @@
1
+ require 'helper'
2
+
3
+ class OpenfootyTest < Test::Unit::TestCase
4
+
5
+ context "Openfooty API" do
6
+
7
+ setup do
8
+ @client = Openfooty::Client.new(:api_key => 'openfooty')
9
+ end
10
+
11
+ should "return a list of fixtures for given league_id" do
12
+ stub_get("/league.getFixtures?league_id=72", "league_fixtures.json")
13
+ league_fixtures = @client.league("getFixtures", :league_id => 72).openfooty.fixtures.match
14
+ league_fixtures.size.should == 20
15
+ league_fixtures.first.home_team.cdata.should == 'South Africa'
16
+ league_fixtures.first.away_team.cdata.should == 'Mexico'
17
+ end
18
+
19
+ should "return a team squad members for a given team_id" do
20
+ stub_get("/team.getSquad?team_id=2281", "team_squad.json")
21
+ team_squad = @client.team("getSquad", :team_id => 2281).openfooty.players.player
22
+ team_squad.size.should == 31
23
+ team_squad.first.cdata.should == 'B. Bradley'
24
+ end
25
+
26
+ should "return a list of stats for a given match_id" do
27
+ stub_get("/match.getStats?match_id=781512", "match_stats.json")
28
+ match_stats = @client.match("getStats", :match_id => 781512).openfooty.match
29
+ match_stats.home_team.assists.assist.size.should == 2
30
+ match_stats.home_team.assists.assist.last.player_name.should == 'T. Cahill'
31
+ end
32
+
33
+ end
34
+
35
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openfooty
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Johnny Khai Nguyen
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-06-08 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: httparty
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 5
30
+ - 0
31
+ version: 0.5.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: hashie
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 1
44
+ - 3
45
+ version: 0.1.3
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: Ruby wrapper for the Openfooy API
49
+ email: johnnyn@gmail.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - README.md
56
+ files:
57
+ - MIT-LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - VERSION
61
+ - init.rb
62
+ - install.rb
63
+ - lib/openfooty.rb
64
+ - tasks/openfooty_tasks.rake
65
+ - test/openfooty_test.rb
66
+ - uninstall.rb
67
+ has_rdoc: true
68
+ homepage: http://github.com/phuphighter/openfooty
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --charset=UTF-8
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ requirements: []
91
+
92
+ rubyforge_project:
93
+ rubygems_version: 1.3.6
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Ruby wrapper for the Openfooty API
97
+ test_files:
98
+ - test/helper.rb
99
+ - test/openfooty_test.rb