class FootballRuby::Client

Public Instance Methods

fixture(id, opts={}) click to toggle source

Show one fixture. Filters:

head2head=/d+/

# File lib/football_ruby/client.rb, line 77
def fixture(id, opts={})
  raise IdMissingError, 'missing id' if id.nil?

  head2head = opts[:head2head]

  uri = "fixtures/#{id}/"
  url = head2head.nil? ? uri : "#{uri}?head2head=#{head2head}"

  json_response get(url)
end
fixtures(opts={}) click to toggle source

List fixtures across a set of leagues. Filters:

time_frame=/p|n{1,2}/ league=leagueCode

# File lib/football_ruby/client.rb, line 61
def fixtures(opts={})
  time_frame = opts[:time_frame]
  league = opts[:league]

  uri = "fixtures/"
  url = time_frame.nil? ? uri : "#{uri}?timeFrame=#{time_frame}"
  url = league.nil? ? url : "#{url}?league=#{league}"

  json_response get(url)
end
league_fixtures(id, opts={}) click to toggle source

List all fixtures for a certain league. Filters:

time_frame=/p|n{1,2}/ match_day=/d+/

# File lib/football_ruby/client.rb, line 42
def league_fixtures(id, opts={})
  raise IdMissingError, 'missing id' if id.nil?

  time_frame  = opts[:time_frame]
  match_day   = opts[:match_day]

  uri = "competitions/#{id}/fixtures/"
  url = time_frame.nil? ? uri : "#{uri}?timeFrame=#{time_frame}"
  url = match_day.nil? ? url : "#{url}?matchday=#{match_day}"

  json_response get(url)
end
league_table(id, opts={}) click to toggle source

Show League Table / current standing. Filters:

match_day=/d+/

# File lib/football_ruby/client.rb, line 25
def league_table(id, opts={})
  raise IdMissingError, 'missing id' if id.nil?

  match_day = opts[:match_day]

  uri = "competitions/#{id}/leagueTable/"
  url = match_day.nil? ? uri : "#{uri}?matchday=#{match_day}"

  json_response get(url)
end
league_teams(id) click to toggle source

List all teams for a certain league.

# File lib/football_ruby/client.rb, line 14
def league_teams(id)
  raise IdMissingError, 'missing id' if id.nil?

  json_response get("competitions/#{id}/teams")
end
leagues(opts={}) click to toggle source

List all available leagues.

# File lib/football_ruby/client.rb, line 7
def leagues(opts={})
  season = opts.fetch(:season) { Time.now.year }

  json_response get("competitions/?season=#{season}")
end
live_scores() click to toggle source

Show live scores

# File lib/football_ruby/client.rb, line 125
def live_scores
  json_response get_live_scores
end
team(id) click to toggle source

Show one team.

# File lib/football_ruby/client.rb, line 111
def team(id)
  raise IdMissingError, 'missing id' if id.nil?

  json_response get("teams/#{id}/")
end
team_fixtures(id, opts={}) click to toggle source

Show all fixtures for a certain team. Filters:

season=/dddd/ time_frame=/p|n{1,2}/ venue=/home|away/

# File lib/football_ruby/client.rb, line 95
def team_fixtures(id, opts={})
  raise IdMissingError, 'missing id' if id.nil?

  season      = opts[:season]
  time_frame  = opts[:time_frame]
  venue       = opts[:venue]

  uri = "teams/#{id}/fixtures/"
  url = season.nil? ? uri : "#{uri}?season=#{season}"
  url = time_frame.nil? ? url : "#{url}?timeFrame=#{time_frame}"
  url = venue.nil? ? url : "#{url}?venue=#{venue}"

  json_response get(url)
end
team_players(id) click to toggle source

Show all players for a certain team.

# File lib/football_ruby/client.rb, line 118
def team_players(id)
  raise IdMissingError, 'missing team id' if id.nil?

  json_response get("teams/#{id}/players/")
end

Private Instance Methods

json_response(request) click to toggle source
# File lib/football_ruby/client.rb, line 131
def json_response(request)
  JSON.parse(request.body, symbolize_names: true)
end