the_tvdb 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ # uncomment this line if your project needs to run something other than `rake`:
5
+ # script: bundle exec rspec spec
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # TheTvdb
2
2
 
3
+ [![Build Status](https://travis-ci.org/freego/the_tvdb.png?branch=master)](https://travis-ci.org/freego/the_tvdb)
4
+
3
5
  Ruby wrapper for [TheTVDB.com](http://thetvdb.com/).
4
6
 
5
7
  ## Installation
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ task :default => :spec
5
+ RSpec::Core::RakeTask.new
@@ -1,9 +1,9 @@
1
1
  module TheTvdb
2
2
  class Episode
3
-
3
+
4
4
  attr_accessor :remote_id, :season_remote_id, :season_number, :name, :number, :aired_at, :description,
5
5
  :guest_stars, :director, :writer, :updated_at, :dvd_disc, :dvd_season, :dvd_episode_number, :dvd_chapter,
6
- :absolute_number, :image_url, :imdb_id, :language, :production_code
6
+ :absolute_number, :image_url, :imdb_id, :language, :production_code, :rating, :rating_count
7
7
 
8
8
  def initialize(info)
9
9
  @remote_id = info['id'].to_i
@@ -13,9 +13,9 @@ module TheTvdb
13
13
  @number = info['EpisodeNumber'].to_i
14
14
  @aired_at = info['FirstAired']
15
15
  @description = info['Overview']
16
- @guest_stars = info['GuestStars']
17
- @director = info['Director']
18
- @writer = info['Writer']
16
+ @guest_stars = info['GuestStars'].try(:to_tvdb_array)
17
+ @director = info['Director'].try(:to_tvdb_array)
18
+ @writer = info['Writer'].try(:to_tvdb_array)
19
19
  @updated_at = Time.at(info['lastupdated'].to_i)
20
20
  @dvd_disc = info['DVD_discid']
21
21
  @dvd_season = info['DVD_season']
@@ -26,13 +26,15 @@ module TheTvdb
26
26
  @imdb_id = info['IMDB_ID']
27
27
  @language = info['Language']
28
28
  @prodiction_code = info['ProductionCode']
29
+ @rating = info['Rating'].try(:to_f)
30
+ @rating_count = info['RatingCount'].try(:to_i)
29
31
  end
30
-
32
+
31
33
  def self.find(remote_id)
32
34
  info = TheTvdb.gateway.get_episode_details(remote_id)
33
35
  self.new(info)
34
36
  end
35
-
37
+
36
38
  def to_hash
37
39
  {
38
40
  remote_id: @remote_id,
@@ -54,7 +56,9 @@ module TheTvdb
54
56
  image_url: @image_url,
55
57
  imdb_id: @imdb_id,
56
58
  language: @language,
57
- production_code: @production_code
59
+ production_code: @production_code,
60
+ rating: @rating,
61
+ rating_count: @rating_count
58
62
  }
59
63
  end
60
64
 
data/lib/the_tvdb/show.rb CHANGED
@@ -1,12 +1,14 @@
1
1
  module TheTvdb
2
2
  class Show
3
-
3
+
4
4
  attr_accessor :remote_id, :name, :banner, :description, :episodes,
5
- :first_aired, :imdb_id, :zap2it_id, :language
6
-
5
+ :first_aired, :imdb_id, :zap2it_id, :language, :actors, :airs_day_of_week,
6
+ :airs_time, :content_rating, :genre, :network, :runtime, :fanart,
7
+ :rating, :rating_count, :status, :added_at, :last_updated, :poster
8
+
7
9
  def self.search(name)
8
10
  shows = TheTvdb.gateway.get_series(name)
9
- shows.map {|s| self.new(s) }
11
+ shows.map {|s| self.new(s, true) }
10
12
  end
11
13
 
12
14
  def self.find(remote_id)
@@ -16,7 +18,7 @@ module TheTvdb
16
18
  show
17
19
  end
18
20
 
19
- def initialize(info)
21
+ def initialize(info, partial=false)
20
22
  @remote_id = info['id'].to_i
21
23
  @name = info['SeriesName']
22
24
  @banner = "#{TheTvdb.gateway.mirror}/banners/#{info['banner']}" unless info['banner'].nil?
@@ -25,9 +27,27 @@ module TheTvdb
25
27
  @zap2it_id = info['zap2it_id']
26
28
  @first_aired = info['FirstAired']
27
29
  @language = info['language']
28
- @episodes = []
30
+
31
+ unless partial
32
+ @episodes = []
33
+ @actors = info['Actors'].try(:to_tvdb_array)
34
+ @airs_day_of_week = info['Airs_DayOfWeek']
35
+ @airs_time = info['Airs_Time']
36
+ @content_rating = info['ContentRating']
37
+ @genre = info['Genre'].try(:to_tvdb_array)
38
+ @network = info['Network']
39
+ @runtime = info['Runtime'].try(:to_i)
40
+ @fanart = "#{TheTvdb.gateway.mirror}/banners/#{info['fanart']}" unless info['fanart'].nil?
41
+ @rating = info['Rating'].try(:to_f)
42
+ @rating_count = info['RatingCount'].try(:to_i)
43
+ @status = info['Status']
44
+ @added_at = info['added']
45
+ @last_updated = info['lastupdated']
46
+ @poster = "#{TheTvdb.gateway.mirror}/banners/#{info['poster']}" unless info['poster'].nil?
47
+ end
48
+
29
49
  end
30
-
50
+
31
51
  def to_hash
32
52
  {
33
53
  remote_id: @remote_id,
@@ -37,9 +57,23 @@ module TheTvdb
37
57
  first_aired: @first_aired,
38
58
  imdb_id: @imdb_id,
39
59
  zap2it_id: @zap2it_id,
40
- language: @language
60
+ language: @language,
61
+ actors: @actors,
62
+ airs_day_of_week: @airs_day_of_week,
63
+ airs_time: @airs_time,
64
+ content_rating: @content_rating,
65
+ genre: @genre,
66
+ network: @network,
67
+ runtime: @runtime,
68
+ fanart: @fanart,
69
+ rating: @rating,
70
+ rating_count: @rating_count,
71
+ status: @status,
72
+ added_at: @added_at,
73
+ last_updated: @last_updated,
74
+ poster: @poster
41
75
  }
42
76
  end
43
77
 
44
78
  end
45
- end
79
+ end
@@ -1,3 +1,3 @@
1
1
  module TheTvdb
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/the_tvdb.rb CHANGED
@@ -32,3 +32,9 @@ module TheTvdb
32
32
  end
33
33
 
34
34
  end
35
+
36
+ class String
37
+ def to_tvdb_array
38
+ gsub(/^\|/, '').split('|')
39
+ end
40
+ end
@@ -26,8 +26,8 @@ describe TheTvdb::Episode do
26
26
  episode.description.should == "Tyrion and the Lannisters fight for their lives as Stannis’ fleet assaults King’s Landing."
27
27
  episode.season_remote_id.should == 473271
28
28
  episode.guest_stars.should be_nil
29
- episode.director.should == 'Neil Marshall'
30
- episode.writer.should == 'George R. R. Martin'
29
+ episode.director.should == [ 'Neil Marshall' ]
30
+ episode.writer.should == [ 'George R. R. Martin' ]
31
31
  episode.updated_at.should == Time.at(1352849383)
32
32
  # episode.flagged.should == '0'
33
33
  episode.dvd_disc.should be_nil
@@ -39,6 +39,9 @@ describe TheTvdb::Episode do
39
39
  episode.imdb_id.should == 'tt2084342'
40
40
  episode.language.should == 'en'
41
41
  episode.production_code.should be_nil
42
+ episode.rating.should == 8.4
43
+ # RatingCount is not included in the detail data, just in the series package
44
+ # episode.rating_count.should == 282
42
45
  end
43
46
 
44
47
  end
@@ -38,13 +38,44 @@ describe TheTvdb::Show do
38
38
  end
39
39
 
40
40
  describe ".find" do
41
+
42
+ context "Game of Thrones" do
43
+
44
+ let(:show) { TheTvdb::Show.find(121361) }
45
+ let(:episode) { show.episodes[24] }
46
+
47
+ it "should return advanced information if available" do
48
+ show.name.should == 'Game of Thrones'
49
+ show.airs_day_of_week.should == "Sunday"
50
+ show.airs_time.should == "9:00 PM"
51
+ show.content_rating.should == 'TV-MA'
52
+ show.genre.should == [ 'Action and Adventure', 'Drama', 'Fantasy' ]
53
+ show.network.should == 'HBO'
54
+ show.runtime.should == 60
55
+ show.fanart.should == 'http://thetvdb.com/banners/fanart/original/121361-15.jpg'
56
+ show.rating.should == 9.4
57
+ show.rating_count.should == 411
58
+ show.status.should == 'Continuing'
59
+ show.added_at.should == '2009-10-26 16:51:46'
60
+ show.last_updated.should == '1355962803'
61
+ show.poster.should == 'http://thetvdb.com/banners/posters/121361-4.jpg'
62
+ end
41
63
 
42
- let(:show) { TheTvdb::Show.find(121361) }
43
- let(:episode) { show.episodes[24] }
64
+ it "should return an array of actors" do
65
+ show.actors.should include('Peter Dinklage')
66
+ show.should have(46).actors
67
+ end
44
68
 
45
- it "should return info and episodes when looking up a show id" do
46
- show.should have(27).episodes
47
- episode.name.should == 'Blackwater'
69
+ it "should return info and episodes when looking up a show id" do
70
+ show.should have(27).episodes
71
+ episode.name.should == 'Blackwater'
72
+ end
73
+
74
+ it "should return an array of episodes even if there is just one episode" do
75
+ one_episode_show = TheTvdb::Show.find(77856)
76
+ one_episode_show.episodes.size.should == 1
77
+ end
78
+
48
79
  end
49
80
 
50
81
  it "should return an array of episodes even if there is just one episode" do
@@ -55,4 +86,4 @@ describe TheTvdb::Show do
55
86
 
56
87
  end
57
88
 
58
- end
89
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_tvdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-28 00:00:00.000000000 Z
12
+ date: 2012-12-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -67,6 +67,7 @@ extensions: []
67
67
  extra_rdoc_files: []
68
68
  files:
69
69
  - .gitignore
70
+ - .travis.yml
70
71
  - Gemfile
71
72
  - LICENSE.txt
72
73
  - README.md