class Tvdbjson::Image

Attributes

id[RW]
rating_average[RW]
rating_count[RW]
resolution[RW]
series_id[RW]
subkey[RW]
thumbnail_url[RW]
type[RW]
url[RW]

Public Class Methods

from_response(response, series_id) click to toggle source
# File lib/tvdbjson/image.rb, line 50
def self.from_response(response, series_id)
  results_array = []

  begin
    response.parsed_response["data"].each do |record|
      hash                  = {}
      hash[:id]             = record["id"]
      hash[:series_id]      = series_id
      hash[:url]            = "https://thetvdb.com/banners/" + record["fileName"]
      hash[:type]           = record["keyType"]
      hash[:subkey]         = record["subKey"]
      hash[:resolution]     = record["resolution"]
      hash[:rating_average] = record["ratingsInfo"]["average"] if record["ratingsInfo"]
      hash[:rating_count]   = record["ratingsInfo"]["count"] if record["ratingsInfo"]
      hash[:thumbnail_url]  = "https://thetvdb.com/banners/" + record["thumbnail"]

      result = Image.new(hash)
      results_array << result
    end
  rescue NoMethodError
    # Means an empty result set was found, don't do anything special
    # here as this method will return an empty array.
  end
  results_array
end
new(options = {}) click to toggle source
# File lib/tvdbjson/image.rb, line 8
def initialize(options = {})
  @id             = options[:id]
  @series_id      = options[:series_id]
  @url            = options[:url]
  @type           = options[:type]
  @subkey         = options[:subkey]
  @resolution     = options[:resolution]
  @rating_average = options[:rating_average]
  @rating_count   = options[:rating_count]
  @thumbnail_url  = options[:thumbnail_url]
end
search_by_series(options = {}, authentication) click to toggle source
# File lib/tvdbjson/image.rb, line 20
def self.search_by_series(options = {}, authentication)
  raise Tvdbjson::RequiredSeriesIdMissingError if !options[:series_id]
  raise Tvdbjson::RequiredSearchParamMissingError if !options[:type]
  raise Tvdbjson::AuthenticationObjectMissingError unless authentication.kind_of?(Tvdbjson::Authentication)
  raise Tvdbjson::InvalidImageTypeRequestedError unless %w(fanart poster season seasonwide series).include?(options[:type])

  hash = {
    :method       => "GET",
    :uri          => "/series/#{options[:series_id]}/images/query",
    :after_action => "Tvdbjson::Image.from_response(response, #{options[:series_id]})",
    :params       => { "keyType" => options[:type].downcase }
  }
  send_authenticated_request(hash, authentication)
end
search_by_series_and_season(options = {}, authentication) click to toggle source
# File lib/tvdbjson/image.rb, line 35
def self.search_by_series_and_season(options = {}, authentication)
  raise Tvdbjson::RequiredSeriesIdMissingError if !options[:series_id]
  raise Tvdbjson::RequiredSearchParamMissingError if !options[:subkey]
  raise Tvdbjson::AuthenticationObjectMissingError unless authentication.kind_of?(Tvdbjson::Authentication)
  raise Tvdbjson::InvalidImageTypeRequestedError unless %w(fanart poster season seasonwide series).include?(options[:type])

  hash = {
    :method       => "GET",
    :uri          => "/series/#{options[:series_id]}/images/query",
    :after_action => "Tvdbjson::Image.from_response(response, #{options[:series_id]})",
    :params       => { "keyType" => options[:type].downcase, "subKey" => options[:subkey] }
  }
  send_authenticated_request(hash, authentication)
end