football_api 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/football_api-0.0.1.gem +0 -0
- data/football_api-0.0.2.gem +0 -0
- data/football_api-0.0.3.gem +0 -0
- data/football_api.gemspec +36 -0
- data/lib/football_api/base_request.rb +75 -0
- data/lib/football_api/card.rb +19 -0
- data/lib/football_api/comment.rb +13 -0
- data/lib/football_api/commentary.rb +79 -0
- data/lib/football_api/competition.rb +54 -0
- data/lib/football_api/errors.rb +13 -0
- data/lib/football_api/event.rb +19 -0
- data/lib/football_api/fixture.rb +44 -0
- data/lib/football_api/goal.rb +17 -0
- data/lib/football_api/match.rb +59 -0
- data/lib/football_api/match_bench.rb +27 -0
- data/lib/football_api/match_info.rb +14 -0
- data/lib/football_api/match_stats.rb +29 -0
- data/lib/football_api/match_substitutions.rb +27 -0
- data/lib/football_api/match_summary.rb +39 -0
- data/lib/football_api/match_team.rb +22 -0
- data/lib/football_api/mixins/requestable.rb +19 -0
- data/lib/football_api/mixins/symbolizer.rb +59 -0
- data/lib/football_api/player.rb +12 -0
- data/lib/football_api/standing.rb +104 -0
- data/lib/football_api/version.rb +3 -0
- data/lib/football_api.rb +32 -0
- data/spec/commentary_spec.rb +112 -0
- data/spec/competition_spec.rb +27 -0
- data/spec/fixture_spec.rb +90 -0
- data/spec/helpers/json_helper.rb +41 -0
- data/spec/json/commentaries.json +1967 -0
- data/spec/json/competitions.json +23 -0
- data/spec/json/fixtures.json +4559 -0
- data/spec/json/matches.json +17 -0
- data/spec/json/standings.json +719 -0
- data/spec/match_spec.rb +25 -0
- data/spec/spec_helper.rb +115 -0
- data/spec/standing_spec.rb +37 -0
- metadata +346 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3de37e6a41a4af23643c980f5261a4e9d9345ec3
|
4
|
+
data.tar.gz: d2eb25bd2a80f95ef6c3e8a75649a854cfdd9560
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9f542c19784774e209a90c898ecf5ea44e95de8eb989df5d972e7ab71530554941eb5f90bd4143ee6c068d66dc68aa63c56a1e843ae4227776b89e40d0ba6a3e
|
7
|
+
data.tar.gz: 1e55fd1031075c1e7b4555576fc2d9c64bd24f1309101777237cd19a0676caa2c2cbbb361553c745abd451f599f5a9cd8127c52e4174ee2dff7eea585e46e9c8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
football_api
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Afonso Tsukamoto
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# FootballApi
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'football_api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install football_api
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/football_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 a new Pull Request
|
data/Rakefile
ADDED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'football_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "football_api"
|
8
|
+
spec.version = FootballApi::VERSION
|
9
|
+
spec.authors = ["Afonso Tsukamoto"]
|
10
|
+
spec.email = ["atsukamoto@faber-ventures.com"]
|
11
|
+
spec.summary = %q{ Interface with football-api }
|
12
|
+
spec.description = %q{ Interface with football-api }
|
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.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency 'reek', '~> 1.3', '>= 1.3.7'
|
24
|
+
spec.add_development_dependency 'rubocop', '~> 0.20', '>= 0.20.1'
|
25
|
+
spec.add_development_dependency 'pry', '~> 0.9', '>= 0.9.12'
|
26
|
+
spec.add_development_dependency 'pry-byebug', '~> 2.0.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.2', '>= 3.2.0'
|
28
|
+
spec.add_development_dependency 'webmock', '~> 1.21', '>= 1.21.0'
|
29
|
+
|
30
|
+
spec.add_dependency 'dotenv', '~> 2.0.2'
|
31
|
+
spec.add_dependency 'activesupport', '~> 4.1'
|
32
|
+
spec.add_dependency 'httparty', '~> 0.13', '>= 0.13.0'
|
33
|
+
spec.add_dependency 'colored', '~> 1.2'
|
34
|
+
spec.add_dependency 'tzinfo', '~> 1.1', '>= 1.1.0'
|
35
|
+
spec.add_dependency 'eventmachine', '~> 1.0', '>= 1.0.3'
|
36
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module FootballApi
|
2
|
+
class BaseRequest
|
3
|
+
include HTTParty
|
4
|
+
include FootballApi::Symbolizer
|
5
|
+
|
6
|
+
debug_output $stdout
|
7
|
+
# Disable the use of rails query string format.
|
8
|
+
#
|
9
|
+
# With rails query string format enabled:
|
10
|
+
# => get '/', :query => { selected_ids: [1,2,3] }
|
11
|
+
#
|
12
|
+
# Would translate to this:
|
13
|
+
# => /?selected_ids[]=1&selected_ids[]=2&selected_ids[]=3
|
14
|
+
#
|
15
|
+
disable_rails_query_string_format
|
16
|
+
|
17
|
+
# How many times should we retry the request if Timeout::Error is raised?
|
18
|
+
RETRIES = 3
|
19
|
+
|
20
|
+
# The API Base URI
|
21
|
+
base_uri 'http://football-api.com/'
|
22
|
+
|
23
|
+
# The default format of the requests. Used on HTTP header 'Content-Type'.
|
24
|
+
format :json
|
25
|
+
|
26
|
+
# The default params for every request
|
27
|
+
# TODO : Pass key in config
|
28
|
+
default_params 'APIKey' => '69216017-4bb7-96db-0deeadb1b645'
|
29
|
+
|
30
|
+
# Default request timeout in seconds. This can be overriden by module configuration.
|
31
|
+
default_timeout 15
|
32
|
+
|
33
|
+
class << self
|
34
|
+
|
35
|
+
# The generic get method for all requests.
|
36
|
+
# Uses httparty get and makes no assumptions about the response,
|
37
|
+
# simply returns it
|
38
|
+
def get!(options = {}, &block)
|
39
|
+
attempts ||= RETRIES
|
40
|
+
query = action_query(options)
|
41
|
+
get("/api/", query, &block)
|
42
|
+
|
43
|
+
rescue Timeout::Error => e
|
44
|
+
puts "Timeout! Retrying... (#{RETRIES - attempts})"
|
45
|
+
|
46
|
+
retry if (attempts -= 1) > 0
|
47
|
+
|
48
|
+
raise FootballApi::RequestError.new('Request timeout')
|
49
|
+
end
|
50
|
+
|
51
|
+
alias_method :request!, :get!
|
52
|
+
|
53
|
+
# This is an handy method for response parsing.
|
54
|
+
# Subclasses that include Requestable can simply use the json_key option
|
55
|
+
# and response will only contain that field.
|
56
|
+
# It also deep symbolizes the response keys
|
57
|
+
def response(options = {})
|
58
|
+
data = get!(options) || Hash.new
|
59
|
+
|
60
|
+
data = custom_deep_symbolic_hash(data)
|
61
|
+
data.present? ? data[json_id] : data
|
62
|
+
end
|
63
|
+
|
64
|
+
def action_query(options = {})
|
65
|
+
{ query: { "Action" => action }.merge(options) }.tap do |hs|
|
66
|
+
hs[:query].merge!(get_parameters) if params_method
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_parameters
|
71
|
+
send(params_method)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module FootballApi
|
2
|
+
class Card
|
3
|
+
TYPE = [ :yellow, :red ]
|
4
|
+
|
5
|
+
attr_accessor :type, :minute, :player
|
6
|
+
|
7
|
+
def initialize(hash = {})
|
8
|
+
return {} unless TYPE.include?(hash[:type])
|
9
|
+
|
10
|
+
@type = hash[:type]
|
11
|
+
@minute = hash[:minute]
|
12
|
+
@player = parse_player(hash)
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse_player(hash = {})
|
16
|
+
FootballApi::Player.new(hash)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module FootballApi
|
2
|
+
class Comment < FootballApi::BaseRequest
|
3
|
+
attr_accessor :id, :important, :is_goal, :minute, :comment
|
4
|
+
|
5
|
+
def initialize(hash = {})
|
6
|
+
@id = hash[:id]
|
7
|
+
@important = hash[:important]
|
8
|
+
@is_goal = hash[:isgoal]
|
9
|
+
@minute = hash[:minute]
|
10
|
+
@comment = hash[:comment]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module FootballApi
|
2
|
+
class Commentary < FootballApi::BaseRequest
|
3
|
+
include FootballApi::Requestable
|
4
|
+
|
5
|
+
api_options action: :commentaries, action_params: :commentary_params, json_key: :commentaries
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :match_id
|
9
|
+
|
10
|
+
def all_from_match(match)
|
11
|
+
@match_id = match.is_a?(Match) ? match.id : match
|
12
|
+
|
13
|
+
res = response
|
14
|
+
res.map { |commentary| new(commentary) }.first
|
15
|
+
end
|
16
|
+
|
17
|
+
def commentary_params
|
18
|
+
{ match_id: self.match_id }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_accessor :match_id, :static_id, :match_info, :match_summary,
|
23
|
+
:match_stats, :local_match_team, :visitor_match_team,
|
24
|
+
:commentaries, :match_bench, :match_substitutions
|
25
|
+
|
26
|
+
def initialize(hash = {})
|
27
|
+
@match_id = hash[:comm_match_id]
|
28
|
+
@static_id = hash[:comm_static_id]
|
29
|
+
@match_info = parse_match_info(hash)
|
30
|
+
@match_summary = parse_match_summary(hash)
|
31
|
+
@match_stats = parse_match_stats(hash)
|
32
|
+
@local_match_team = parse_match_teams(hash, :localteam)
|
33
|
+
@visitor_match_team = parse_match_teams(hash, :visitorteam)
|
34
|
+
@match_bench = parse_match_bench(hash)
|
35
|
+
@match_substitutions = parse_match_substitutions(hash)
|
36
|
+
@commentaries = parse_comments(hash[:comm_commentaries])
|
37
|
+
end
|
38
|
+
|
39
|
+
def parse_match_info(hash = {})
|
40
|
+
hash = hash[:comm_match_info].merge(id: hash[:comm_match_id])
|
41
|
+
FootballApi::MatchInfo.new(hash)
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse_match_summary(hash = {})
|
45
|
+
hash = hash[:comm_match_summary].merge(id: hash[:comm_match_id])
|
46
|
+
FootballApi::MatchSummary.new(hash)
|
47
|
+
end
|
48
|
+
|
49
|
+
def parse_match_stats(hash = {})
|
50
|
+
return unless hash[:comm_match_stats].is_a?(Hash)
|
51
|
+
hash = hash[:comm_match_stats].merge(id: hash[:comm_match_id])
|
52
|
+
FootballApi::MatchStats.new(hash)
|
53
|
+
end
|
54
|
+
|
55
|
+
def parse_match_teams(hash = {}, key)
|
56
|
+
FootballApi::MatchTeam.new(hash, key)
|
57
|
+
end
|
58
|
+
|
59
|
+
def parse_comments(hash = {})
|
60
|
+
return unless hash[:comment]
|
61
|
+
|
62
|
+
Array(hash[:comment]).map{ |comment| FootballApi::Comment.new(comment) }
|
63
|
+
end
|
64
|
+
|
65
|
+
def parse_match_bench(hash = {})
|
66
|
+
return unless hash[:comm_match_subs]
|
67
|
+
|
68
|
+
FootballApi::MatchBench.new(hash[:comm_match_subs]
|
69
|
+
.merge(match_id: hash[:comm_match_id]))
|
70
|
+
end
|
71
|
+
|
72
|
+
def parse_match_substitutions(hash)
|
73
|
+
return unless hash[:comm_match_substitutions]
|
74
|
+
|
75
|
+
FootballApi::MatchSubstitutions.new(hash[:comm_match_substitutions]
|
76
|
+
.merge(match_id: hash[:comm_match_id]))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module FootballApi
|
2
|
+
class Competition < FootballApi::BaseRequest
|
3
|
+
include FootballApi::Requestable
|
4
|
+
|
5
|
+
api_options action: :competitions, json_key: :Competition
|
6
|
+
|
7
|
+
# Response sample :
|
8
|
+
# [
|
9
|
+
# {
|
10
|
+
# "id":"1064",
|
11
|
+
# "name":"Superliga",
|
12
|
+
# "region":"Albania"
|
13
|
+
# } ...
|
14
|
+
# ]
|
15
|
+
attr_accessor :id, :name, :region
|
16
|
+
|
17
|
+
def self.all
|
18
|
+
response && response.map do |comp|
|
19
|
+
new(comp)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.where(options = {})
|
24
|
+
response.select{ |c| matches_options(c, options) }.map{ |hsh| new(hsh) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(hash = {})
|
28
|
+
@id = hash[:id]
|
29
|
+
@name = hash[:name]
|
30
|
+
@region = hash[:region]
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# Matches the two given hashes.
|
36
|
+
# For example, if an options hash has:
|
37
|
+
# => {id:1, name: 'ze'}
|
38
|
+
#
|
39
|
+
# And the object has:
|
40
|
+
# => {id:1, name: 'ze', region: 'beira'}
|
41
|
+
#
|
42
|
+
# This function returns the reduce(:&) from the array:
|
43
|
+
# [true, true, true] -> true
|
44
|
+
#
|
45
|
+
# Where the two first trues are from *id == id* and *name == name*
|
46
|
+
# and since the options hash has no key :region,
|
47
|
+
# it returns *true* since that's a non searched option
|
48
|
+
def matches_options(object, options)
|
49
|
+
options.keys.map{ |key|
|
50
|
+
object.has_key?(key) ? options[key] == object[key] : true
|
51
|
+
}.reduce(:&)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module FootballApi
|
2
|
+
class Event
|
3
|
+
TYPES = %w(yellowcard goal redcard yellowred)
|
4
|
+
|
5
|
+
attr_accessor :event_id, :event_match_id, :event_type, :event_minute, :event_team,
|
6
|
+
:event_player, :event_player_id, :event_result
|
7
|
+
|
8
|
+
def initialize(hash = {})
|
9
|
+
@event_id = hash[:event_id]
|
10
|
+
@event_match_id = hash[:event_match_id]
|
11
|
+
@event_type = hash[:event_type]
|
12
|
+
@event_minute = hash[:event_minute]
|
13
|
+
@event_team = hash[:event_team]
|
14
|
+
@event_player = hash[:event_player]
|
15
|
+
@event_player_id = hash[:event_player_id]
|
16
|
+
@event_result = hash[:event_result]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module FootballApi
|
2
|
+
class Fixture < FootballApi::BaseRequest
|
3
|
+
include FootballApi::Requestable
|
4
|
+
|
5
|
+
api_options action: :fixtures, action_params: :fixture_params, json_key: :matches
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :match_date, :from_date, :to_date, :comp_id
|
9
|
+
|
10
|
+
def where(options = {})
|
11
|
+
@comp_id = options.delete(:comp_id)
|
12
|
+
@match_date = options.delete(:match_date)
|
13
|
+
@from_date = options.delete(:from_date)
|
14
|
+
@to_date = options.delete(:to_date)
|
15
|
+
|
16
|
+
response.map{ |fixture|
|
17
|
+
new (fixture)
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def fixture_params
|
22
|
+
[:comp_id, :match_date, :from_date, :to_date].each_with_object({}) do |symb, opts|
|
23
|
+
opts.merge!(symb => send(symb) ) if send(symb)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
attr_accessor :match, :match_timer, :match_events
|
29
|
+
|
30
|
+
def initialize(hash = {})
|
31
|
+
@match = parse_match(hash)
|
32
|
+
@match_timer = hash[:match_timer]
|
33
|
+
@match_events = parse_match_events(hash[:match_events])
|
34
|
+
end
|
35
|
+
|
36
|
+
def parse_match(hash = {})
|
37
|
+
FootballApi::Match.new(hash)
|
38
|
+
end
|
39
|
+
|
40
|
+
def parse_match_events(arr = [])
|
41
|
+
Array(arr).map { |e| FootballApi::Event.new(e) }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module FootballApi
|
2
|
+
class Goal
|
3
|
+
attr_accessor :score, :minute, :player, :owngoal, :penalty
|
4
|
+
|
5
|
+
def initialize(hash = {})
|
6
|
+
@score = hash[:score]
|
7
|
+
@minute = hash[:minute]
|
8
|
+
@owngoal = hash[:owngoal]
|
9
|
+
@penalty = hash[:penalty]
|
10
|
+
@player = parse_player(hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse_player(hash = {})
|
14
|
+
FootballApi::Player.new(hash)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module FootballApi
|
2
|
+
class Match < FootballApi::BaseRequest
|
3
|
+
include FootballApi::Requestable
|
4
|
+
|
5
|
+
api_options action: :today,
|
6
|
+
action_params: :match_params,
|
7
|
+
json_key: :matches
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_accessor :competition_id
|
11
|
+
|
12
|
+
def all_from_competition(competition)
|
13
|
+
@competition_id = competition.is_a?(Competition) ? competition.id : competition
|
14
|
+
|
15
|
+
Array(response).map { |match| new(match) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def match_params
|
19
|
+
{ comp_id: self.competition_id}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_accessor :match_id, :static_id, :match_comp_id, :match_date,
|
24
|
+
:match_formatted_date, :match_status, :match_time,
|
25
|
+
:match_commentary_available, :match_ht_score,
|
26
|
+
:match_localteam_id, :match_localteam_name,
|
27
|
+
:match_localteam_score, :match_visitorteam_id,
|
28
|
+
:match_visitorteam_name, :match_visitorteam_score,
|
29
|
+
:match_venue_city_beta, :match_venue_id_beta,
|
30
|
+
:match_venue_beta, :match_week_beta, :match_season_beta,
|
31
|
+
:match_et_score, :match_ft_score
|
32
|
+
|
33
|
+
|
34
|
+
def initialize(hash = {})
|
35
|
+
@match_id = hash[:match_id]
|
36
|
+
@static_id = hash[:match_static_id]
|
37
|
+
@match_comp_id = hash[:match_comp_id]
|
38
|
+
@match_date = hash[:match_date]
|
39
|
+
@match_formatted_date = hash[:match_formatted_date]
|
40
|
+
@match_status = hash[:match_status]
|
41
|
+
@match_time = hash[:match_time]
|
42
|
+
@match_commentary_available = hash[:match_commentary_available]
|
43
|
+
@match_localteam_id = hash[:match_localteam_id]
|
44
|
+
@match_localteam_name = hash[:match_localteam_name]
|
45
|
+
@match_localteam_score = hash[:match_localteam_score]
|
46
|
+
@match_visitorteam_id = hash[:match_visitorteam_id]
|
47
|
+
@match_visitorteam_name = hash[:match_visitorteam_name]
|
48
|
+
@match_visitorteam_score = hash[:match_visitorteam_score]
|
49
|
+
@match_ht_score = hash[:match_ht_score]
|
50
|
+
@match_ft_score = hash[:match_ft_score]
|
51
|
+
@match_et_score = hash[:match_et_score]
|
52
|
+
@match_season_beta = hash[:match_season_beta]
|
53
|
+
@match_week_beta = hash[:match_week_beta]
|
54
|
+
@match_venue_beta = hash[:match_venue_beta]
|
55
|
+
@match_venue_id_beta = hash[:match_venue_id_beta]
|
56
|
+
@match_venue_city_beta = hash[:match_venue_city_beta]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module FootballApi
|
2
|
+
class MatchBench
|
3
|
+
|
4
|
+
attr_accessor :match_id, :local_team, :visitor_team
|
5
|
+
|
6
|
+
def initialize(hash = {})
|
7
|
+
@match_id = hash[:match_id]
|
8
|
+
@local_team = Bench.new(hash, :localteam)
|
9
|
+
@visitor_team = Bench.new(hash, :visitorteam)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Bench
|
14
|
+
|
15
|
+
attr_accessor :team, :players
|
16
|
+
|
17
|
+
def initialize(opts = {}, key)
|
18
|
+
# XXX - Use case for more than one player, might be different
|
19
|
+
# Api returns single object without number index on single occurrence.
|
20
|
+
opts = opts[key]
|
21
|
+
return unless opts.present?
|
22
|
+
|
23
|
+
@team = key
|
24
|
+
@players = Array(opts[:player]).map { |v| Player.new(v) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module FootballApi
|
2
|
+
class MatchInfo
|
3
|
+
|
4
|
+
attr_accessor :stadium_name, :attendance, :time, :referee, :id
|
5
|
+
|
6
|
+
def initialize(hash = {})
|
7
|
+
@id = hash[:id]
|
8
|
+
@stadium_name = hash[:stadium][:name] if hash[:stadium]
|
9
|
+
@attendance = hash[:attendance][:name] if hash[:attendance]
|
10
|
+
@time = hash[:time][:name] if hash[:time]
|
11
|
+
@referee = hash[:referee][:name] if hash[:referee]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module FootballApi
|
2
|
+
class MatchStats
|
3
|
+
attr_accessor :id, :local_team_stats, :visitor_team_stats
|
4
|
+
|
5
|
+
def initialize(hash = {})
|
6
|
+
@id = hash[:id]
|
7
|
+
@local_team_stats = Stats.new(hash[:localteam])
|
8
|
+
@visitor_team_stats = Stats.new(hash[:visitorteam])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
class Stats
|
14
|
+
attr_accessor :total_shots, :ongoal_shots, :fouls, :corners, :offsides, :possestiontime,
|
15
|
+
:yellowcards, :redcards, :saves
|
16
|
+
|
17
|
+
def initialize(hash = {})
|
18
|
+
@total_shots = hash[:shots][:total] if hash[:shots]
|
19
|
+
@ongoal_shots = hash[:shots][:ongoal] if hash[:shots]
|
20
|
+
@fouls = hash[:fouls][:total] if hash[:fouls]
|
21
|
+
@corners = hash[:corners][:total] if hash[:corners]
|
22
|
+
@offsides = hash[:offsides][:total] if hash[:offsides]
|
23
|
+
@possestiontime = hash[:possestiontime][:total] if hash[:possestiontime]
|
24
|
+
@yellowcards = hash[:yellowcards][:total] if hash[:yellowcards]
|
25
|
+
@redcards = hash[:redcards][:total] if hash[:redcards]
|
26
|
+
@saves = hash[:saves][:total] if hash[:saves]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module FootballApi
|
2
|
+
class MatchSubstitutions
|
3
|
+
|
4
|
+
attr_accessor :match_id, :local_team, :visitor_team
|
5
|
+
|
6
|
+
def initialize(hash = {})
|
7
|
+
@match_id = hash[:match_id]
|
8
|
+
@local_team = subs(hash, :localteam)
|
9
|
+
@visitor_team = subs(hash, :visitorteam)
|
10
|
+
end
|
11
|
+
|
12
|
+
def subs(hash, key)
|
13
|
+
return [] unless hash[key]
|
14
|
+
Array(hash[key][:substitution]).map { |s| Substitution.new(s) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Substitution
|
19
|
+
def initialize(opts = {})
|
20
|
+
@off = opts[:off]
|
21
|
+
@on = opts[:on]
|
22
|
+
@minute = opts[:minute]
|
23
|
+
@on_id = opts[:on_id]
|
24
|
+
@off_id = opts[:off_id]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|