Sha256: 78cb1100789a6fbccb58794c0ec41977d2951c6c93c85c8ac45ca2bccccbdd1f

Contents?: true

Size: 1.91 KB

Versions: 240

Compression:

Stored size: 1.91 KB

Contents

module Sportradar
  module Api
    class LiveImages < Request
      attr_accessor :sport, :access_level

      def initialize( sport, access_level = 't')
        raise Sportradar::Api::Error::InvalidSport unless allowed_sports.include? sport
        @sport = sport
        raise Sportradar::Api::Error::InvalidAccessLevel unless allowed_access_levels.include? access_level
        @access_level = access_level
      end

      def daily_manifest(date = Date.today )
        response = get request_url("#{image_type }/#{date.to_s}/manifests/all_assets")
        if response.success? && response["assetlist"]
          Sportradar::Api::Images::AssetList.new response["assetlist"]
        else
          response
        end
      end
      alias_method :all_images, :daily_manifest

      # The Event images APIs aren't really meant to be used directly, the manifests return an href path of an image we can pass it into the image_url method to get the entire image url
      def image_url(href)
        href.slice!(0) if href.chars.first == '/'  # remove initial '/'
        set_base request_url(href) + api_key_query_string
      end

      private

      def request_url(path)
        "/#{sport}-liveimages-#{access_level}#{version}/#{provider}/#{path}"
      end

      def api_key
        if access_level == 'p'
          Sportradar::Api.api_key_params("live_images_#{sport}", "production")
        else
          Sportradar::Api.api_key_params("live_images_#{sport}")
        end

      end

      def api_key_query_string
        "?#{api_key.keys.first}=#{api_key.values.first}"
      end

      def provider
        'usat'
      end

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

      def image_type
        'news'
      end

      def allowed_access_levels
        ['p', 't']
      end

      def allowed_sports
        ['golf', 'mlb', 'nascar', 'nba', 'nfl', 'nhl', 'ncaafb', 'ncaamb', 'mls']
      end

    end
  end
end

Version data entries

240 entries across 240 versions & 1 rubygems

Version Path
sportradar-api-0.11.8 lib/sportradar/api/live_images.rb
sportradar-api-0.11.7 lib/sportradar/api/live_images.rb
sportradar-api-0.11.6 lib/sportradar/api/live_images.rb
sportradar-api-0.11.5 lib/sportradar/api/live_images.rb
sportradar-api-0.11.4 lib/sportradar/api/live_images.rb
sportradar-api-0.11.3 lib/sportradar/api/live_images.rb
sportradar-api-0.11.1 lib/sportradar/api/live_images.rb
sportradar-api-0.11.0 lib/sportradar/api/live_images.rb
sportradar-api-0.10.55 lib/sportradar/api/live_images.rb
sportradar-api-0.10.54 lib/sportradar/api/live_images.rb
sportradar-api-0.10.53 lib/sportradar/api/live_images.rb
sportradar-api-0.10.52 lib/sportradar/api/live_images.rb
sportradar-api-0.10.51 lib/sportradar/api/live_images.rb
sportradar-api-0.10.50 lib/sportradar/api/live_images.rb
sportradar-api-0.10.49 lib/sportradar/api/live_images.rb
sportradar-api-0.10.48 lib/sportradar/api/live_images.rb
sportradar-api-0.10.47 lib/sportradar/api/live_images.rb
sportradar-api-0.10.46 lib/sportradar/api/live_images.rb
sportradar-api-0.10.45 lib/sportradar/api/live_images.rb
sportradar-api-0.10.44 lib/sportradar/api/live_images.rb