Class: TmdbImage

Inherits:
Object show all
Defined in:
lib/tmdb/tmdb_image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ident, api_key, logger, filespec = nil) ⇒ TmdbImage

imdb_id => String IMDB ID either with or without the ‘tt’ prefix api_key => String containing the themovieDb.com API key logger => nil or logger instance



7
8
9
10
11
12
# File 'lib/tmdb/tmdb_image.rb', line 7

def initialize(ident, api_key, logger, filespec=nil)
  @imdb_id = 'tt' + ident.gsub(/^tt/, '') unless ident.blank?
  @api_key = api_key
  @logger = OptionalLogger.new(logger)
  @filespec = filespec
end

Instance Attribute Details

#imdb_idObject (readonly)

Returns the value of attribute imdb_id.



2
3
4
# File 'lib/tmdb/tmdb_image.rb', line 2

def imdb_id
  @imdb_id
end

Instance Method Details

#fanart(size, dest_filespec = nil) ⇒ Object

return nil or the source url to the given size (must be in fanart_sizes) fanart optionally save the image to dest_filespec unless dest_filespec is nil



26
27
28
29
30
31
32
33
# File 'lib/tmdb/tmdb_image.rb', line 26

def fanart(size, dest_filespec=nil)
  src_url = nil
  if fanart_sizes.include?(size)
    src_url = image_url(@imdb_id, 'fanarts', size)
    copy_image(src_url, dest_filespec)
  end
  src_url
end

#fanart_mid(dest_filespec = nil) ⇒ Object

return nil or the source url to the ‘mid’ size fanart optionally save the image to dest_filespec unless dest_filespec is nil



54
55
56
# File 'lib/tmdb/tmdb_image.rb', line 54

def fanart_mid(dest_filespec=nil)
  fanart('mid', dest_filespec)
end

#fanart_original(dest_filespec = nil) ⇒ Object

return nil or the source url to the ‘original’ size fanart optionally save the image to dest_filespec unless dest_filespec is nil



48
49
50
# File 'lib/tmdb/tmdb_image.rb', line 48

def fanart_original(dest_filespec=nil)
  fanart('original', dest_filespec)
end

#fanart_sizesObject

return an Array of fanart sizes as Strings



15
16
17
# File 'lib/tmdb/tmdb_image.rb', line 15

def fanart_sizes
  ['original', 'mid', 'thumb']
end

#fanart_thumb(dest_filespec = nil) ⇒ Object

return nil or the source url to the ‘thumb’ size fanart optionally save the image to dest_filespec unless dest_filespec is nil



60
61
62
# File 'lib/tmdb/tmdb_image.rb', line 60

def fanart_thumb(dest_filespec=nil)
  fanart('thumb', dest_filespec)
end

#poster(size, dest_filespec = nil) ⇒ Object

return nil or the source url to the given size (must be in poster_sizes) poster optionally save the image to dest_filespec unless dest_filespec is nil



37
38
39
40
41
42
43
44
# File 'lib/tmdb/tmdb_image.rb', line 37

def poster(size, dest_filespec=nil)
  src_url = nil
  if poster_sizes.include?(size)
    src_url = image_url(@imdb_id, 'posters', size)
    copy_image(src_url, dest_filespec)
  end
  src_url
end

#poster_cover(dest_filespec = nil) ⇒ Object

return nil or the source url to the ‘cover’ size poster optionally save the image to dest_filespec unless dest_filespec is nil



84
85
86
# File 'lib/tmdb/tmdb_image.rb', line 84

def poster_cover(dest_filespec=nil)
  poster('original', dest_filespec)
end

#poster_mid(dest_filespec = nil) ⇒ Object

return nil or the source url to the ‘mid’ size poster optionally save the image to dest_filespec unless dest_filespec is nil



72
73
74
# File 'lib/tmdb/tmdb_image.rb', line 72

def poster_mid(dest_filespec=nil)
  poster('original', dest_filespec)
end

#poster_original(dest_filespec = nil) ⇒ Object

return nil or the source url to the ‘original’ size poster optionally save the image to dest_filespec unless dest_filespec is nil



66
67
68
# File 'lib/tmdb/tmdb_image.rb', line 66

def poster_original(dest_filespec=nil)
  poster('original', dest_filespec)
end

#poster_sizesObject

return an Array of poster sizes as Strings



20
21
22
# File 'lib/tmdb/tmdb_image.rb', line 20

def poster_sizes
  ['original', 'mid', 'thumb', 'cover']
end

#poster_thumb(dest_filespec = nil) ⇒ Object

return nil or the source url to the ‘thumb’ size poster optionally save the image to dest_filespec unless dest_filespec is nil



78
79
80
# File 'lib/tmdb/tmdb_image.rb', line 78

def poster_thumb(dest_filespec=nil)
  poster('original', dest_filespec)
end