Class: TvdbParty::Search

Inherits:
Object
  • Object
show all
Includes:
HTTParty, HTTParty::Icebox
Defined in:
lib/tvdb_party/search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HTTParty::Icebox

included

Constructor Details

#initialize(the_api_key, language = 'en') ⇒ Search

Returns a new instance of Search.



10
11
12
13
# File 'lib/tvdb_party/search.rb', line 10

def initialize(the_api_key, language = 'en')
  @api_key = the_api_key
  @language = language
end

Instance Attribute Details

#languageObject

Returns the value of attribute language.



5
6
7
# File 'lib/tvdb_party/search.rb', line 5

def language
  @language
end

Instance Method Details

#get_actors(series) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/tvdb_party/search.rb', line 70

def get_actors(series)
  response = self.class.get("/#{@api_key}/series/#{series.id}/actors.xml").parsed_response
  if response["Actors"] && response["Actors"]["Actor"]
    response["Actors"]["Actor"].collect {|a| Actor.new(a)}
  else
    nil
  end
end

#get_all_episodes(series, language = self.language) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/tvdb_party/search.rb', line 57

def get_all_episodes(series, language = self.language)
  response = self.class.get("/#{@api_key}/series/#{series.id}/all/#{language}.xml").parsed_response
  return [] unless response["Data"] && response["Data"]["Episode"]
  case response["Data"]["Episode"]
  when Array
    response["Data"]["Episode"].map{|result| Episode.new(self, result)}
  when Hash
    [Episode.new(response["Data"]["Episode"])]
  else
    []
  end
end

#get_banners(series) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/tvdb_party/search.rb', line 79

def get_banners(series)
  response = self.class.get("/#{@api_key}/series/#{series.id}/banners.xml").parsed_response
  return [] unless response["Banners"] && response["Banners"]["Banner"]
  case response["Banners"]["Banner"]
  when Array
    response["Banners"]["Banner"].map{|result| Banner.new(result)}
  when Hash
    [Banner.new(response["Banners"]["Banner"])]
  else
    []
  end
end

#get_episode(series, season_number, episode_number, language = self.language) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/tvdb_party/search.rb', line 48

def get_episode(series, season_number, episode_number, language = self.language)
  response = self.class.get("/#{@api_key}/series/#{series.id}/default/#{season_number}/#{episode_number}/#{language}.xml").parsed_response
  if response["Data"] && response["Data"]["Episode"]
    Episode.new(self, response["Data"]["Episode"])
  else
    nil
  end
end

#get_episode_by_id(episode_id, language = self.language) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/tvdb_party/search.rb', line 39

def get_episode_by_id(episode_id, language = self.language)
  response = self.class.get("/#{@api_key}/episodes/#{episode_id}/#{language}.xml").parsed_response
  if response["Data"] && response["Data"]["Episode"]
    Episode.new(self, response["Data"]["Episode"])
  else
    nil
  end
end

#get_series_by_id(series_id, language = self.language) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/tvdb_party/search.rb', line 29

def get_series_by_id(series_id, language = self.language)
  response = self.class.get("/#{@api_key}/series/#{series_id}/#{language}.xml").parsed_response

  if response["Data"] && response["Data"]["Series"]
    Series.new(self, response["Data"]["Series"])
  else
    nil
  end
end

#search(series_name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tvdb_party/search.rb', line 15

def search(series_name)
  response = self.class.get("/GetSeries.php", {:query => {:seriesname => series_name, :language => @language}}).parsed_response
  return [] unless response["Data"]

  case response["Data"]["Series"]
  when Array
    response["Data"]["Series"]
  when Hash
    [response["Data"]["Series"]]
  else
    []
  end
end