Class: P3::Tvdb::Search

Inherits:
Object
  • Object
show all
Includes:
HTTParty, HTTParty::Icebox
Defined in:
lib/p3-tvdb/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.



10
11
12
13
14
15
16
17
18
# File 'lib/p3-tvdb/search.rb', line 10

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.



6
7
8
# File 'lib/p3-tvdb/search.rb', line 6

def language
  @language
end

Instance Method Details

#get_actors(series) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/p3-tvdb/search.rb', line 75

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



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/p3-tvdb/search.rb', line 62

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



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/p3-tvdb/search.rb', line 84

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



53
54
55
56
57
58
59
60
# File 'lib/p3-tvdb/search.rb', line 53

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



44
45
46
47
48
49
50
51
# File 'lib/p3-tvdb/search.rb', line 44

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



34
35
36
37
38
39
40
41
42
# File 'lib/p3-tvdb/search.rb', line 34

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



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/p3-tvdb/search.rb', line 20

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