OPTA Sports Data Soccer API (OPTA SDAPI)
Ruby API Client for OPTA SDAPI (Sports Data Soccer API)
WARNING: This project is not maintained anymore.
Installation
Add this line to your application's Gemfile:
gem 'opta_sd'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install opta_sd
Using Guide
This Gem is just a class builder for the APIs, every api have a Class for it, and for every api's parameters there are methods to build them, and those parameter methods are explained down below for each Class.
Available Classes :
Available Feeds | Class | API End Point |
---|---|---|
Fixtures and Results | Match | /soccerdata/match/... |
Match Statistics | MatchStatistics | /soccerdata/matchstats/... |
Match Events | MatchEvent | /soccerdata/matchevent/... |
Pass Matrix and Average Formation | PassMatrix | /soccerdata/passmatrix/... |
Possession | Possession | /soccerdata/possession/... |
Commentary | Commentary | /soccerdata/Commentary/... |
Match Facts | MatchFacts | /soccerdata/matchfacts/... |
Seasonal Stats | SeasonalStats | /soccerdata/seasonstats/... |
Squads | Squads | /soccerdata/squads/... |
Team Standings | TeamStandings | /soccerdata/standings/... |
Player Career | PlayerCareer | /soccerdata/playercareer/... |
Tournament Calendars | TournamentCalendar | /soccerdata/tournamentcalendar/... |
Match Preview | MatchPreview | /soccerdata/matchpreview/... |
Rankings | Rankings | /soccerdata/rankings/... |
Tournament Schedule | TournamentSchedule | /soccerdata/tournamentschedule/... |
Venues | Venues | /soccerdata/venues/... |
Parameter Methods :
Parameters are changed in this gem to be more readable, and will be transulated to Opta keys in the backend.
There are two types of parameters, core parameters that can be used in all apis, and api parameters those are specific for each api.
Core Parameters are have _
prefix, and they are:
Method | Actual Parameter |
---|---|
_rt |
_rt |
_format |
_fmt |
_locale |
_lcl |
_callback |
_clbk |
_sort |
_ordSrt |
_page_size |
_pgSz |
_page_number |
_pgNm |
Example of using core parameters
OptaSD::Soccer::Match.new.competition('722fdbecxzcq9788l6jqclzlw').time_range(Time.now - 86400, Time.now + 86400)
Response Format
OPTA SD provides the response in json
and xml
format, you can use _format
method to define the required response format, json
is the default.
JSON response will be Parsed by JSON.parse
and XML will be parsed by nokogiri
gem. you can override parse_xml
method from Core Class in case you need to change the behaviour.
The Final Call
After building the required parameters, you will call get
method at the end of the chain to build the request and pull the data. after that you can retrieve the response by calling data
.
Example:
# Build the request hit the api
match = OptaSD::Soccer::Match.new.resource('bsu6pjne1eqz2hs8r3685vbhl').live.lineups.get
# retrieve the response data
match.data['match']
Use this Gem with Rails
To be able to use this gem with your own key, you need to create a opta_sd.yml
in config dir and override config_file
method from Core Class to read the opta_sd.yml
from your app directory.
# config/opta_sd.yml
opta_domain: 'http://api.performfeeds.com'
opta_auth_token: 'YOUR-OWN-KEY'
# config/initializers/opta_sd.rb
class OptaSD::Core
def config_file
YAML::load(File.open(Rails.root.join('config/opta_sd.yml')))
end
end
APIS
Sports Data Soccer API guide
http://api.performfeeds.com/soccerdata/match/sdapidocumentation?_docu
1. Fixtures and Results
Examples:
# Get Match details with live and lineups
OptaSD::Soccer::Match.new.resource('bsu6pjne1eqz2hs8r3685vbhl').live.lineups.get
# Using Old OPTA Core Match ID
OptaSD::Soccer::Match.new.fixture('urn:perform:optacore:fixture:2366080').live.lineups.get
# Get competition matches between two time stamps
OptaSD::Soccer::Match.new.competition('722fdbecxzcq9788l6jqclzlw').time_range(Time.now - 86400, Time.now + 86400).get
Available Parameters:
resource(match_id)
fixture(match_id)
tournament(tournament_id)
stage(stage_id)
competition(competition_id)
contestant(contestant_id)
-
live(ture/false)
by default will pass true -
lineups(ture/false)
by default will pass true -
status(status)
statuses : (all
-fixture
-played
-playing
-cancelled
-postponed
-suspended
) -
time_range(from, to)
from and to should be a valid Time, likeTime.now
2. Match Statistics
# Get Statistics Of Match
OptaSD::Soccer::MatchStatistics.new.resource('bsu6pjne1eqz2hs8r3685vbhl').get
# Get Statistics Of Match with more details
OptaSD::Soccer::MatchStatistics.new.fixture('bsu6pjne1eqz2hs8r3685vbhl').detailed.get
Available Parameters:
resource(match_id)
fixture(match_id)
-
detailed(ture/false)
by default will pass true
3. Match Events
# Get Match Events
OptaSD::Soccer::MatchEvent.new.fixture('bsu6pjne1eqz2hs8r3685vbhl').get
Available Parameters:
resource(match_id)
fixture(match_id)
4. Pass Matrix and Average Formation
# Get Match Matrix
OptaSD::Soccer::PassMatrix.new.fixture('bsu6pjne1eqz2hs8r3685vbhl').get
Available Parameters:
resource(match_id)
fixture(match_id)
5. Possession
# Get Possession Throughout A Match
OptaSD::Soccer::Possession.new.fixture('bsu6pjne1eqz2hs8r3685vbhl').get
Available Parameters:
resource(match_id)
fixture(match_id)
6. Commentary
# Get Match Commentary
OptaSD::Soccer::Commentary.new.fixture('bsu6pjne1eqz2hs8r3685vbhl').get
# Get Match Commentary with type
OptaSD::Soccer::Commentary.new.fixture('bsu6pjne1eqz2hs8r3685vbhl').type('auto').get
# Or
OptaSD::Soccer::Commentary.new.fixture('bsu6pjne1eqz2hs8r3685vbhl').auto.get
Available Parameters:
resource(match_id)
fixture(match_id)
-
type(type)
types are :auto
-fallback
-manual
auto
fallback
manual
7. Match Facts
# Get Match Facts
OptaSD::Soccer::MatchFacts.new.fixture('bsu6pjne1eqz2hs8r3685vbhl').get
Available Parameters:
resource(match_id)
fixture(match_id)
8. Seasonal Stats
# Get Seasonal Stats by Competition Contestants
OptaSD::Soccer::SeasonalStats.new.competition('722fdbecxzcq9788l6jqclzlw').contestant('884uzyf1wosc7ykji6e18gifp').get
# Get Seasonal Stats by Tournament Contestants
OptaSD::Soccer::SeasonalStats.new.tournament('408bfjw6uz5k19zk4am50ykmh').contestant('884uzyf1wosc7ykji6e18gifp').get
Available Parameters:
competition(competition_id)
tournament(tournament_id)
contestant(contestant_id)
9. Squads
# Get Squads By Tournament
OptaSD::Soccer::Squads.new.tournament('408bfjw6uz5k19zk4am50ykmh').get
# Get Squads By Contestant
OptaSD::Soccer::Squads.new.contestant('884uzyf1wosc7ykji6e18gifp').get
# Get Detailed Squads
OptaSD::Soccer::Squads.new.tournament('408bfjw6uz5k19zk4am50ykmh').detailed.get
# Get People Squads
OptaSD::Soccer::Squads.new.tournament('408bfjw6uz5k19zk4am50ykmh').people.get
Available Parameters:
tournament(tournament_id)
contestant(contestant_id)
detailed(ture/false)
people(ture/false)
10. Team Standings
# Get Team Standings By Tournament
OptaSD::Soccer::TeamStandings.new.tournament('408bfjw6uz5k19zk4am50ykmh').get
# Get Team Standings By Tournament And Stage
OptaSD::Soccer::TeamStandings.new.tournament('408bfjw6uz5k19zk4am50ykmh').stage('123').get
# Get Team Standings With Live Data
OptaSD::Soccer::TeamStandings.new.tournament('408bfjw6uz5k19zk4am50ykmh').live.get
# Get Team Standings By Type
OptaSD::Soccer::TeamStandings.new.tournament('408bfjw6uz5k19zk4am50ykmh').type('total').get
OptaSD::Soccer::TeamStandings.new.tournament('408bfjw6uz5k19zk4am50ykmh').total.get
Available Parameters:
stage(stage_id)
tournament(tournament_id)
-
type(type)
types are :total
-home
-away
-form-total
-form-home
-form-away
live(ture/false)
total
home
away
form_total
form_home
form_away
11. Player Career
# Get Player Career By Person ID
OptaSD::Soccer::PlayerCareer.new.resource('1c4gmhsc0mfjl2or3oxggg6hh').get
OptaSD::Soccer::PlayerCareer.new.person('1c4gmhsc0mfjl2or3oxggg6hh').get
# Get Players Career By Contestant ID
OptaSD::Soccer::PlayerCareer.new.contestant('apoawtpvac4zqlancmvw4nk4o').get
# Get Players Career By Contestant ID and Active on In-Active
OptaSD::Soccer::PlayerCareer.new.contestant('apoawtpvac4zqlancmvw4nk4o').active.get
OptaSD::Soccer::PlayerCareer.new.contestant('apoawtpvac4zqlancmvw4nk4o').active(false).get
Available Parameters:
resource(person_id)
person(person_id)
contestant(contestant_id)
active(ture/false)
12. Tournament Calendars
# Get All Competitions With All Tournaments
OptaSD::Soccer::TournamentCalendar.new.get
# Get Tournaments Of Competitions
OptaSD::Soccer::TournamentCalendar.new.competition('722fdbecxzcq9788l6jqclzlw').get
# Get All Competitions With Only Active Tournaments
OptaSD::Soccer::TournamentCalendar.new.active.get
# Get Only Authorized Competitions With Only Active Tournaments
OptaSD::Soccer::TournamentCalendar.new.active.authorized.get
Available Parameters:
competition(competition_id)
active
authorized
13. Match Preview
# Get Preview of Match
OptaSD::Soccer::MatchPreview.new.fixture('bsu6pjne1eqz2hs8r3685vbhl').get
Available Parameters:
resource(match_id)
fixture(match_id)
14. Rankings
# Get Tournament Rankings
OptaSD::Soccer::Rankings.new.resource('408bfjw6uz5k19zk4am50ykmh').get
OptaSD::Soccer::Rankings.new.tournament('408bfjw6uz5k19zk4am50ykmh').get
Available Parameters:
resource(tournament_id)
tournament(tournament_id)
15. Tournament Schedule
# Get Tournament Schedule
OptaSD::Soccer::TournamentSchedule.new.resource('408bfjw6uz5k19zk4am50ykmh').get
OptaSD::Soccer::TournamentSchedule.new.tournament('408bfjw6uz5k19zk4am50ykmh').get
Available Parameters:
resource(tournament_id)
tournament(tournament_id)
16. Venues
# Get Venues
OptaSD::Soccer::Venues.new.venue('bdkmbkf8yi951wrjraknp9wad').get
OptaSD::Soccer::Venues.new.tournament('9xjsbe05up1jqycf7no90as4p').get
OptaSD::Soccer::Venues.new.contestant('c8h9bw1l82s06h77xxrelzhur').get
Available Parameters:
venue(venue_id)
tournament(tournament_id)
contestant(contestant_id)
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
License
The gem is available as open source under the terms of the MIT License.