Ruby API Client for OPTA SDAPI (Sports Data Soccer API)
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
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 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/... |
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 |
OptaSD::Soccer::Match.new.competition('722fdbecxzcq9788l6jqclzlw').time_range(Time.now - 86400, Time.now + 86400)
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.
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']
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
Sports Data Soccer API guide
http://api.performfeeds.com/soccerdata/match/sdapidocumentation?_docu
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 truelineups(ture/false)
by default will pass truestatus(status)
statuses : (all
-fixture
-played
-playing
-cancelled
-postponed
-suspended
)time_range(from, to)
from and to should be a valid Time, likeTime.now
# 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
# Get Match Events
OptaSD::Soccer::MatchEvent.new.fixture('bsu6pjne1eqz2hs8r3685vbhl').get
Available Parameters:
resource(match_id)
fixture(match_id)
# Get Match Matrix
OptaSD::Soccer::PassMatrix.new.fixture('bsu6pjne1eqz2hs8r3685vbhl').get
Available Parameters:
resource(match_id)
fixture(match_id)
# Get Possession Throughout A Match
OptaSD::Soccer::Possession.new.fixture('bsu6pjne1eqz2hs8r3685vbhl').get
Available Parameters:
resource(match_id)
fixture(match_id)
# 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
# Get Match Facts
OptaSD::Soccer::MatchFacts.new.fixture('bsu6pjne1eqz2hs8r3685vbhl').get
Available Parameters:
resource(match_id)
fixture(match_id)
# 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)
# 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)
# 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
# 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)
# 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
# Get Preview of Match
OptaSD::Soccer::MatchPreview.new.fixture('bsu6pjne1eqz2hs8r3685vbhl').get
Available Parameters:
resource(match_id)
fixture(match_id)
# 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)
# 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)
# 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)
- 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
The gem is available as open source under the terms of the MIT License.