Class: Footballdata::Metal

Inherits:
Object
  • Object
show all
Defined in:
lib/webget-football/apis/download.rb

Overview

todo/check: put in Downloader namespace/class - why? why not?

or use Metal    - no "porcelain" downloaders / machinery

Constant Summary collapse

BASE_URL =
'http://api.football-data.org/v2'

Class Method Summary collapse

Class Method Details

.competition_matches_url(code, year) ⇒ Object

just use matches_url - why? why not?



29
# File 'lib/webget-football/apis/download.rb', line 29

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

.competition_teams_url(code, year) ⇒ Object



30
# File 'lib/webget-football/apis/download.rb', line 30

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

.competitions_tier_oneObject



34
35
36
# File 'lib/webget-football/apis/download.rb', line 34

def self.competitions_tier_one
  get( competitions_url( 'TIER_ONE' ))
end

.competitions_tier_threeObject



42
43
44
# File 'lib/webget-football/apis/download.rb', line 42

def self.competitions_tier_three
  get( competions_url( 'TIER_THREE' ))
end

.competitions_tier_twoObject



38
39
40
# File 'lib/webget-football/apis/download.rb', line 38

def self.competitions_tier_two
  get( competions_url( 'TIER_TWO' ))
end

.competitions_url(plan) ⇒ Object



26
# File 'lib/webget-football/apis/download.rb', line 26

def self.competitions_url( plan )  "#{BASE_URL}/competitions?plan=#{plan}"; end

.get(url) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/webget-football/apis/download.rb', line 70

def self.get( url )
  token = ENV['FOOTBALLDATA']
  ## note: because of public workflow log - do NOT output token
  ## puts token

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

  ## note: add format: 'json' for pretty printing json (before) save in cache
  response = Webget.call( url, headers: 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
end

.matches(code, year) ⇒ Object



51
52
53
# File 'lib/webget-football/apis/download.rb', line 51

def self.matches( code, year )
  get( competition_matches_url( code, year ))
end

.teams(code, year) ⇒ Object



47
48
49
# File 'lib/webget-football/apis/download.rb', line 47

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