footy 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/footy/api.rb +17 -0
- data/lib/footy/card.rb +10 -0
- data/lib/footy/commentary.rb +164 -0
- data/lib/footy/competition.rb +26 -0
- data/lib/footy/configuration.rb +21 -0
- data/lib/footy/fixture.rb +24 -0
- data/lib/footy/goal.rb +19 -0
- data/lib/footy/player.rb +12 -0
- data/lib/footy/substitution.rb +17 -0
- data/lib/footy/team.rb +9 -0
- data/lib/footy/version.rb +3 -0
- data/lib/footy.rb +22 -0
- metadata +55 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cf582dedd0e62a8d95112f26cdba29ea66c56d0b
|
4
|
+
data.tar.gz: 4cef928f2751dae1e4411de61997b15b4bb4d195
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4736bae5c900f8ffe21d4ddd96de3cd7d113458f36402c51e2afbe86259868b78f4dcd134f558a6eb4d3f84200ca3b2531b0f193ea96102909bbce5999488fb9
|
7
|
+
data.tar.gz: 3bca618ac215c8949d4a232578d452e6315b1448fe4a19de6b3ad240e5de086d5ec66332ec01d00609f42273dfcc3bd91428e69183d9082332cee6fc3bb519c9
|
data/lib/footy/api.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
module Footy
|
4
|
+
class Api
|
5
|
+
class << self
|
6
|
+
def call options={}
|
7
|
+
JSON.parse(Net::HTTP.get_response(URI.parse(url(options))).body)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
def url options={}
|
12
|
+
options['APIKey'] = Footy.configuration.api_key
|
13
|
+
options.inject(Footy.configuration.api_url){|q, o| q += "#{o.first}=#{o.last}&"}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/footy/card.rb
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
module Footy
|
2
|
+
class Commentary
|
3
|
+
attr_accessor :info,
|
4
|
+
:localteam_players,
|
5
|
+
:visitorteam_players,
|
6
|
+
:commentaries,
|
7
|
+
:localteam_subs,
|
8
|
+
:visitorteam_subs,
|
9
|
+
:localteam_substitutions,
|
10
|
+
:visitorteam_substitutions,
|
11
|
+
:localteam_cards,
|
12
|
+
:visitorteam_cards,
|
13
|
+
:localteam_goals,
|
14
|
+
:visitorteam_goals
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@match_info = nil
|
18
|
+
@localteam_players = []
|
19
|
+
@visitorteam_players = []
|
20
|
+
@commentaries = []
|
21
|
+
@localteam_subs = []
|
22
|
+
@visitorteam_subs = []
|
23
|
+
@localteam_substitutions = []
|
24
|
+
@visitorteam_substitutions = []
|
25
|
+
@localteam_goals = []
|
26
|
+
@visitorteam_goals = []
|
27
|
+
@localteam_cards = []
|
28
|
+
@visitorteam_cards = []
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_info data
|
32
|
+
match_info = Struct.const_defined?("MatchInfo") ? Struct::MatchInfo : Struct.new("MatchInfo", *data.keys)
|
33
|
+
@info = match_info.new *data.values
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_localteam data
|
37
|
+
if !data["localteam"].nil? and !data["localteam"]["player"].nil?
|
38
|
+
data["localteam"]["player"].each do |k, v|
|
39
|
+
@localteam_players << Footy::Player.new(v["id"], v["name"], v["number"], v["pos"])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def set_vistorteam data
|
45
|
+
if !data["visitorteam"].nil? and !data["visitorteam"]["player"].nil?
|
46
|
+
data["visitorteam"]["player"].each do |k, v|
|
47
|
+
@visitorteam_players << Footy::Player.new(v["id"], v["name"], v["number"], v["pos"])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_localteam_subs data
|
53
|
+
if !data["localteam"].nil? and !data["localteam"]["player"].nil?
|
54
|
+
data["localteam"]["player"].each do |k, v|
|
55
|
+
@localteam_subs << Footy::Player.new(v["id"], v["name"], v["number"], v["pos"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def set_vistorteam_subs data
|
61
|
+
if !data["visitorteam"].nil? and !data["visitorteam"]["player"].nil?
|
62
|
+
data["visitorteam"]["player"].each do |k, v|
|
63
|
+
@visitorteam_subs << Footy::Player.new(v["id"], v["name"], v["number"], v["pos"])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def set_commentaries data
|
69
|
+
data.each do |comm|
|
70
|
+
c = Struct.const_defined?("Commentary") ? Struct::Commentary : Struct.new("Commentary", :id, :isgoal, :comment, :minute)
|
71
|
+
@commentaries << c.new(comm["id"], comm["isgoal"] == "True", comm["comment"], comm["minute"])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def set_localteam_substitutions data
|
76
|
+
if !data["localteam"].nil? and !data["localteam"]["substitution"].nil?
|
77
|
+
data["localteam"]["substitution"].each do |k, v|
|
78
|
+
@localteam_substitutions << Footy::Substitution.new(v["off"], v["off_id"], v["on"], v["on_id"], v["minute"])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def set_visitorteam_substitutions data
|
84
|
+
if !data["visitorteam"].nil? and !data["visitorteam"]["substitution"].nil?
|
85
|
+
data["visitorteam"]["substitution"].each do |k, v|
|
86
|
+
@visitorteam_substitutions << Footy::Substitution.new(v["off"], v["off_id"], v["on"], v["on_id"], v["minute"])
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def set_cards data
|
92
|
+
if !data.nil? and !data["localteam"].nil? and data["localteam"]["yellowcards"].count > 0
|
93
|
+
if data["localteam"]["yellowcards"]["player"]["1"].nil? #Handle the stupid JSON. This should have been an array
|
94
|
+
card = data["localteam"]["yellowcards"]["player"]
|
95
|
+
@localteam_cards << Footy::Card.new(card["name"], card["minute"], 'yellow')
|
96
|
+
else
|
97
|
+
data["localteam"]["yellowcards"]["player"].each{|k, v| @localteam_cards << Footy::Card.new(v["name"], v["minute"], 'yellow') }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
if !data.nil? and !data["localteam"].nil? and data["localteam"]["redcards"].count > 0
|
101
|
+
if data["localteam"]["redcards"]["player"]["1"].nil?
|
102
|
+
card = data["localteam"]["redcards"]["player"]
|
103
|
+
@localteam_cards << Footy::Card.new(card["name"], card["minute"], 'red')
|
104
|
+
else
|
105
|
+
data["localteam"]["redcards"]["player"].each{|k, v| @localteam_cards << Footy::Card.new(v["name"], v["minute"], 'red') }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
if !data.nil? and !data["visitorteam"].nil? and data["visitorteam"]["yellowcards"].count > 0
|
110
|
+
if data["visitorteam"]["yellowcards"]["player"]["1"].nil?
|
111
|
+
card = data["visitorteam"]["yellowcards"]["player"]
|
112
|
+
@visitorteam_cards << Footy::Card.new(card["name"], card["minute"], 'yellow')
|
113
|
+
else
|
114
|
+
data["visitorteam"]["yellowcards"]["player"].each{|k, v| @visitorteam_cards << Footy::Card.new(v["name"], v["minute"], 'yellow') }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
if !data.nil? and !data["visitorteam"].nil? and data["visitorteam"]["redcards"].count > 0
|
118
|
+
if data["visitorteam"]["redcards"]["player"]["1"].nil?
|
119
|
+
card = data["visitorteam"]["redcards"]["player"]
|
120
|
+
@visitorteam_cards << Footy::Card.new(card["name"], card["minute"], 'red')
|
121
|
+
else
|
122
|
+
data["visitorteam"]["redcards"]["player"].each{|k, v| @visitorteam_cards << Footy::Card.new(v["name"], v["minute"], 'red') }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def set_goals data
|
128
|
+
if !data.nil? and !data["localteam"].nil? and data["localteam"]["goals"].count > 0
|
129
|
+
if data["localteam"]["goals"]["player"]["1"].nil?
|
130
|
+
goal = data["localteam"]["goals"]["player"]
|
131
|
+
@localteam_goals << Footy::Goal.new(goal["name"], goal["minute"], goal["owngoal"] == "True", goal["penalty"] == "True")
|
132
|
+
else
|
133
|
+
data["localteam"]["goals"]["player"].each{|k, v| @localteam_goals << Footy::Goal.new(v["name"], v["minute"], v["owngoal"] == "True", v["penalty"] == "True") }
|
134
|
+
end
|
135
|
+
end
|
136
|
+
if !data.nil? and !data["visitorteam"].nil? and data["visitorteam"]["goals"].count > 0
|
137
|
+
if data["visitorteam"]["goals"]["player"]["1"].nil?
|
138
|
+
goal = data["visitorteam"]["goals"]["player"]
|
139
|
+
@visitorteam_goals << Footy::Goal.new(goal["name"], goal["minute"], goal["owngoal"] == "True", goal["penalty"] == "True")
|
140
|
+
else
|
141
|
+
data["visitorteam"]["goals"]["player"].each{|k, v| @visitorteam_goals << Footy::Goal.new(v["name"], v["minute"], v["owngoal"] == "True", v["penalty"] == "True") }
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
class << self
|
147
|
+
def parse_from_response response
|
148
|
+
commentary = Commentary.new
|
149
|
+
commentary.set_info(response["comm_match_info"]) unless response["comm_match_info"].nil?
|
150
|
+
commentary.set_localteam(response["comm_match_teams"]) unless response["comm_match_teams"].nil?
|
151
|
+
commentary.set_vistorteam(response["comm_match_teams"]) unless response["comm_match_teams"].nil?
|
152
|
+
commentary.set_localteam_subs(response["comm_match_subs"]) unless response["comm_match_subs"].nil?
|
153
|
+
commentary.set_vistorteam_subs(response["comm_match_subs"]) unless response["comm_match_subs"].nil?
|
154
|
+
commentary.set_localteam_substitutions(response["comm_match_substitutions"]) unless response["comm_match_substitutions"].nil?
|
155
|
+
commentary.set_visitorteam_substitutions(response["comm_match_substitutions"]) unless response["comm_match_substitutions"].nil?
|
156
|
+
commentary.set_cards(response["comm_match_summary"]) unless response["comm_match_summary"].nil?
|
157
|
+
commentary.set_goals(response["comm_match_summary"]) unless response["comm_match_summary"].nil?
|
158
|
+
|
159
|
+
commentary.set_commentaries(response["comm_commentaries"]["comment"].values) if !response["comm_commentaries"].nil? and !response["comm_commentaries"]["comment"].nil?
|
160
|
+
commentary
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Footy
|
2
|
+
class Competition
|
3
|
+
attr_accessor :id, :name, :region
|
4
|
+
def initialize id, name, region
|
5
|
+
@id = id
|
6
|
+
@name = name
|
7
|
+
@region = region
|
8
|
+
end
|
9
|
+
|
10
|
+
def fixtures from, to
|
11
|
+
response = Footy::Api.call :Action => 'fixtures', :comp_id => self.id, :from_date => from.strftime("%d.%m.%Y"), :to_date => to.strftime("%d.%m.%Y")
|
12
|
+
return Footy::Fixture.from_array(response['matches']) if response["ERROR"] == "OK"
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def all
|
17
|
+
response = Footy::Api.call :Action => 'competitions'
|
18
|
+
return from_array(response['Competition']) if response["ERROR"] == "OK"
|
19
|
+
end
|
20
|
+
|
21
|
+
def from_array competitions
|
22
|
+
competitions.collect{|c| Competition.new(c["id"], c["name"], c["region"]) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Footy
|
2
|
+
# Footy.configure do |config|
|
3
|
+
# config # => instance of Footy::Configuration
|
4
|
+
# end
|
5
|
+
#
|
6
|
+
# Setting the keys with this Configuration
|
7
|
+
#
|
8
|
+
# Footy.configure do |config|
|
9
|
+
# config.api_key = '2342kjrlkwjelfkjl2342jkljfaadfadf'
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
class Configuration
|
13
|
+
attr_accessor :api_key,
|
14
|
+
:api_url
|
15
|
+
|
16
|
+
def initialize #:nodoc:
|
17
|
+
@api_key = ENV['FOOTBALL_API_KEY']
|
18
|
+
@api_url = "http://football-api.com/api/?"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Footy
|
2
|
+
class Fixture
|
3
|
+
attr_accessor :id, :date, :time, :status, :localteam, :visitorteam
|
4
|
+
def initialize id, date, time, status, localteam_id, localteam_name, visitorteam_id, visitorteam_name
|
5
|
+
@id = id
|
6
|
+
@date = date
|
7
|
+
@time = time
|
8
|
+
@status = status
|
9
|
+
@localteam = Footy::Team.new localteam_id, localteam_name
|
10
|
+
@visitorteam = Footy::Team.new visitorteam_id, visitorteam_name
|
11
|
+
end
|
12
|
+
|
13
|
+
def commentary
|
14
|
+
response = Footy::Api.call :Action => 'commentaries', :match_id => self.id
|
15
|
+
Footy::Commentary.parse_from_response(response["commentaries"].first) if response["ERROR"] == "OK"
|
16
|
+
end
|
17
|
+
|
18
|
+
class << self
|
19
|
+
def from_array fixtures
|
20
|
+
fixtures.collect{ |f| Footy::Fixture.new f['match_id'], f['match_formatted_date'], f['match_time'], f['match_status'], f['match_localteam_id'], f['match_localteam_name'], f['match_visitorteam_id'], f['match_visitorteam_name'] }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/footy/goal.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Footy
|
2
|
+
class Goal
|
3
|
+
attr_accessor :name, :minute, :owngoal, :penalty
|
4
|
+
def initialize name, minute, owngoal, penalty
|
5
|
+
@name = name
|
6
|
+
@minute = minute
|
7
|
+
@owngoal = owngoal
|
8
|
+
@penalty = penalty
|
9
|
+
end
|
10
|
+
|
11
|
+
def owngoal?
|
12
|
+
owngoal
|
13
|
+
end
|
14
|
+
|
15
|
+
def penalty?
|
16
|
+
penalty
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/footy/player.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Footy
|
2
|
+
class Substitution
|
3
|
+
attr_accessor :off_name,
|
4
|
+
:off_id,
|
5
|
+
:on_name,
|
6
|
+
:on_id,
|
7
|
+
:minute
|
8
|
+
|
9
|
+
def initialize off_name, off_id, on_name, on_id, minute
|
10
|
+
@off_name = off_name
|
11
|
+
@off_id = off_id
|
12
|
+
@on_name = on_name
|
13
|
+
@on_id = on_id
|
14
|
+
@minute = minute
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/footy/team.rb
ADDED
data/lib/footy.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'footy/configuration'
|
2
|
+
require 'footy/api'
|
3
|
+
require 'footy/competition'
|
4
|
+
require 'footy/team'
|
5
|
+
require 'footy/fixture'
|
6
|
+
require 'footy/commentary'
|
7
|
+
require 'footy/player'
|
8
|
+
require 'footy/substitution'
|
9
|
+
require 'footy/card'
|
10
|
+
require 'footy/goal'
|
11
|
+
|
12
|
+
module Footy
|
13
|
+
# Gives access to the current Configuration.
|
14
|
+
def self.configuration
|
15
|
+
@configuration ||= Configuration.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configure
|
19
|
+
config = configuration
|
20
|
+
yield(config)
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: footy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Laiq Jafri
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple plugin for accessing your football API @ football-api.com
|
14
|
+
email: laiq@tekstart.us
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/footy.rb
|
20
|
+
- lib/footy/api.rb
|
21
|
+
- lib/footy/card.rb
|
22
|
+
- lib/footy/commentary.rb
|
23
|
+
- lib/footy/competition.rb
|
24
|
+
- lib/footy/configuration.rb
|
25
|
+
- lib/footy/fixture.rb
|
26
|
+
- lib/footy/goal.rb
|
27
|
+
- lib/footy/player.rb
|
28
|
+
- lib/footy/substitution.rb
|
29
|
+
- lib/footy/team.rb
|
30
|
+
- lib/footy/version.rb
|
31
|
+
homepage: http://github.com/laiqjafri/Footy
|
32
|
+
licenses:
|
33
|
+
- MIT
|
34
|
+
metadata: {}
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 2.2.2
|
52
|
+
signing_key:
|
53
|
+
specification_version: 4
|
54
|
+
summary: Footy!
|
55
|
+
test_files: []
|