Sha256: c7d11b5f5320bd9c06dee9593ab92079be757f87d5ebd58c0584d9fc6707738e

Contents?: true

Size: 1.76 KB

Versions: 15

Compression:

Stored size: 1.76 KB

Contents

module Sportradar
  module Api
    module Soccer
      class Api < Request
        attr_accessor :league_group, :access_level, :language_code, :error

        def initialize(access_level: default_access_level, league_group:, language_code: 'en')
          @league_group = league_group
          @language_code = language_code
          @access_level = access_level
          raise Sportradar::Api::Error::InvalidLeague unless allowed_leagues.include? @league_group
          raise Sportradar::Api::Error::InvalidAccessLevel unless allowed_access_levels.include? @access_level
        end

        def default_year
          (Date.today - 210).year # TODO
        end
        def default_season
          'reg'
        end
        def default_access_level
          if (ENV['SPORTRADAR_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV']) == 'production'
            'x'
          else
            'xt'
          end
        end

        def content_format
          'json'
        end

        private

        def request_url(path)
          "/soccer-#{access_level}#{version}/#{league_group}/#{language_code}/#{path}"
        end

        def api_key
          if !['xt', 'sim'].include?(access_level) || (access_level == 'sim' && default_access_level == 'x')
            Sportradar::Api.api_key_params("soccer-#{@league_group}", 'production')
          else
            Sportradar::Api.api_key_params("soccer-#{@league_group}")
          end
        end

        def version
          Sportradar::Api.version('soccer')
        end

        def allowed_access_levels
          %w[x xt sim]
        end

        def allowed_leagues
          ["eu", "am", "as", "intl", "other", "global"]
        end

        # def allowed_seasons
        #   ["pre", "reg", "pst"]
        # end
      end

    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
sportradar-api-0.13.14 lib/sportradar/api/soccer/api.rb
sportradar-api-0.13.13 lib/sportradar/api/soccer/api.rb
sportradar-api-0.13.12 lib/sportradar/api/soccer/api.rb
sportradar-api-0.13.11 lib/sportradar/api/soccer/api.rb
sportradar-api-0.13.10 lib/sportradar/api/soccer/api.rb
sportradar-api-0.13.9 lib/sportradar/api/soccer/api.rb
sportradar-api-0.13.8 lib/sportradar/api/soccer/api.rb
sportradar-api-0.13.7 lib/sportradar/api/soccer/api.rb
sportradar-api-0.13.6 lib/sportradar/api/soccer/api.rb
sportradar-api-0.13.5 lib/sportradar/api/soccer/api.rb
sportradar-api-0.13.4 lib/sportradar/api/soccer/api.rb
sportradar-api-0.13.3 lib/sportradar/api/soccer/api.rb
sportradar-api-0.13.2 lib/sportradar/api/soccer/api.rb
sportradar-api-0.13.1 lib/sportradar/api/soccer/api.rb
sportradar-api-0.13.0 lib/sportradar/api/soccer/api.rb