class TVMaze::Show
Constants
- SHOW_MAPPING
Attributes
episodes[RW]
image_medium[RW]
image_original[RW]
next_episode[RW]
seasons[RW]
Public Class Methods
find(id, params = {})
click to toggle source
# File lib/tvmaze/show.rb, line 45 def self.find(id, params = {}) embed = params.delete(:embed) embed ||= [] result = TVMaze.request(find_url(id, embed), params) Show.new(result) end
new(json = {})
click to toggle source
# File lib/tvmaze/show.rb, line 17 def initialize(json = {}) @seasons = [] @episodes = [] return if json.nil? SHOW_MAPPING.each do |source, destination| send("#{destination}=", json[source.to_s] || json[source.to_sym]) end unless json['image'].nil? @image_original = json['image']['original'] @image_medium = json['image']['medium'] end unless json['_embedded'].nil? embedded_json = json['_embedded'] @next_episode = TVMaze::Episode.new(embedded_json['nextepisode']) @episodes = parse_episodes(embedded_json['episodes']) @seasons = parse_seasons(@episodes) end end
search(query = '', params = {})
click to toggle source
# File lib/tvmaze/show.rb, line 39 def self.search(query = '', params = {}) params[:q] = query.to_s.strip result = TVMaze.request('/search/shows', params) build_search_results(result) end
Protected Class Methods
build_search_results(search_results_json)
click to toggle source
# File lib/tvmaze/show.rb, line 64 def self.build_search_results(search_results_json) search_results_json.map { |entry_json| Show.new(entry_json['show']) } end
find_url(id, embeds_array = [])
click to toggle source
# File lib/tvmaze/show.rb, line 54 def self.find_url(id, embeds_array = []) url = "/shows/#{id}" prefix = 'embed' prefix << '[]' if embeds_array.count > 1 query = embeds_array.map { |e| prefix + '=' + e }.join('&') [url, query].compact.join('?') end
Protected Instance Methods
parse_episodes(json_array)
click to toggle source
# File lib/tvmaze/show.rb, line 68 def parse_episodes(json_array) return [] if json_array.nil? || json_array.count == 0 json_array.map { |episode_json| TVMaze::Episode.new(episode_json) } end
parse_seasons(json_array)
click to toggle source
# File lib/tvmaze/show.rb, line 73 def parse_seasons(json_array) return [] if json_array.nil? || json_array.count == 0 TVMaze::Season.from_episodes(json_array) end