Class: Footballdata::Metal

Inherits:
Object
  • Object
show all
Defined in:
lib/footballdata/download.rb

Overview

plumbing metal "helpers"

Constant Summary collapse

BASE_URL =

note - starting in 2026 requires https !!! (plain http will not work) resutls in -- 301 Moved Permanently

'https://api.football-data.org/v4'

Class Method Summary collapse

Class Method Details

.areasObject



128
129
130
# File 'lib/footballdata/download.rb', line 128

def self.areas
   get( "#{BASE_URL}/areas" )
end

.competition(code) ⇒ Object

more



112
113
114
# File 'lib/footballdata/download.rb', line 112

def self.competition( code )
  get( "#{BASE_URL}/competitions/#{code}" )
end

.competition_matches_url(code, year) ⇒ Object

just use matches_url - why? why not?



85
# File 'lib/footballdata/download.rb', line 85

def self.competition_matches_url( code, year )   "#{BASE_URL}/competitions/#{code}/matches?season=#{year}";   end

.competition_scorers_url(code, year) ⇒ Object



88
# File 'lib/footballdata/download.rb', line 88

def self.competition_scorers_url( code, year )   "#{BASE_URL}/competitions/#{code}/scorers?season=#{year}"; end

.competition_standings_url(code, year) ⇒ Object



87
# File 'lib/footballdata/download.rb', line 87

def self.competition_standings_url( code, year ) "#{BASE_URL}/competitions/#{code}/standings?season=#{year}"; end

.competition_teams_url(code, year) ⇒ Object



86
# File 'lib/footballdata/download.rb', line 86

def self.competition_teams_url( code, year )     "#{BASE_URL}/competitions/#{code}/teams?season=#{year}";     end

.competitions(auth: false) ⇒ Object



79
80
81
# File 'lib/footballdata/download.rb', line 79

def self.competitions( auth: false )
  get( competitions_url, auth: auth )
end

.competitions_urlObject



75
76
77
# File 'lib/footballdata/download.rb', line 75

def self.competitions_url
  "#{BASE_URL}/competitions"
end

.get(url, auth: true, headers: {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/footballdata/download.rb', line 41

def self.get( url,
                auth:    true,
                headers: {} )

  token = ENV['FOOTBALLDATA']
  ## note: because of public workflow log - do NOT output token
  ## puts token

  request_headers = {}
  request_headers['X-Auth-Token'] = token    if auth && token
  request_headers['User-Agent']   = 'ruby'
  request_headers['Accept']       = '*/*'

  request_headers = request_headers.merge( headers )   unless headers.empty?


  ## note: add format: 'json' for pretty printing json (before) save in cache
  response = Webget.call( url, headers: request_headers )

  ## for debugging print pretty printed json first 400 chars
  puts response.json.pretty_inspect[0..400]

  exit 1  if response.status.nok?   # e.g. HTTP status code != 200

  response.json
end

.match(id) ⇒ Object



120
121
122
# File 'lib/footballdata/download.rb', line 120

def self.match( id )
  get( "#{BASE_URL}/matches/#{id}" )
end

.matches(code, year, headers: {}) ⇒ Object



90
91
92
93
94
# File 'lib/footballdata/download.rb', line 90

def self.matches( code, year,
                  headers: {} )
    get( competition_matches_url( code, year ),
         headers: headers )
end

.person(id) ⇒ Object



124
125
126
# File 'lib/footballdata/download.rb', line 124

def self.person( id )
 get( "#{BASE_URL}/persons/#{id}" )
end

.scorers(code, year) ⇒ Object



108
# File 'lib/footballdata/download.rb', line 108

def self.scorers( code, year ) get( competition_scorers_url( code, year )); end

.standings(code, year) ⇒ Object



107
# File 'lib/footballdata/download.rb', line 107

def self.standings( code, year ) get( competition_standings_url( code, year )); end

.team(id) ⇒ Object



116
117
118
# File 'lib/footballdata/download.rb', line 116

def self.team( id )
  get( "#{BASE_URL}/teams/#{id}" )
end

.teams(code, year) ⇒ Object



106
# File 'lib/footballdata/download.rb', line 106

def self.teams( code, year )    get( competition_teams_url( code, year )); end

.todays_matches(date = Date.today) ⇒ Object

use/rename to matches_today or such - why? why not?



101
102
103
# File 'lib/footballdata/download.rb', line 101

def self.todays_matches( date=Date.today )    ## use/rename to matches_today or such - why? why not?
    get( todays_matches_url( date ) )
end

.todays_matches_url(date = Date.today) ⇒ Object



96
97
98
99
100
# File 'lib/footballdata/download.rb', line 96

def self.todays_matches_url( date=Date.today )
  "#{BASE_URL}/matches?"+
  "dateFrom=#{date.strftime('%Y-%m-%d')}&"+
  "dateTo=#{(date+1).strftime('%Y-%m-%d')}"
end