Class: Tvdbjson::Image

Inherits:
Object
  • Object
show all
Extended by:
Requestable
Includes:
Hashable
Defined in:
lib/tvdbjson/image.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Requestable

build_uri, send_authenticated_request

Methods included from Hashable

#to_hash

Constructor Details

#initialize(options = {}) ⇒ Image

Returns a new instance of Image.



8
9
10
11
12
13
14
15
16
17
18
# 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

Instance Attribute Details

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/tvdbjson/image.rb', line 6

def id
  @id
end

#rating_averageObject

Returns the value of attribute rating_average.



6
7
8
# File 'lib/tvdbjson/image.rb', line 6

def rating_average
  @rating_average
end

#rating_countObject

Returns the value of attribute rating_count.



6
7
8
# File 'lib/tvdbjson/image.rb', line 6

def rating_count
  @rating_count
end

#resolutionObject

Returns the value of attribute resolution.



6
7
8
# File 'lib/tvdbjson/image.rb', line 6

def resolution
  @resolution
end

#series_idObject

Returns the value of attribute series_id.



6
7
8
# File 'lib/tvdbjson/image.rb', line 6

def series_id
  @series_id
end

#subkeyObject

Returns the value of attribute subkey.



6
7
8
# File 'lib/tvdbjson/image.rb', line 6

def subkey
  @subkey
end

#thumbnail_urlObject

Returns the value of attribute thumbnail_url.



6
7
8
# File 'lib/tvdbjson/image.rb', line 6

def thumbnail_url
  @thumbnail_url
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/tvdbjson/image.rb', line 6

def type
  @type
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/tvdbjson/image.rb', line 6

def url
  @url
end

Class Method Details

.from_response(response, series_id) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 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

.search_by_series(options = {}, authentication) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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