tv-data-api-clients 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/Rakefile +11 -0
- data/lib/base.rb +2 -0
- data/lib/base/api/episode.rb +104 -0
- data/lib/base/api/show.rb +132 -0
- data/lib/core_ext/object.rb +15 -0
- data/lib/helpers.rb +22 -0
- data/lib/the_tv_db.rb +23 -0
- data/lib/the_tv_db/api/episode.rb +56 -0
- data/lib/the_tv_db/api/episode_list.rb +28 -0
- data/lib/the_tv_db/api/image.rb +114 -0
- data/lib/the_tv_db/api/image_list.rb +35 -0
- data/lib/the_tv_db/api/image_list_helpers.rb +32 -0
- data/lib/the_tv_db/api/mirror.rb +13 -0
- data/lib/the_tv_db/api/mirrors.rb +11 -0
- data/lib/the_tv_db/api/show.rb +125 -0
- data/lib/the_tv_db/configuration.rb +7 -0
- data/lib/tv_data_api_clients.rb +12 -0
- data/lib/tv_data_api_clients/version.rb +3 -0
- data/lib/tv_rage.rb +7 -0
- data/lib/tv_rage/show.rb +81 -0
- data/test/fixtures/example.gif +0 -0
- data/test/fixtures/the_tv_db/api_get_series_lost.xml +24 -0
- data/test/fixtures/the_tv_db/api_series_12345_all_en.xml +9 -0
- data/test/fixtures/the_tv_db/api_series_73739_banners.xml +157 -0
- data/test/fixtures/the_tv_db/api_series_73739_en.xml +30 -0
- data/test/fixtures/tv_rage/feeds_search_show.xml +11 -0
- data/test/fixtures/tv_rage/feeds_showinfo_sid_7926.xml +28 -0
- data/test/support/shared_episode_naming_tests.rb +90 -0
- data/test/support/shared_show_naming_tests.rb +29 -0
- data/test/test_helper.rb +28 -0
- data/test/unit/base/api/episode_test.rb +11 -0
- data/test/unit/base/api/show_test.rb +11 -0
- data/test/unit/the_tv_db/api/episode_list_test.rb +15 -0
- data/test/unit/the_tv_db/api/episode_test.rb +93 -0
- data/test/unit/the_tv_db/api/image_list_test.rb +42 -0
- data/test/unit/the_tv_db/api/image_test.rb +35 -0
- data/test/unit/the_tv_db/api/mirrors_test.rb +17 -0
- data/test/unit/the_tv_db/api/show_test.rb +57 -0
- data/test/unit/the_tv_db/configuration_test.rb +28 -0
- data/test/unit/tv_rage/show_test.rb +55 -0
- data/tv-data-api-clients.gemspec +29 -0
- metadata +238 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
2
|
+
<Data>
|
3
|
+
<Series>
|
4
|
+
<id>73739</id>
|
5
|
+
<Actors>|Matthew Fox|Terry O'Quinn|Evangeline Lilly|Naveen Andrews|</Actors>
|
6
|
+
<Airs_DayOfWeek>Tuesday</Airs_DayOfWeek>
|
7
|
+
<Airs_Time>9:00 PM</Airs_Time>
|
8
|
+
<ContentRating>TV-14</ContentRating>
|
9
|
+
<FirstAired>2004-09-22</FirstAired>
|
10
|
+
<Genre>|Action and Adventure|Drama|Science-Fiction|</Genre>
|
11
|
+
<IMDB_ID>tt0411008</IMDB_ID>
|
12
|
+
<Language>en</Language>
|
13
|
+
<Network>ABC</Network>
|
14
|
+
<NetworkID></NetworkID>
|
15
|
+
<Overview>After their plane, Oceanic Air flight 815, tore apart whilst thousands of miles off course, the survivors find themselves on a mysterious deserted island where they soon find out they are not alone.</Overview>
|
16
|
+
<Rating>9.1</Rating>
|
17
|
+
<RatingCount>548</RatingCount>
|
18
|
+
<Runtime>60</Runtime>
|
19
|
+
<SeriesID>24313</SeriesID>
|
20
|
+
<SeriesName>Lost</SeriesName>
|
21
|
+
<Status>Ended</Status>
|
22
|
+
<added></added>
|
23
|
+
<addedBy></addedBy>
|
24
|
+
<banner>graphical/73739-g4.jpg</banner>
|
25
|
+
<fanart>fanart/original/73739-34.jpg</fanart>
|
26
|
+
<lastupdated>1302842432</lastupdated>
|
27
|
+
<poster>posters/73739-7.jpg</poster>
|
28
|
+
<zap2it_id>SH672362</zap2it_id>
|
29
|
+
</Series>
|
30
|
+
</Data>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
2
|
+
<Showinfo>
|
3
|
+
<showid>7926</showid>
|
4
|
+
<showname>Dexter</showname>
|
5
|
+
<showlink>http://tvrage.com/Dexter</showlink>
|
6
|
+
<started>2006</started>
|
7
|
+
<startdate>Oct/01/2006</startdate>
|
8
|
+
<ended></ended>
|
9
|
+
<origin_country>US</origin_country>
|
10
|
+
<status>Returning Series</status>
|
11
|
+
<classification>Scripted</classification>
|
12
|
+
<genres>
|
13
|
+
<genre>Crime</genre>
|
14
|
+
<genre>Drama</genre>
|
15
|
+
</genres>
|
16
|
+
<runtime>60</runtime>
|
17
|
+
<network country="US">Showtime</network>
|
18
|
+
<airtime>21:00</airtime>
|
19
|
+
<airday>Sunday</airday>
|
20
|
+
<timezone>GMT-5 +DST</timezone>
|
21
|
+
<akas>
|
22
|
+
<aka attr="Book">Darkly Dreaming Dexter</aka>
|
23
|
+
<aka country="LT">Deksteris</aka>
|
24
|
+
<aka country="LV">Deksters</aka>
|
25
|
+
<aka country="BG">Декстър</aka>
|
26
|
+
<aka country="IL">דקסטר</aka>
|
27
|
+
</akas>
|
28
|
+
</Showinfo>
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module SharedEpisodeNamingTests
|
2
|
+
|
3
|
+
def test_should_not_allow_season_x_or_episode_x_titles
|
4
|
+
subject.stubs(:original_name).returns('Season 1')
|
5
|
+
assert subject.name.nil?
|
6
|
+
subject.stubs(:original_name).returns('Episode 1')
|
7
|
+
assert subject.name.nil?
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_should_not_allow_finale_summary_etc_names
|
11
|
+
subject.stubs(:original_name).returns('Series Finale')
|
12
|
+
assert subject.name == 'Series Finale'
|
13
|
+
subject.stubs(:original_name).returns('Season Finale')
|
14
|
+
assert subject.name == 'Season Finale'
|
15
|
+
subject.stubs(:original_name).returns('Episode Summary')
|
16
|
+
assert subject.name == 'Episode Summary'
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_should_not_allow_season_x_with_episode_y_names
|
20
|
+
subject.stubs(:original_name).returns('Season 1, Episode 14')
|
21
|
+
assert subject.name.nil?
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_not_allow_series_x_with_episode_y_names
|
25
|
+
subject.stubs(:original_name).returns('Series 1, Episode 14')
|
26
|
+
assert subject.name.nil?
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_should_not_allow_dates_for_names
|
30
|
+
subject.stubs(:original_name).returns('2001/15/05')
|
31
|
+
assert subject.name.nil?
|
32
|
+
subject.stubs(:original_name).returns('9/7/77')
|
33
|
+
assert subject.name.nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_stripping_quotes_from_names
|
37
|
+
subject.stubs(:original_name).returns('"The Taboja!"')
|
38
|
+
assert_equal 'The Taboja!', subject.name
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_no_info_edge_case_from_one_api
|
42
|
+
subject.stubs(:original_name).returns('no info')
|
43
|
+
assert subject.name.nil?
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_stripping_leading_and_trailing_whitespace_from_names
|
47
|
+
subject.stubs(:original_name).returns(' whee, data entry! ')
|
48
|
+
assert_equal 'whee, data entry!', subject.name
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_not_being_usable_unless_a_number_is_set
|
52
|
+
subject.stubs(:number).returns(nil)
|
53
|
+
assert !subject.usable?
|
54
|
+
subject.stubs(:number).returns(123)
|
55
|
+
assert subject.usable?
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_not_allowing_more_symbols_than_letters_in_names
|
59
|
+
subject.stubs(:original_name).returns('......:::::Coming Soon!::::::......')
|
60
|
+
assert subject.name.nil?
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_stripping_bracketed_digits_from_names
|
64
|
+
subject.stubs(:original_name).returns('Example (15)')
|
65
|
+
assert_equal "Example", subject.name
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_stripping_bracketed_digits_from_names_doesn_t_strip_single_digits
|
69
|
+
subject.stubs(:original_name).returns('Example (2)')
|
70
|
+
assert_equal "Example (2)", subject.name
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_disllowing_e_nubmer_names
|
74
|
+
subject.stubs(:original_name).returns('E1')
|
75
|
+
assert subject.name.nil?
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_not_allowing_s_number_dot_e_number_names
|
79
|
+
subject.stubs(:original_name).returns('S04.E01')
|
80
|
+
assert subject.name.nil?
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def subject
|
86
|
+
mock_xml_node = mock("Nokogiri XML Node Shared Episode Naming Tests")
|
87
|
+
@subject ||= @subject_class.new(mock_xml_node)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module SharedShowNamingTests
|
2
|
+
|
3
|
+
def test_swallowing_the_year_in_show_names
|
4
|
+
subject.stubs(:original_name).returns("Example Show (2005)")
|
5
|
+
assert_equal "Example Show", subject.name
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_swallowing_the_bracketed_year_in_show_names
|
9
|
+
['UK', 'USA'].each do |c|
|
10
|
+
subject.stubs(:original_name).returns("Example Show (#{c})")
|
11
|
+
assert_equal "Example Show", subject.name
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_not_hide_the_country_when_not_bracketed
|
16
|
+
['UK', 'USA'].each do |c|
|
17
|
+
subject.stubs(:original_name).returns("Example Show #{c}")
|
18
|
+
assert_equal "Example Show #{c}", subject.name
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def subject
|
25
|
+
mock_xml_node = mock('Nokogiri XML Node Shared Show Naming Tests')
|
26
|
+
@subject ||= @subject_class.new(mock_xml_node)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
Bundler.setup(:test)
|
4
|
+
|
5
|
+
require 'minitest/unit'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
|
8
|
+
require 'ruby-debug'
|
9
|
+
require 'mocha'
|
10
|
+
require 'webmock'
|
11
|
+
require 'webmock/minitest'
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'turn'
|
15
|
+
rescue LoadError
|
16
|
+
puts "Running without `turn`"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'tv_data_api_clients'
|
20
|
+
|
21
|
+
require 'support/shared_episode_naming_tests'
|
22
|
+
require 'support/shared_show_naming_tests'
|
23
|
+
|
24
|
+
WebMock.disable_net_connect!
|
25
|
+
|
26
|
+
TheTvDb.configure do |config|
|
27
|
+
config.api_key = 'ABCDE12345'
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TheTvDbApiEpisodeListTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
stub_request(:get, "http://thetvdb.com/api/ABCDE12345/series/12345/all/en.xml").
|
7
|
+
to_return(:status => 200, :body => File.read('test/fixtures/the_tv_db/api_series_12345_all_en.xml'))
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_finds_two_episodes_when_looking_for_show_12345
|
11
|
+
TheTvDb::Api::Episode.expects(:new).times(2)
|
12
|
+
TheTvDb::Api::EpisodeList.get_for(12345)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TheTvDbApiEpisodeTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
x = Nokogiri::XML(<<-EOXML)
|
7
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
8
|
+
<Data>
|
9
|
+
<Episode>
|
10
|
+
<id>328099</id>
|
11
|
+
<Combined_episodenumber>1</Combined_episodenumber>
|
12
|
+
<Combined_season>0</Combined_season>
|
13
|
+
<DVD_chapter></DVD_chapter>
|
14
|
+
<DVD_discid></DVD_discid>
|
15
|
+
<DVD_episodenumber></DVD_episodenumber>
|
16
|
+
<DVD_season></DVD_season>
|
17
|
+
<Director>Joss Whedon</Director>
|
18
|
+
<EpImgFlag>2</EpImgFlag>
|
19
|
+
<filename>episodes/73255/110992.jpg</filename>
|
20
|
+
<EpisodeName>Unaired Pilot</EpisodeName>
|
21
|
+
<EpisodeNumber>1</EpisodeNumber>
|
22
|
+
<FirstAired>1995-01-16</FirstAired>
|
23
|
+
<GuestStars>|Riff Regan|Danny Strong|Amy Faith Chance|Persia White|Stephen Tobolowsky|</GuestStars>
|
24
|
+
<IMDB_ID></IMDB_ID>
|
25
|
+
<Language>en</Language>
|
26
|
+
<Overview>Meet Buffy Summers. She's almost the girl next door... if it weren't for that pesky Slayer destiny thing. When Buffy moves to Sunnydale, she just wants to start over and be a normal teenage girl. But when her new friend Willow is lured by vampires into a trap at the school, Buffy instinctively rushes to her friends rescue. And Buffy soon realizes that escaping one's destiny, isn't as easy as she'd hoped.</Overview>
|
27
|
+
<ProductionCode>AV79</ProductionCode>
|
28
|
+
<Rating>7.0</Rating>
|
29
|
+
<RatingCount>1</RatingCount>
|
30
|
+
<SeasonNumber>0</SeasonNumber>
|
31
|
+
<Writer>Joss Whedon</Writer>
|
32
|
+
<absolute_number></absolute_number>
|
33
|
+
<airsafter_season></airsafter_season>
|
34
|
+
<airsbefore_episode>1</airsbefore_episode>
|
35
|
+
<airsbefore_season>1</airsbefore_season>
|
36
|
+
<filename>episodes/70327/328099.jpg</filename>
|
37
|
+
<lastupdated>1277254417</lastupdated>
|
38
|
+
<seasonid>17796</seasonid>
|
39
|
+
<seriesid>70327</seriesid>
|
40
|
+
</Episode>
|
41
|
+
</Data>
|
42
|
+
EOXML
|
43
|
+
@episode = TheTvDb::Api::Episode.new(x.xpath('//Episode').first.remove)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_should_extract_the_network_id
|
47
|
+
assert_equal 328099, @episode.network_id
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_season_number
|
51
|
+
assert_nil @episode.season_number
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_episode_number
|
55
|
+
assert_equal 1, @episode.number
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_name
|
59
|
+
assert_equal "Unaired Pilot", @episode.name
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_first_aired_date
|
63
|
+
assert_equal Date.new(1995, 1, 16), @episode.air_dates.first
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_rating
|
67
|
+
assert_equal 70, @episode.rating
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_number_of_ratings
|
71
|
+
assert_equal 1, @episode.number_of_ratings
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_overview
|
75
|
+
assert_match /Meet Buffy Summers/, @episode.overview
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_banner_path
|
79
|
+
assert_equal 'http://thetvdb.com/banners/episodes/73255/110992.jpg', @episode.banner_path
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_attributes_hash
|
83
|
+
assert_equal @episode.attributes, {
|
84
|
+
:name => "Unaired Pilot",
|
85
|
+
:number => 1,
|
86
|
+
:season_number => nil,
|
87
|
+
:absolute_number => nil
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TheTVDBAPIImageListTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
stub_request(:get, "http://thetvdb.com/api/ABCDE12345/series/73739/banners.xml").
|
7
|
+
to_return(:status => 200, :body => File.read('test/fixtures/the_tv_db/api_series_73739_banners.xml'))
|
8
|
+
@image_list = TheTvDb::Api::ImageList.for(73739)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_should_find_only_english_language_images_in_the_stub
|
12
|
+
assert_equal 10, @image_list.length
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_extract_the_correct_attributes
|
16
|
+
i = @image_list.first
|
17
|
+
assert_equal 23089, i.network_id
|
18
|
+
assert_equal "#{TheTvDb::Api::Mirrors.all.first}/banners/fanart/original/73739-First.jpg", i.path
|
19
|
+
assert_equal :fanart, i.type
|
20
|
+
assert i.sub_type.nil?
|
21
|
+
assert_equal 1920, i.width
|
22
|
+
assert_equal 1080, i.height
|
23
|
+
assert_equal [16, 9], i.aspect
|
24
|
+
assert_equal 6.9, i.rating
|
25
|
+
assert_equal :en, i.language
|
26
|
+
assert i.widescreen?
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_finding_the_highest_pixel_count_image
|
30
|
+
b = @image_list.highest_pixel_count
|
31
|
+
assert_equal 1920, b.width
|
32
|
+
assert_equal 1080, b.height
|
33
|
+
assert_equal "http://thetvdb.com/banners/fanart/original/73739-First.jpg", b.path
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_allowing_convenient_access_to_the_season_banners
|
37
|
+
sbs = @image_list.season_banners
|
38
|
+
assert_equal 4, sbs.length
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TheTvDbApiImageTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
x = Nokogiri::XML(<<-EOXML)
|
7
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
8
|
+
<Banners>
|
9
|
+
<Banner>
|
10
|
+
<id>25884</id>
|
11
|
+
<BannerPath>posters/73739-1.jpg</BannerPath>
|
12
|
+
<BannerType>poster</BannerType>
|
13
|
+
<BannerType2>680x1000</BannerType2>
|
14
|
+
<Language>en</Language>
|
15
|
+
<Rating>7.6429</Rating>
|
16
|
+
<RatingCount>14</RatingCount>
|
17
|
+
</Banner>
|
18
|
+
<Banners>
|
19
|
+
EOXML
|
20
|
+
@image = TheTvDb::Api::Image.new(x.xpath('Banners/Banner').first.remove)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_not_being_widescreen
|
24
|
+
assert !@image.widescreen?
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_extracting_dimensions_from_images
|
28
|
+
@image.stubs(:subtype_looks_like_dimensions?).returns(false)
|
29
|
+
@image.stubs(:path).returns('test/fixtures/example.gif')
|
30
|
+
assert_equal 160, @image.width
|
31
|
+
assert_equal 160, @image.height
|
32
|
+
assert_equal 25600, @image.pixels
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TheTvDbApiMirrorsTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def test_mirrors_are_enumerable
|
6
|
+
assert_respond_to TheTvDb::Api::Mirrors.all, :each
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_one_mirror_extracted_from_xml
|
10
|
+
assert_equal 1, TheTvDb::Api::Mirrors.all.length
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_mirrors_list_returns_an_instance_of_a_mirror
|
14
|
+
assert_kind_of TheTvDb::Api::Mirror, TheTvDb::Api::Mirrors.all.first
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|