Class: Tvdbjson::Episode
- Inherits:
-
Object
- Object
- Tvdbjson::Episode
- Extended by:
- Requestable
- Includes:
- Hashable
- Defined in:
- lib/tvdbjson/episode.rb
Instance Attribute Summary collapse
-
#episode_number ⇒ Object
Returns the value of attribute episode_number.
-
#first_aired ⇒ Object
Returns the value of attribute first_aired.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#overview ⇒ Object
Returns the value of attribute overview.
-
#season_number ⇒ Object
Returns the value of attribute season_number.
-
#series_id ⇒ Object
Returns the value of attribute series_id.
Class Method Summary collapse
- .all_episodes(options = {}, authentication) ⇒ Object
- .from_response(response, series_id) ⇒ Object
- .get_page_count_from_response(response) ⇒ Object
- .search_by_season_and_episode(options = {}, authentication) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Episode
constructor
A new instance of Episode.
Methods included from Requestable
build_uri, send_authenticated_request
Methods included from Hashable
Constructor Details
#initialize(options = {}) ⇒ Episode
Returns a new instance of Episode.
9 10 11 12 13 14 15 16 17 |
# File 'lib/tvdbjson/episode.rb', line 9 def initialize( = {}) @id = [:id] @name = [:name] @series_id = [:series_id] @episode_number = [:episode_number] @season_number = [:season_number] @first_aired = [:first_aired] @overview = [:overview] end |
Instance Attribute Details
#episode_number ⇒ Object
Returns the value of attribute episode_number.
7 8 9 |
# File 'lib/tvdbjson/episode.rb', line 7 def episode_number @episode_number end |
#first_aired ⇒ Object
Returns the value of attribute first_aired.
7 8 9 |
# File 'lib/tvdbjson/episode.rb', line 7 def first_aired @first_aired end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/tvdbjson/episode.rb', line 7 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/tvdbjson/episode.rb', line 7 def name @name end |
#overview ⇒ Object
Returns the value of attribute overview.
7 8 9 |
# File 'lib/tvdbjson/episode.rb', line 7 def overview @overview end |
#season_number ⇒ Object
Returns the value of attribute season_number.
7 8 9 |
# File 'lib/tvdbjson/episode.rb', line 7 def season_number @season_number end |
#series_id ⇒ Object
Returns the value of attribute series_id.
7 8 9 |
# File 'lib/tvdbjson/episode.rb', line 7 def series_id @series_id end |
Class Method Details
.all_episodes(options = {}, authentication) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/tvdbjson/episode.rb', line 19 def self.all_episodes( = {}, authentication) raise Tvdbjson::RequiredSeriesIdMissingError if ![:series_id] raise Tvdbjson::AuthenticationObjectMissingError unless authentication.kind_of?(Tvdbjson::Authentication) hash = { :method => "GET", :uri => "/series/#{[:series_id]}/episodes", :params => { "page" => 1 } } # Create an empty array for all episodes arr = [] # Receive the first page of results response = send_authenticated_request(hash, authentication) # Store the Page count to retrieve additional pages in the future page_count = get_page_count_from_response(response) # Whilst we have the response object for page 1, let's add it to our array arr.concat( Episode.from_response(response,[:series_id]) ) # Now to process the additional pages (starting with page 2) (2..page_count).each do |page_number| hash = { :method => "GET", :uri => "/series/#{[:series_id]}/episodes", :params => { "page" => page_number } } response = send_authenticated_request(hash, authentication) arr.concat( Episode.from_response(response,[:series_id]) ) end arr end |
.from_response(response, series_id) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/tvdbjson/episode.rb', line 71 def self.from_response(response, series_id) results_array = [] begin response.parsed_response["data"].each do |record| hash = {} hash[:id] = record["id"] hash[:name] = record["episodeName"] hash[:series_id] = series_id hash[:episode_number] = record["airedEpisodeNumber"] hash[:season_number] = record["airedSeasonID"] hash[:first_aired] = record["firstAired"] hash[:overview] = record["overview"] result = Episode.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 |
.get_page_count_from_response(response) ⇒ Object
95 96 97 |
# File 'lib/tvdbjson/episode.rb', line 95 def self.get_page_count_from_response(response) response.parsed_response["links"]["last"] end |
.search_by_season_and_episode(options = {}, authentication) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/tvdbjson/episode.rb', line 56 def self.search_by_season_and_episode( = {}, authentication) raise Tvdbjson::RequiredSeriesIdMissingError if ![:series_id] raise Tvdbjson::RequiredSearchParamMissingError if ![:season_number] raise Tvdbjson::RequiredSearchParamMissingError if ![:episode_number] raise Tvdbjson::AuthenticationObjectMissingError unless authentication.kind_of?(Tvdbjson::Authentication) hash = { :method => "GET", :uri => "/series/#{[:series_id]}/episodes/query", :after_action => "Tvdbjson::Episode.from_response(response, #{[:series_id]})", :params => { "airedSeason" => [:season_number], "airedEpisode" => [:episode_number] } } send_authenticated_request(hash, authentication) end |