Class: Sportradar::Api::Images

Inherits:
Request
  • Object
show all
Defined in:
lib/sportradar/api/images.rb

Defined Under Namespace

Classes: Asset, AssetList, Link, Ref, Tag

Instance Attribute Summary collapse

Attributes inherited from Request

#qps_allotted, #qps_current, #quota_allotted, #quota_current

Instance Method Summary collapse

Methods inherited from Request

#get, #get_data, #get_request_info, #parse_usage, #sim!, #usage

Constructor Details

#initialize(sport, access_level: 't', league: nil, nfl_premium: false, usat_premium: false, event_id: nil, date: nil) ⇒ Images

Returns a new instance of Images.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/sportradar/api/images.rb', line 6

def initialize( sport, access_level: 't', league: nil, nfl_premium: false, usat_premium: false, event_id: nil, date: nil )
  raise Sportradar::Api::Error::InvalidSport unless allowed_sports.include? sport
  @sport = sport
  raise Sportradar::Api::Error::InvalidLeague unless soccer_leagues.include?(league) || league.nil?
  @league = league
  @nfl_premium = nfl_premium
  @usat_premium = usat_premium
  @event_id = event_id
  @date = date.strftime("%Y/%m/%d") if date
  raise Sportradar::Api::Error::InvalidAccessLevel unless allowed_access_levels.include? access_level
  @access_level = access_level
end

Instance Attribute Details

#access_levelObject

Returns the value of attribute access_level.



5
6
7
# File 'lib/sportradar/api/images.rb', line 5

def access_level
  @access_level
end

#dateObject

Returns the value of attribute date.



5
6
7
# File 'lib/sportradar/api/images.rb', line 5

def date
  @date
end

#event_idObject

Returns the value of attribute event_id.



5
6
7
# File 'lib/sportradar/api/images.rb', line 5

def event_id
  @event_id
end

#leagueObject

Returns the value of attribute league.



5
6
7
# File 'lib/sportradar/api/images.rb', line 5

def league
  @league
end

#live_image_requestObject

Returns the value of attribute live_image_request.



5
6
7
# File 'lib/sportradar/api/images.rb', line 5

def live_image_request
  @live_image_request
end

#nfl_premiumObject

Returns the value of attribute nfl_premium.



5
6
7
# File 'lib/sportradar/api/images.rb', line 5

def nfl_premium
  @nfl_premium
end

#sportObject

Returns the value of attribute sport.



5
6
7
# File 'lib/sportradar/api/images.rb', line 5

def sport
  @sport
end

#usat_premiumObject

Returns the value of attribute usat_premium.



5
6
7
# File 'lib/sportradar/api/images.rb', line 5

def usat_premium
  @usat_premium
end

Instance Method Details

#coach_manifestsObject Also known as: all_coaches

Coach Manifests



41
42
43
44
45
46
47
48
# File 'lib/sportradar/api/images.rb', line 41

def coach_manifests
  response = get request_url("coaches/#{image_type}/manifests/all_assets")
  if response.success? && response["assetlist"]
    Sportradar::Api::Images::AssetList.new response["assetlist"]
  else
    response
  end
end

#event_manifestsObject Also known as: all_events, live_images

Event manifests will respont to either date or event_id



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/sportradar/api/images.rb', line 66

def event_manifests
  # /[league]/[image_type]/events/[year]/[month]/[day]/manifest.[format]?api_key={your_api_key}
  raise Sportradar::Api::Error::InvalidType unless date.present? || event_id.present?
  @live_image_request = true
  if event_id.present?
    response = get request_url("actionshots/events/game/#{event_id}/manifest")
  elsif date.present?
    response = get request_url("actionshots/events/#{date}/manifest")
  end
  if response.success? && response["assetlist"]
    Sportradar::Api::Images::AssetList.new response["assetlist"]
  else
    response
  end

end

#image_url(href) ⇒ Object Also known as: player_images, coach_images, venue_images

The Player Images, Coach Images, Venue 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



86
87
88
89
90
# File 'lib/sportradar/api/images.rb', line 86

def image_url(href)
  @live_image_request = true if href.include?('actionshots')
  href.slice!(0) if href.chars.first == '/' # remove initial '/'
  set_base request_url(href) + api_key_query_string
end

#player_manifests(year = Date.today.year) ⇒ Object Also known as: all_players



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sportradar/api/images.rb', line 19

def player_manifests(year = Date.today.year)
  if league
    if year != Date.today.year
      response = get request_url("#{league}/#{image_type}/players/#{year}/manifest")
    else
      response = get request_url("#{league}/#{image_type}/players/manifest")
    end
  elsif nfl_premium || usat_premium || sport == 'ncaafb'
    response = get request_url("#{image_type}/players/#{year}/manifest")
  else
    response = get request_url("players/#{image_type}/manifests/all_assets")
  end
  if response.success? && response["assetlist"]
    Sportradar::Api::Images::AssetList.new response["assetlist"]
  else
    response
  end
end

#venue_manifestsObject Also known as: all_venues



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sportradar/api/images.rb', line 51

def venue_manifests
  if version == 3
    response = get request_url("venues/manifest")
  else
    response = get request_url("venues/manifests/all_assets")
  end
  if response.success? && response["assetlist"]
    Sportradar::Api::Images::AssetList.new response["assetlist"]
  else
    response
  end
end