Sha256: 2241797511ab98f9aeb8ac02dab55fb3b39f362a06dd48a68b73998e90e5f0fa

Contents?: true

Size: 1.91 KB

Versions: 68

Compression:

Stored size: 1.91 KB

Contents

module Sportradar
  module Api
    module Baseball
      class Mlb < Request
        attr_accessor :league, :access_level, :simulation, :error

        def initialize(access_level = default_access_level)
          @league = 'mlb'
          raise Sportradar::Api::Error::InvalidAccessLevel unless allowed_access_levels.include? access_level
          @access_level = access_level
        end

        def sim!
          @version = 5
          super
        end

        def get_data(url)
          data = get request_url(url)
          if data.is_a?(Sportradar::Api::Error)
            puts request_url(url)
            puts
            puts data.inspect
            raise 'Sportradar error'
          end
          data
        end

        def default_year
          Date.today.year
        end
        def default_date
          Date.today
        end
        def default_season
          'reg'
        end
        def default_access_level
          if (ENV['SPORTRADAR_ENV'] || ENV['SPORTRADAR_ENV_MLB'] || ENV['RACK_ENV'] || ENV['RAILS_ENV']) == 'production'
            'p'
          else
            't'
          end
        end

        def content_format
          'json'
        end

        private

        def request_url(path)
          "/mlb-#{access_level}#{version}/#{path}"
        end

        def api_key
          if !['t', 'sim'].include?(access_level)
            Sportradar::Api.api_key_params('mlb', 'production')
          elsif 'sim' == access_level
            Sportradar::Api.api_key_params('mlb', 'simulation')
          else
            Sportradar::Api.api_key_params('mlb')
          end
        end

        def version
          @version || Sportradar::Api.version('mlb')
        end

        def allowed_access_levels
          %w[p t sim]
        end

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

      end
    end
  end
end

__END__
# mlb = Sportradar::Api::Baseball::Mlb::Hierarchy.new

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
sportradar-api-0.11.69 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.68 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.67 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.66 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.65 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.64 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.63 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.62 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.61 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.60 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.59 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.58 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.57 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.56 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.55 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.54 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.53 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.52 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.51 lib/sportradar/api/baseball/mlb.rb
sportradar-api-0.11.50 lib/sportradar/api/baseball/mlb.rb