Sha256: c10c0057bde92b6ea183ed8658193a3017ad944753b1b7b24d682e6a65cbf8f2

Contents?: true

Size: 1.79 KB

Versions: 12

Compression:

Stored size: 1.79 KB

Contents

module Sportradar
  module Api
    module Football
      class Nfl
        class Api < Request
          attr_accessor :league, :access_level, :error

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

          def default_year
            default_date.year
          end
          def default_date
            Date.today - 90
          end
          def default_season
            'reg'
          end
          def default_access_level
            if (ENV['SPORTRADAR_ENV'] || ENV['SPORTRADAR_ENV_NFL'] || ENV['RACK_ENV'] || ENV['RAILS_ENV']) == 'production'
              'production'
            else
              'trial'
            end
          end

          private

          def content_format
            'json'
          end

          def request_url(path)
            "/nfl/official/#{access_level}/v#{version}/en/#{path}"
          end

          def api_key
            if !['trial', 'sim'].include?(access_level) || (access_level == 'sim' && default_access_level == 'production')
              ::Sportradar::Api.api_key_params('nfl', 'production')
            else
              ::Sportradar::Api.api_key_params('nfl')
            end
          end

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

          def allowed_access_levels
            %w[production trial sim]
          end

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

      end
    end
  end
end

__END__

nfl = Sportradar::Api::Football.Nfl.new
sw = nfl.weekly_schedule;
ss = nfl.schedule;

ss.games.count
ss.weeks.count
ss.weeks.first.response['game'].count

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
sportradar-api-0.20.2 lib/sportradar/api/football/nfl/api.rb
sportradar-api-0.20.1 lib/sportradar/api/football/nfl/api.rb
sportradar-api-0.20.0 lib/sportradar/api/football/nfl/api.rb
sportradar-api-0.20.0.pre2 lib/sportradar/api/football/nfl/api.rb
sportradar-api-0.20.0.pre lib/sportradar/api/football/nfl/api.rb
sportradar-api-0.19.6 lib/sportradar/api/football/nfl/api.rb
sportradar-api-0.19.5 lib/sportradar/api/football/nfl/api.rb
sportradar-api-0.19.4 lib/sportradar/api/football/nfl/api.rb
sportradar-api-0.19.3 lib/sportradar/api/football/nfl/api.rb
sportradar-api-0.19.2 lib/sportradar/api/football/nfl/api.rb
sportradar-api-0.19.1 lib/sportradar/api/football/nfl/api.rb
sportradar-api-0.19.0 lib/sportradar/api/football/nfl/api.rb