Sha256: 3552d1a1378eac1af85897655bf9ffe520561dc6e9e148689879d8aa46f9d039

Contents?: true

Size: 1.65 KB

Versions: 8

Compression:

Stored size: 1.65 KB

Contents

module Sportradar
  module Api
    module Odds
      class Competition < Data
        attr_accessor :response, :api, :id, :name, :gender


        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

        def update(data, **opts)

        end

        def sport_events
          @sport_events_hash.values
        end

        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

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

        # url path helpers
        def path_base
          "competitions/#{id}"
        end

        def path_player_props
          "#{path_base}/players_props"
        end

        def path_player_props
          "#{path_base}/players_props"
        end

      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sportradar-api-0.20.1 lib/sportradar/api/odds/competition.rb
sportradar-api-0.20.0 lib/sportradar/api/odds/competition.rb
sportradar-api-0.20.0.pre2 lib/sportradar/api/odds/competition.rb
sportradar-api-0.20.0.pre lib/sportradar/api/odds/competition.rb
sportradar-api-0.19.6 lib/sportradar/api/odds/competition.rb
sportradar-api-0.19.5 lib/sportradar/api/odds/competition.rb
sportradar-api-0.19.4 lib/sportradar/api/odds/competition.rb
sportradar-api-0.19.3 lib/sportradar/api/odds/competition.rb