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', cache_options = {}) ⇒ Search

Returns a new instance of Search.



9
10
11
12
13
14
15
16
17
# File 'lib/tvdb_party/search.rb', line 9

def initialize(the_api_key, language = 'en', cache_options = {})
  @api_key = the_api_key
  @language = language

  if cache_options.keys.size > 0
    self.class.cache cache_options
  end

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



74
75
76
77
78
79
80
81
# File 'lib/tvdb_party/search.rb', line 74

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



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/tvdb_party/search.rb', line 61

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



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/tvdb_party/search.rb', line 83

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



52
53
54
55
56
57
58
59
# File 'lib/tvdb_party/search.rb', line 52

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



43
44
45
46
47
48
49
50
# File 'lib/tvdb_party/search.rb', line 43

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



33
34
35
36
37
38
39
40
41
# File 'lib/tvdb_party/search.rb', line 33

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



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tvdb_party/search.rb', line 19

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