tvdb_party 0.1.1

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jon Maddox
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,45 @@
1
+ h1. TvdbParty!
2
+
3
+ h2. What?
4
+
5
+ TvdbParty is a simple Ruby library to talk to thetvdb.com database.
6
+
7
+ h2. How?
8
+
9
+ set up the client
10
+ <code>tvdb = TvdbParty::Search.new("YOURAPIKEY")
11
+
12
+ search for your series
13
+ <code>results = tvdb.search('the west wing')</code>
14
+
15
+ get the series
16
+ <code>west_wing = tvdb.get_series_by_id(results["seriesid"])</code>
17
+ <code>puts west_wing.name</code>
18
+ => The West Wing
19
+
20
+ get an episode
21
+ <code>episode_22 = west_wing.get_episode(1, 22)</code>
22
+ <code>puts episode_22.name</code>
23
+ => What Kind of Day Has It Been?
24
+
25
+ get series fanart - pass in your language
26
+ <code>puts west_wing.fanart('en').first.url</code>
27
+ => http://thetvdb.com/banners/fanart/original/72521-2.jpg
28
+
29
+ get series posters
30
+ <code>puts west_wing.posters('en').first.url</code>
31
+ => http://thetvdb.com/banners/posters/72521-1.jpg
32
+
33
+ get series banners
34
+ <code>puts west_wing.series_banners('en').first.url</code>
35
+ => http://thetvdb.com/banners/graphical/189-g.jpg
36
+
37
+ get season posters
38
+ <code>puts west_wing.season_posters(2, 'en').first.url</code>
39
+ => http://thetvdb.com/banners/seasons/72521-2.jpg
40
+
41
+ h2. Thanks
42
+
43
+ Thanks to thetvdb.com for their awesome database allowing us to meta out to our hearts consent.
44
+
45
+ Project name graciously stolen from jduff/tmdb_party.
data/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "tvdb_party"
8
+ gem.summary = %Q{Simple Ruby library to talk to thetvdb.com's api}
9
+ gem.description = %Q{Simple Ruby library to talk to thetvdb.com's api}
10
+ gem.email = "jon@jonsthoughtsoneverything.com"
11
+ gem.homepage = "http://github.com/maddox/tvdb_party"
12
+ gem.authors = ["Jon Maddox"]
13
+ gem.add_development_dependency "thoughtbot-shoulda"
14
+ gem.add_dependency('httparty', '>= 0.4.4')
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/*_test.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/*_test.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ if File.exist?('VERSION')
48
+ version = File.read('VERSION')
49
+ else
50
+ version = ""
51
+ end
52
+
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "tvdb_party #{version}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,17 @@
1
+ module TvdbParty
2
+ class Banner
3
+ attr_accessor :banner_type, :banner_type2, :season, :path, :thumbnail_path, :language
4
+
5
+ def initialize(options={})
6
+ @banner_type = options["BannerType"]
7
+ @banner_type2 = options["BannerType2"]
8
+ @season = options["Season"]
9
+ @path = options["BannerPath"]
10
+ @language = options["Language"]
11
+ end
12
+
13
+ def url
14
+ "http://thetvdb.com/banners/" + @path
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module TvdbParty
2
+ class Episode
3
+ attr_accessor :id, :season_number, :number, :name, :overview, :air_date, :thumb, :guest_stars, :director, :writer
4
+
5
+ def initialize(options={})
6
+ @id = options["id"]
7
+ @season_number = options["SeasonNumber"]
8
+ @number = options["EpisodeNumber"]
9
+ @name = options["EpisodeName"]
10
+ @overview = options["Overview"]
11
+ @air_date = Date.parse(options["FirstAired"]) if options["FirstAired"]
12
+ @thumb = "http://thetvdb.com/banners/" + options["filename"] if options["filename"].to_s != ""
13
+ @guest_stars = options["GuestStars"][1..-1].split("|")
14
+ @director = options["Director"]
15
+ @writer = options["Writer"]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,44 @@
1
+ module TvdbParty
2
+ class Search
3
+ include HTTParty
4
+ base_uri 'www.thetvdb.com/api'
5
+
6
+ def initialize(the_api_key)
7
+ @api_key = the_api_key
8
+ end
9
+
10
+ def search(series_name)
11
+ response = self.class.get("/GetSeries.php", {:query => {:seriesname => series_name}})
12
+ response["Data"]["Series"]
13
+ case response["Data"]["Series"]
14
+ when Array
15
+ response["Data"]["Series"]
16
+ when Hash
17
+ [response["Data"]["Series"]]
18
+ end
19
+ end
20
+
21
+ def get_series_by_id(series_id)
22
+ response = self.class.get("/#{@api_key}/series/#{series_id}/en.xml")
23
+ Series.new(self, response["Data"]["Series"])
24
+ end
25
+
26
+ def get_episode(series, season_number, episode_number)
27
+ response = self.class.get("/#{@api_key}/series/#{series.id}/default/#{season_number}/#{episode_number}/en.xml")
28
+ Episode.new(response["Data"]["Episode"])
29
+ end
30
+
31
+ def get_banners(series)
32
+ response = self.class.get("/#{@api_key}/series/#{series.id}/banners.xml")
33
+ case response["Banners"]["Banner"]
34
+ when Array
35
+ response["Banners"]["Banner"].map{|result| Banner.new(result)}
36
+ when Hash
37
+ [Banner.new(response["Banners"]["Banner"])]
38
+ else
39
+ []
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,64 @@
1
+ module TvdbParty
2
+ class Series
3
+ attr_reader :client
4
+ attr_accessor :id, :name, :overview, :seasons, :first_aired, :genres, :network, :rating, :runtime,
5
+ :actors, :banners
6
+
7
+ def initialize(client, options={})
8
+ @client = client
9
+
10
+ @id = options["id"]
11
+ @name = options["SeriesName"]
12
+ @overview = options["Overview"]
13
+ @network = options["Network"]
14
+ @runtime = options["Runtime"]
15
+ @first_aired = Date.parse(options["FirstAired"])
16
+
17
+ @genres = options["Genre"][1..-1].split("|")
18
+ @actors = options["Actors"][1..-1].split("|")
19
+
20
+ if options["Rating"] && options["Rating"].size > 0
21
+ @rating = options["Rating"].to_f
22
+ else
23
+ @rating = 0
24
+ end
25
+ end
26
+
27
+ def get_episode(season_number, episode_number)
28
+ client.get_episode(self, season_number, episode_number)
29
+ end
30
+
31
+ def posters(language)
32
+ banners.select{|b| b.banner_type == 'poster' && b.language == language}
33
+ end
34
+
35
+ def fanart(language)
36
+ banners.select{|b| b.banner_type == 'fanart' && b.language == language}
37
+ end
38
+
39
+ def series_banners(language)
40
+ banners.select{|b| b.banner_type == 'series' && b.language == language}
41
+ end
42
+
43
+ def season_posters(season_number, language)
44
+ banners.select{|b| b.banner_type == 'season' && b.banner_type2 == 'season' && b.season == season_number.to_s && b.language == language}
45
+ end
46
+
47
+ def seasonwide_posters(season_number, language)
48
+ banners.select{|b| b.banner_type == 'season' && b.banner_type2 == 'seasonwide' && b.season == season_number.to_s && b.language == language}
49
+ end
50
+
51
+ def banners
52
+ @banners ||= client.get_banners(self)
53
+ end
54
+
55
+ def seasons
56
+ @seasons ||= client.get_seasons(self)
57
+ end
58
+
59
+ def season(season_number)
60
+ seasons.detect{|s| s.number == season_number}
61
+ end
62
+
63
+ end
64
+ end
data/lib/tvdb_party.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+
4
+ directory = File.expand_path(File.dirname(__FILE__))
5
+ require File.join(directory, 'tvdb_party', 'search')
6
+ require File.join(directory, 'tvdb_party', 'series')
7
+ require File.join(directory, 'tvdb_party', 'episode')
8
+ require File.join(directory, 'tvdb_party', 'banner')
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'tvdb_party'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class TvdbPartyTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{tvdb_party}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jon Maddox"]
12
+ s.date = %q{2009-09-29}
13
+ s.description = %q{Simple Ruby library to talk to thetvdb.com's api}
14
+ s.email = %q{jon@jonsthoughtsoneverything.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.textile"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.textile",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/tvdb_party.rb",
27
+ "lib/tvdb_party/banner.rb",
28
+ "lib/tvdb_party/episode.rb",
29
+ "lib/tvdb_party/search.rb",
30
+ "lib/tvdb_party/series.rb",
31
+ "test/test_helper.rb",
32
+ "test/tvdb_party_test.rb",
33
+ "tvdb_party.gemspec"
34
+ ]
35
+ s.homepage = %q{http://github.com/maddox/tvdb_party}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.5}
39
+ s.summary = %q{Simple Ruby library to talk to thetvdb.com's api}
40
+ s.test_files = [
41
+ "test/test_helper.rb",
42
+ "test/tvdb_party_test.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
+ s.add_runtime_dependency(%q<httparty>, [">= 0.4.4"])
52
+ else
53
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
+ s.add_dependency(%q<httparty>, [">= 0.4.4"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
58
+ s.add_dependency(%q<httparty>, [">= 0.4.4"])
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tvdb_party
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Jon Maddox
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-29 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: httparty
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.4
34
+ version:
35
+ description: Simple Ruby library to talk to thetvdb.com's api
36
+ email: jon@jonsthoughtsoneverything.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.textile
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.textile
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/tvdb_party.rb
52
+ - lib/tvdb_party/banner.rb
53
+ - lib/tvdb_party/episode.rb
54
+ - lib/tvdb_party/search.rb
55
+ - lib/tvdb_party/series.rb
56
+ - test/test_helper.rb
57
+ - test/tvdb_party_test.rb
58
+ - tvdb_party.gemspec
59
+ has_rdoc: true
60
+ homepage: http://github.com/maddox/tvdb_party
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --charset=UTF-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 1.3.5
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Simple Ruby library to talk to thetvdb.com's api
87
+ test_files:
88
+ - test/test_helper.rb
89
+ - test/tvdb_party_test.rb