Class: Sportradar::Api::Odds::Base

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/odds/base.rb

Direct Known Subclasses

PlayerOdds

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

#initializeBase

Returns a new instance of Base.



7
8
9
10
11
# File 'lib/sportradar/api/odds/base.rb', line 7

def initialize
  @api = self.class.api
  @books_hash = {}
  @sports_hash = {}
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



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

def api
  @api
end

Class Method Details

.apiObject



86
87
88
# File 'lib/sportradar/api/odds/base.rb', line 86

def self.api
  Api.new(base_path: api_base)
end

Instance Method Details

#booksObject



13
14
15
# File 'lib/sportradar/api/odds/base.rb', line 13

def books
  @books_hash.values
end

#get_booksObject



21
22
23
24
25
# File 'lib/sportradar/api/odds/base.rb', line 21

def get_books
  data = api.get_data(path_books);
  create_data(@books_hash, data['books'], klass: Book, api: api)
  data
end

#get_competitor_mappingsObject



57
58
59
# File 'lib/sportradar/api/odds/base.rb', line 57

def get_competitor_mappings
  data = api.get_data(path_competitor_mappings)
end

#get_event_mappingsObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sportradar/api/odds/base.rb', line 33

def get_event_mappings
  data = api.get_data(path_event_mappings).fetch('mappings', [])
  if data.size == 1000
    new_data = data
    while new_data.size == 1000
      new_data = api.get_data(path_player_mappings, start: data.size).fetch('mappings', [])
      data += new_data
    end
  end
  {'mappings' => data }
end

#get_player_mappingsObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/sportradar/api/odds/base.rb', line 45

def get_player_mappings
  data = api.get_data(path_player_mappings).fetch('mappings', [])
  if data.size == 1000
    new_data = data
    while new_data.size == 1000
      new_data = api.get_data(path_player_mappings, start: data.size).fetch('mappings', [])
      data += new_data
    end
  end
  {'mappings' => data }
end

#get_sportsObject



27
28
29
30
31
# File 'lib/sportradar/api/odds/base.rb', line 27

def get_sports
  data = api.get_data(path_sports);
  create_data(@sports_hash, data['sports'], klass: Sport, api: api)
  data
end

#path_baseObject

url path helpers



62
63
64
# File 'lib/sportradar/api/odds/base.rb', line 62

def path_base
  ""
end

#path_booksObject



66
67
68
# File 'lib/sportradar/api/odds/base.rb', line 66

def path_books
  "books"
end

#path_competitor_mappingsObject



82
83
84
# File 'lib/sportradar/api/odds/base.rb', line 82

def path_competitor_mappings
  'competitors/mappings'
end

#path_event_mappingsObject



74
75
76
# File 'lib/sportradar/api/odds/base.rb', line 74

def path_event_mappings
  'sport_events/mappings'
end

#path_player_mappingsObject



78
79
80
# File 'lib/sportradar/api/odds/base.rb', line 78

def path_player_mappings
  'players/mappings'
end

#path_sportsObject



70
71
72
# File 'lib/sportradar/api/odds/base.rb', line 70

def path_sports
  "sports"
end

#sportsObject



17
18
19
# File 'lib/sportradar/api/odds/base.rb', line 17

def sports
  @sports_hash.values
end