Class: Sportradar::Api::Soccer::Season

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/soccer/season.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Data

#all_attributes, #attributes, #create_data, #parse_into_array, #parse_into_array_with_options, #parse_out_hashes, #structure_links, #update_data

Constructor Details

#initialize(data = {}, competition: nil, **opts) ⇒ Season

Returns a new instance of Season.



7
8
9
10
11
12
13
14
15
16
# File 'lib/sportradar/api/soccer/season.rb', line 7

def initialize(data = {}, competition: nil, **opts)
  @response     = data
  @id           = data["id"]
  @api          = opts[:api]
  @competition  = competition
  @matches_hash = {}
  @competitors_hash = {}

  update(data, **opts)
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



5
6
7
# File 'lib/sportradar/api/soccer/season.rb', line 5

def category
  @category
end

#competitionObject (readonly)

Returns the value of attribute competition.



5
6
7
# File 'lib/sportradar/api/soccer/season.rb', line 5

def competition
  @competition
end

#current_seasonObject (readonly)

Returns the value of attribute current_season.



5
6
7
# File 'lib/sportradar/api/soccer/season.rb', line 5

def current_season
  @current_season
end

#end_dateObject (readonly)

Returns the value of attribute end_date.



5
6
7
# File 'lib/sportradar/api/soccer/season.rb', line 5

def end_date
  @end_date
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/sportradar/api/soccer/season.rb', line 5

def id
  @id
end

#league_groupObject (readonly)

Returns the value of attribute league_group.



5
6
7
# File 'lib/sportradar/api/soccer/season.rb', line 5

def league_group
  @league_group
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/sportradar/api/soccer/season.rb', line 5

def name
  @name
end

#season_coverage_infoObject (readonly)

Returns the value of attribute season_coverage_info.



5
6
7
# File 'lib/sportradar/api/soccer/season.rb', line 5

def season_coverage_info
  @season_coverage_info
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



5
6
7
# File 'lib/sportradar/api/soccer/season.rb', line 5

def start_date
  @start_date
end

Instance Method Details

#apiObject



72
73
74
# File 'lib/sportradar/api/soccer/season.rb', line 72

def api
  @api ||= Sportradar::Api::Soccer::Api.new(league_group: @league_group)
end

#competitorsObject



56
57
58
# File 'lib/sportradar/api/soccer/season.rb', line 56

def competitors
  @competitors_hash.values
end

#current?Boolean

def get_tournament_id(data, **opts)

@tournament_id ||= if opts[:tournament]
  opts[:tournament].id
elsif data['tournament_id']
  data['tournament_id']
elsif data['tournament']
  data.dig('tournament', 'id')
end

end

Returns:

  • (Boolean)


48
49
50
# File 'lib/sportradar/api/soccer/season.rb', line 48

def current?
  !!@current
end

#get_competitorsObject



97
98
99
100
# File 'lib/sportradar/api/soccer/season.rb', line 97

def get_competitors
  data = api.get_data(path_competitors).to_h
  ingest_competitors(data)
end

#get_scheduleObject



83
84
85
86
# File 'lib/sportradar/api/soccer/season.rb', line 83

def get_schedule
  data = api.get_data(path_schedule).to_h
  ingest_schedule(data)
end

#ingest_competitors(data) ⇒ Object



101
102
103
104
105
106
# File 'lib/sportradar/api/soccer/season.rb', line 101

def ingest_competitors(data)
  @competitors_retrieved = true
  update(data)
  # TODO parse the rest of the data. keys: ["tournament", "sport_events"]
  data
end

#ingest_schedule(data) ⇒ Object



87
88
89
90
91
92
# File 'lib/sportradar/api/soccer/season.rb', line 87

def ingest_schedule(data)
  @schedule_retrieved = true
  update(data)
  # TODO parse the rest of the data. keys: ["tournament", "sport_events"]
  data
end

#matchesObject



52
53
54
# File 'lib/sportradar/api/soccer/season.rb', line 52

def matches
  @matches_hash.values
end

#parse_competitors(data) ⇒ Object



66
67
68
69
70
# File 'lib/sportradar/api/soccer/season.rb', line 66

def parse_competitors(data)
  if data['season_competitors']
    create_data(@competitors_hash, data['season_competitors'], klass: Team, api: api, competition: @competition, season: self)
  end
end

#parse_schedule(data) ⇒ Object



60
61
62
63
64
# File 'lib/sportradar/api/soccer/season.rb', line 60

def parse_schedule(data)
  if data['schedules']
    create_data(@matches_hash, data['schedules'], klass: Match, api: api, competition: @competition, season: self)
  end
end

#path_baseObject



76
77
78
# File 'lib/sportradar/api/soccer/season.rb', line 76

def path_base
  "seasons/#{@id}"
end

#path_competitorsObject



94
95
96
# File 'lib/sportradar/api/soccer/season.rb', line 94

def path_competitors
  "#{ path_base }/competitors"
end

#path_scheduleObject



80
81
82
# File 'lib/sportradar/api/soccer/season.rb', line 80

def path_schedule
  "#{ path_base }/schedules"
end

#queue_scheduleObject



107
108
109
110
# File 'lib/sportradar/api/soccer/season.rb', line 107

def queue_schedule
  url, headers, options, timeout = api.get_request_info(path_schedule)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_schedule)}
end

#update(data, **opts) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sportradar/api/soccer/season.rb', line 18

def update(data, **opts)
  @league_group       = opts[:league_group] || data['league_group'] || @league_group
  @id                 = data['id'] || data['season_id'] || @id
  @current            = opts[:current] || @current
  # get_tournament_id(data, **opts)

  @name               = data['name']                || @name
  @start_date         = data['start_date']          || @start_date
  @end_date           = data['end_date']            || @end_date
  @year               = data['year']                || @year
  @scheduled          = data['scheduled']           || @scheduled
  @played             = data['played']              || @played
  @max_coverage_level = data['max_coverage_level']  || @max_coverage_level
  @max_covered        = data['max_covered']         || @max_covered
  @min_coverage_level = data['min_coverage_level']  || @min_coverage_level

  parse_schedule(data)
  parse_competitors(data)
end