Class: SportsDirect::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/sports_direct/api.rb

Constant Summary collapse

Error =
Class.new(StandardError)
Timeout =
Class.new(Error)
Unauthorized =
Class.new(Error)

Class Method Summary collapse

Class Method Details

.baseball_mlb_scheduleObject



20
21
22
# File 'lib/sports_direct/api.rb', line 20

def baseball_mlb_schedule
  get('/baseball/MLB/schedule/schedule_MLB.xml')
end

.baseball_mlb_teams(season) ⇒ Object



24
25
26
# File 'lib/sports_direct/api.rb', line 24

def baseball_mlb_teams(season)
  get("/baseball/MLB/teams/#{season}/teams_MLB.xml")
end

.basketball_nba_scheduleObject



28
29
30
# File 'lib/sports_direct/api.rb', line 28

def basketball_nba_schedule
  get('/basketball/NBA/schedule/schedule_NBA.xml')
end

.basketball_nba_teams(season) ⇒ Object



32
33
34
# File 'lib/sports_direct/api.rb', line 32

def basketball_nba_teams(season)
  get("/basketball/NBA/teams/#{season}/teams_NBA.xml")
end

.basketball_ncaa_scheduleObject



36
37
38
# File 'lib/sports_direct/api.rb', line 36

def basketball_ncaa_schedule
  get('/basketball/NCAAB/schedule/schedule_NCAAB.xml')
end

.basketball_ncaa_teams(season) ⇒ Object



40
41
42
# File 'lib/sports_direct/api.rb', line 40

def basketball_ncaa_teams(season)
  get("/basketball/NCAAB/teams/#{season}/teams_NCAAB.xml")
end

.get(*args) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/sports_direct/api.rb', line 52

def get(*args)
  response = super

  case response.code
    when 401
      raise Unauthorized.new(response.at('h2').text.split(': ').last)
    when 403
      raise Unauthorized.new(response.at('head/title').text)
    else
      response
  end
rescue Errno::ECONNRESET
  raise Error.new($!.message)
rescue Errno::ETIMEDOUT
  raise Timeout.new($!.message)
end

.hockey_nhl_scheduleObject



44
45
46
# File 'lib/sports_direct/api.rb', line 44

def hockey_nhl_schedule
  get('/hockey/NHL/schedule/schedule_NHL.xml')
end

.hockey_nhl_teams(season) ⇒ Object



48
49
50
# File 'lib/sports_direct/api.rb', line 48

def hockey_nhl_teams(season)
  get("/hockey/NHL/teams/#{season}/teams_NHL.xml")
end