Sha256: 62ae54c3dbec934a4e0a2f5eb979db8478903bea4b752d584c4e646154a66e1a

Contents?: true

Size: 1.75 KB

Versions: 61

Compression:

Stored size: 1.75 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'
              'o'
            else
              'ot'
            end
          end

          private

          def content_format
            'json'
          end

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

          def api_key
            if !['ot', 'sim'].include?(access_level) || (default_access_level == 'o' && access_level == 'sim')
              ::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[rt o p s b t ot 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

61 entries across 61 versions & 1 rubygems

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