Class: Sportradar::Api::Soccer::Group

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

Instance Attribute Summary collapse

Class Method 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 = {}, league_group: nil, **opts) ⇒ Group

Returns a new instance of Group.



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

def initialize(data = {}, league_group: nil, **opts)
  @id = data['id']

  @league_group = league_group || data['league_group']

  @tournaments_hash = {}
  # @daily_schedule   = {}

  update(data, **opts)
end

Instance Attribute Details

#league_groupObject (readonly)

Returns the value of attribute league_group.



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

def league_group
  @league_group
end

Class Method Details

.americasObject



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

def self.americas
  self.new(league_group: 'am')
end

.europeObject



53
54
55
# File 'lib/sportradar/api/soccer/group.rb', line 53

def self.europe
  self.new(league_group: 'eu')
end

.internationalObject



63
64
65
# File 'lib/sportradar/api/soccer/group.rb', line 63

def self.international
  self.new(league_group: 'intl')
end

.north_americaObject



59
60
61
# File 'lib/sportradar/api/soccer/group.rb', line 59

def self.north_america
  self.new(league_group: 'na')
end

Instance Method Details

#apiObject



30
31
32
# File 'lib/sportradar/api/soccer/group.rb', line 30

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

#get_tournamentsObject



34
35
36
37
# File 'lib/sportradar/api/soccer/group.rb', line 34

def get_tournaments
  data = api.get_data(path_tournaments).to_h
  ingest_tournaments(data)
end

#ingest_tournaments(data) ⇒ Object



39
40
41
42
# File 'lib/sportradar/api/soccer/group.rb', line 39

def ingest_tournaments(data)
  update(data, source: :tournaments)
  data
end

#path_tournamentsObject



49
50
51
# File 'lib/sportradar/api/soccer/group.rb', line 49

def path_tournaments
  'tournaments'
end

#queue_tournamentsObject



44
45
46
47
# File 'lib/sportradar/api/soccer/group.rb', line 44

def queue_tournaments
  url, headers, options, timeout = api.get_request_info(path_tournaments)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_tournaments)}
end

#tournament(id) ⇒ Object



26
27
28
# File 'lib/sportradar/api/soccer/group.rb', line 26

def tournament(id)
  @tournaments_hash[id]
end

#tournamentsObject



22
23
24
# File 'lib/sportradar/api/soccer/group.rb', line 22

def tournaments
  @tournaments_hash.values
end

#update(data, **opts) ⇒ Object



18
19
20
# File 'lib/sportradar/api/soccer/group.rb', line 18

def update(data, **opts)
  create_data(@tournaments_hash, data['tournaments'], klass: Tournament, api: api, league_group: @league_group) if data['tournaments']
end