Class: Sportradar::Api::Odds::Competition

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/odds/competition.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, **opts) ⇒ Competition

Returns a new instance of Competition.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/sportradar/api/odds/competition.rb', line 8

def initialize(data, **opts)
  @response = data
  @api      = opts[:api]
  @id       = data['id']

  @name         = data['name']
  @gender       = data['gender']
  @has_markets      = data['markets']       # boolean
  @has_futures      = data['futures']       # boolean
  @has_player_props = data['player_props']  # boolean

  @sport_events_hash = {}
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



5
6
7
# File 'lib/sportradar/api/odds/competition.rb', line 5

def api
  @api
end

#genderObject

Returns the value of attribute gender.



5
6
7
# File 'lib/sportradar/api/odds/competition.rb', line 5

def gender
  @gender
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/sportradar/api/odds/competition.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/sportradar/api/odds/competition.rb', line 5

def name
  @name
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/sportradar/api/odds/competition.rb', line 5

def response
  @response
end

Instance Method Details

#fetch_player_props(params = {}) ⇒ Object



44
45
46
# File 'lib/sportradar/api/odds/competition.rb', line 44

def fetch_player_props(params = {})
  api.get_data(path_player_props, params)
end

#get_player_propsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sportradar/api/odds/competition.rb', line 30

def get_player_props
  prop_data = fetch_player_props.fetch('competition_sport_events_players_props', [])
  if prop_data.size == 10
    new_data = prop_data
    while new_data.size == 10
      new_data = fetch_player_props(start: prop_data.size).fetch('competition_sport_events_players_props', [])
      prop_data += new_data
    end
  end
  data = {'competition_sport_events_players_props' => prop_data }
  create_data(@sport_events_hash, prop_data, klass: SportEvent, api: api)
  data
end

#path_baseObject

url path helpers



49
50
51
# File 'lib/sportradar/api/odds/competition.rb', line 49

def path_base
  "competitions/#{id}"
end

#path_player_propsObject



53
54
55
# File 'lib/sportradar/api/odds/competition.rb', line 53

def path_player_props
  "#{path_base}/players_props"
end

#sport_eventsObject



26
27
28
# File 'lib/sportradar/api/odds/competition.rb', line 26

def sport_events
  @sport_events_hash.values
end

#update(data, **opts) ⇒ Object



22
23
24
# File 'lib/sportradar/api/odds/competition.rb', line 22

def update(data, **opts)

end