tvdb_party 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rubygems'
2
+ require 'rake/dsl_definition'
2
3
  require 'rake'
3
4
 
4
5
  begin
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.6.1
@@ -1,8 +1,10 @@
1
1
  module TvdbParty
2
2
  class Episode
3
+ attr_reader :client
3
4
  attr_accessor :id, :season_number, :number, :name, :overview, :air_date, :thumb, :guest_stars, :director, :writer
4
-
5
- def initialize(options={})
5
+
6
+ def initialize(client, options={})
7
+ @client = client
6
8
  @id = options["id"]
7
9
  @season_number = options["SeasonNumber"]
8
10
  @number = options["EpisodeNumber"]
@@ -11,7 +13,7 @@ module TvdbParty
11
13
  @thumb = "http://thetvdb.com/banners/" + options["filename"] if options["filename"].to_s != ""
12
14
  @director = options["Director"]
13
15
  @writer = options["Writer"]
14
-
16
+ @series_id = options["seriesid"]
15
17
  if options["GuestStars"]
16
18
  @guest_stars = options["GuestStars"][1..-1].split("|")
17
19
  else
@@ -24,5 +26,9 @@ module TvdbParty
24
26
  puts 'invalid date'
25
27
  end
26
28
  end
29
+
30
+ def series
31
+ client.get_series_by_id(@series_id)
32
+ end
27
33
  end
28
34
  end
@@ -207,11 +207,11 @@ module HTTParty #:nodoc:
207
207
  end
208
208
  def set(key, value)
209
209
  Cache.logger.info("Cache: set (#{key})")
210
- File.open( @path.join(key), 'w' ) { |file| file << Marshal.dump(value) }
210
+ File.open( @path.join(key), 'w' ) { |file| Marshal.dump(value, file) }
211
211
  true
212
212
  end
213
213
  def get(key)
214
- data = Marshal.load(File.read( @path.join(key)))
214
+ data = Marshal.load(File.new(@path.join(key)))
215
215
  Cache.logger.info("Cache: #{data.nil? ? "miss" : "hit"} (#{key})")
216
216
  data
217
217
  end
@@ -4,18 +4,18 @@ module TvdbParty
4
4
  include HTTParty::Icebox
5
5
  attr_accessor :language
6
6
  cache :store => 'file', :timeout => 120, :location => Dir.tmpdir
7
-
7
+
8
8
  base_uri 'www.thetvdb.com/api'
9
9
 
10
10
  def initialize(the_api_key, language = 'en')
11
11
  @api_key = the_api_key
12
12
  @language = language
13
13
  end
14
-
14
+
15
15
  def search(series_name)
16
16
  response = self.class.get("/GetSeries.php", {:query => {:seriesname => series_name, :language => @language}}).parsed_response
17
17
  return [] unless response["Data"]
18
-
18
+
19
19
  case response["Data"]["Series"]
20
20
  when Array
21
21
  response["Data"]["Series"]
@@ -28,22 +28,45 @@ module TvdbParty
28
28
 
29
29
  def get_series_by_id(series_id, language = self.language)
30
30
  response = self.class.get("/#{@api_key}/series/#{series_id}/#{language}.xml").parsed_response
31
+
31
32
  if response["Data"] && response["Data"]["Series"]
32
33
  Series.new(self, response["Data"]["Series"])
33
34
  else
34
35
  nil
35
36
  end
36
37
  end
38
+
39
+ def get_episode_by_id(episode_id, language = self.language)
40
+ response = self.class.get("/#{@api_key}/episodes/#{episode_id}/#{language}.xml").parsed_response
41
+ if response["Data"] && response["Data"]["Episode"]
42
+ Episode.new(self, response["Data"]["Episode"])
43
+ else
44
+ nil
45
+ end
46
+ end
37
47
 
38
48
  def get_episode(series, season_number, episode_number, language = self.language)
39
49
  response = self.class.get("/#{@api_key}/series/#{series.id}/default/#{season_number}/#{episode_number}/#{language}.xml").parsed_response
40
50
  if response["Data"] && response["Data"]["Episode"]
41
- Episode.new(response["Data"]["Episode"])
51
+ Episode.new(self, response["Data"]["Episode"])
42
52
  else
43
53
  nil
44
54
  end
45
55
  end
46
56
 
57
+ def get_all_episodes(series, language = self.language)
58
+ response = self.class.get("/#{@api_key}/series/#{series.id}/all/#{language}.xml").parsed_response
59
+ return [] unless response["Data"] && response["Data"]["Episode"]
60
+ case response["Data"]["Episode"]
61
+ when Array
62
+ response["Data"]["Episode"].map{|result| Episode.new(result)}
63
+ when Hash
64
+ [Episode.new(response["Data"]["Episode"])]
65
+ else
66
+ []
67
+ end
68
+ end
69
+
47
70
  def get_actors(series)
48
71
  response = self.class.get("/#{@api_key}/series/#{series.id}/actors.xml").parsed_response
49
72
  if response["Actors"] && response["Actors"]["Actor"]
@@ -2,40 +2,40 @@ module TvdbParty
2
2
  class Series
3
3
  attr_reader :client
4
4
  attr_accessor :id, :name, :overview, :seasons, :first_aired, :genres, :network, :rating, :runtime,
5
- :actors, :banners
6
-
5
+ :actors, :banners, :air_time
6
+
7
7
  def initialize(client, options={})
8
8
  @client = client
9
-
10
9
  @id = options["id"]
11
10
  @name = options["SeriesName"]
12
11
  @overview = options["Overview"]
13
12
  @network = options["Network"]
14
13
  @runtime = options["Runtime"]
15
-
14
+ @air_time = options['Airs_Time'] if options['Airs_Time']
15
+
16
16
  if options["Genre"]
17
17
  @genres = options["Genre"][1..-1].split("|")
18
18
  else
19
19
  @genres = []
20
20
  end
21
-
21
+
22
22
  if options["Rating"] && options["Rating"].size > 0
23
23
  @rating = options["Rating"].to_f
24
24
  else
25
25
  @rating = 0
26
26
  end
27
-
28
- begin
27
+
28
+ begin
29
29
  @first_aired = Date.parse(options["FirstAired"])
30
30
  rescue
31
31
  puts 'invalid date'
32
32
  end
33
33
  end
34
-
34
+
35
35
  def get_episode(season_number, episode_number)
36
36
  client.get_episode(self, season_number, episode_number)
37
37
  end
38
-
38
+
39
39
  def posters(language)
40
40
  banners.select{|b| b.banner_type == 'poster' && b.language == language}
41
41
  end
@@ -55,22 +55,26 @@ module TvdbParty
55
55
  def seasonwide_posters(season_number, language)
56
56
  banners.select{|b| b.banner_type == 'season' && b.banner_type2 == 'seasonwide' && b.season == season_number.to_s && b.language == language}
57
57
  end
58
-
58
+
59
59
  def banners
60
- @banners ||= client.get_banners(self)
60
+ @banners ||= client.get_banners(self)
61
61
  end
62
62
 
63
63
  def seasons
64
- @seasons ||= client.get_seasons(self)
64
+ @seasons ||= client.get_seasons(self)
65
+ end
66
+
67
+ def episodes
68
+ @episodes ||= client.get_all_episodes(self)
65
69
  end
66
70
 
67
71
  def actors
68
- @actors ||= client.get_actors(self)
72
+ @actors ||= client.get_actors(self)
69
73
  end
70
-
74
+
71
75
  def season(season_number)
72
76
  seasons.detect{|s| s.number == season_number}
73
77
  end
74
-
78
+
75
79
  end
76
80
  end
data/tvdb_party.gemspec CHANGED
@@ -1,48 +1,42 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tvdb_party}
8
- s.version = "0.6.0"
8
+ s.version = "0.6.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jon Maddox"]
12
- s.date = %q{2010-11-19}
12
+ s.date = %q{2011-10-11}
13
13
  s.description = %q{Simple Ruby library to talk to thetvdb.com's api}
14
14
  s.email = %q{jon@mustacheinc.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.textile"
17
+ "README.textile"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.textile",
24
- "Rakefile",
25
- "VERSION",
26
- "lib/tvdb_party.rb",
27
- "lib/tvdb_party/actor.rb",
28
- "lib/tvdb_party/banner.rb",
29
- "lib/tvdb_party/episode.rb",
30
- "lib/tvdb_party/httparty_icebox.rb",
31
- "lib/tvdb_party/search.rb",
32
- "lib/tvdb_party/series.rb",
33
- "test/test_helper.rb",
34
- "test/tvdb_party_test.rb",
35
- "tvdb_party.gemspec"
21
+ "LICENSE",
22
+ "README.textile",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/tvdb_party.rb",
26
+ "lib/tvdb_party/actor.rb",
27
+ "lib/tvdb_party/banner.rb",
28
+ "lib/tvdb_party/episode.rb",
29
+ "lib/tvdb_party/httparty_icebox.rb",
30
+ "lib/tvdb_party/search.rb",
31
+ "lib/tvdb_party/series.rb",
32
+ "test/test_helper.rb",
33
+ "test/tvdb_party_test.rb",
34
+ "tvdb_party.gemspec"
36
35
  ]
37
36
  s.homepage = %q{http://github.com/maddox/tvdb_party}
38
- s.rdoc_options = ["--charset=UTF-8"]
39
37
  s.require_paths = ["lib"]
40
38
  s.rubygems_version = %q{1.3.7}
41
39
  s.summary = %q{Simple Ruby library to talk to thetvdb.com's api}
42
- s.test_files = [
43
- "test/test_helper.rb",
44
- "test/tvdb_party_test.rb"
45
- ]
46
40
 
47
41
  if s.respond_to? :specification_version then
48
42
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -60,3 +54,4 @@ Gem::Specification.new do |s|
60
54
  s.add_dependency(%q<httparty>, [">= 0.6.1"])
61
55
  end
62
56
  end
57
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tvdb_party
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 0
10
- version: 0.6.0
9
+ - 1
10
+ version: 0.6.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jon Maddox
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-19 00:00:00 -05:00
18
+ date: 2011-10-11 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -59,7 +59,6 @@ extra_rdoc_files:
59
59
  - README.textile
60
60
  files:
61
61
  - .document
62
- - .gitignore
63
62
  - LICENSE
64
63
  - README.textile
65
64
  - Rakefile
@@ -79,8 +78,8 @@ homepage: http://github.com/maddox/tvdb_party
79
78
  licenses: []
80
79
 
81
80
  post_install_message:
82
- rdoc_options:
83
- - --charset=UTF-8
81
+ rdoc_options: []
82
+
84
83
  require_paths:
85
84
  - lib
86
85
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -108,6 +107,5 @@ rubygems_version: 1.3.7
108
107
  signing_key:
109
108
  specification_version: 3
110
109
  summary: Simple Ruby library to talk to thetvdb.com's api
111
- test_files:
112
- - test/test_helper.rb
113
- - test/tvdb_party_test.rb
110
+ test_files: []
111
+
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- *.sw?
2
- .DS_Store
3
- coverage
4
- rdoc
5
- pkg