Class: Tvdbjson::Image
- Inherits:
-
Object
- Object
- Tvdbjson::Image
- Extended by:
- Requestable
- Includes:
- Hashable
- Defined in:
- lib/tvdbjson/image.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#rating_average ⇒ Object
Returns the value of attribute rating_average.
-
#rating_count ⇒ Object
Returns the value of attribute rating_count.
-
#resolution ⇒ Object
Returns the value of attribute resolution.
-
#series_id ⇒ Object
Returns the value of attribute series_id.
-
#subkey ⇒ Object
Returns the value of attribute subkey.
-
#thumbnail_url ⇒ Object
Returns the value of attribute thumbnail_url.
-
#type ⇒ Object
Returns the value of attribute type.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .from_response(response, series_id) ⇒ Object
- .search_by_series(options = {}, authentication) ⇒ Object
- .search_by_series_and_season(options = {}, authentication) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Image
constructor
A new instance of Image.
Methods included from Requestable
build_uri, send_authenticated_request
Methods included from Hashable
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( = {}) @id = [:id] @series_id = [:series_id] @url = [:url] @type = [:type] @subkey = [:subkey] @resolution = [:resolution] @rating_average = [:rating_average] @rating_count = [:rating_count] @thumbnail_url = [:thumbnail_url] end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/tvdbjson/image.rb', line 6 def id @id end |
#rating_average ⇒ Object
Returns the value of attribute rating_average.
6 7 8 |
# File 'lib/tvdbjson/image.rb', line 6 def @rating_average end |
#rating_count ⇒ Object
Returns the value of attribute rating_count.
6 7 8 |
# File 'lib/tvdbjson/image.rb', line 6 def @rating_count end |
#resolution ⇒ Object
Returns the value of attribute resolution.
6 7 8 |
# File 'lib/tvdbjson/image.rb', line 6 def resolution @resolution end |
#series_id ⇒ Object
Returns the value of attribute series_id.
6 7 8 |
# File 'lib/tvdbjson/image.rb', line 6 def series_id @series_id end |
#subkey ⇒ Object
Returns the value of attribute subkey.
6 7 8 |
# File 'lib/tvdbjson/image.rb', line 6 def subkey @subkey end |
#thumbnail_url ⇒ Object
Returns the value of attribute thumbnail_url.
6 7 8 |
# File 'lib/tvdbjson/image.rb', line 6 def thumbnail_url @thumbnail_url end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/tvdbjson/image.rb', line 6 def type @type end |
#url ⇒ Object
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( = {}, authentication) raise Tvdbjson::RequiredSeriesIdMissingError if ![:series_id] raise Tvdbjson::RequiredSearchParamMissingError if ![:type] raise Tvdbjson::AuthenticationObjectMissingError unless authentication.kind_of?(Tvdbjson::Authentication) raise Tvdbjson::InvalidImageTypeRequestedError unless %w(fanart poster season seasonwide series).include?([:type]) hash = { :method => "GET", :uri => "/series/#{[:series_id]}/images/query", :after_action => "Tvdbjson::Image.from_response(response, #{[:series_id]})", :params => { "keyType" => [: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( = {}, authentication) raise Tvdbjson::RequiredSeriesIdMissingError if ![:series_id] raise Tvdbjson::RequiredSearchParamMissingError if ![:subkey] raise Tvdbjson::AuthenticationObjectMissingError unless authentication.kind_of?(Tvdbjson::Authentication) raise Tvdbjson::InvalidImageTypeRequestedError unless %w(fanart poster season seasonwide series).include?([:type]) hash = { :method => "GET", :uri => "/series/#{[:series_id]}/images/query", :after_action => "Tvdbjson::Image.from_response(response, #{[:series_id]})", :params => { "keyType" => [:type].downcase, "subKey" => [:subkey] } } send_authenticated_request(hash, authentication) end |