flix4r 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +39 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/flix4r.gemspec +75 -0
- data/init.rb +2 -0
- data/lib/flix4r.rb +22 -0
- data/lib/net_flix.rb +36 -0
- data/lib/net_flix/authenticator.rb +78 -0
- data/lib/net_flix/builders/actor_builder.rb +29 -0
- data/lib/net_flix/builders/format_builder.rb +33 -0
- data/lib/net_flix/credentials.rb +41 -0
- data/lib/net_flix/movie.rb +10 -0
- data/lib/net_flix/request.rb +82 -0
- data/lib/net_flix/television.rb +14 -0
- data/lib/net_flix/title.rb +113 -0
- data/lib/valuable.rb +82 -0
- data/test/actor_builder_test.rb +34 -0
- data/test/authenticator_test.rb +69 -0
- data/test/credentials_test.rb +27 -0
- data/test/fixtures/autocomplete.xml +15 -0
- data/test/fixtures/cast.xml +10 -0
- data/test/fixtures/directors.xml +15 -0
- data/test/fixtures/movies.xml +56 -0
- data/test/fixtures/synopsis.xml +3 -0
- data/test/fixtures/titles.xml +69 -0
- data/test/format_builder_test.rb +67 -0
- data/test/movie_test.rb +54 -0
- data/test/request_test.rb +39 -0
- data/test/test_helper.rb +40 -0
- data/test/title_test.rb +59 -0
- metadata +95 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
<?xml version="1.0" standalone="yes"?>
|
2
|
+
|
3
|
+
<people><person><id>http://api.netflix.com/catalog/people/82729</id><name>Roy Scheider</name><bio><![CDATA[Born in Orange, N.J., on Nov. 10, 1932, Roy Scheider shifted his career ambitions from athletics to acting when he began studying drama during his college years. Following a stint in the Air Force, Scheider debuted on stage with the New York Shakespeare Festival in "Romeo and Juliet."<p>Between 1962 and '67, Scheider appeared in the soap operas "The Edge of Night," "Love of Life" and "The Secret Storm." His breakthrough performance came in 1971 with the thriller Klute, succeeded by his Oscar-nominated turn in The French Connection. He made a big splash in the box-office blockbuster Jaws (1975) and its sequel, Jaws 2 (1978).<p>Looking for a change of pace from his tough-cop screen persona, Scheider starred in the musical roman à clef All That Jazz (1979), snagging another Academy Award nod. The actor returned to television in 1993 with the sci-fi series "SeaQuest DSV." He died Feb. 10, 2008.]]></bio><link href="http://api.netflix.com/catalog/people/82729/filmography" rel="http://schemas.netflix.com/catalog/titles.filmography" title="filmography"></link><link href="http://www.netflix.com/RoleDisplay/Roy_Scheider/82729" rel="alternate" title="web page"></link></person>
|
4
|
+
<person><id>http://api.netflix.com/catalog/people/25823</id><name>Richard Dreyfuss</name><bio><![CDATA[Born in Brooklyn, N.Y., on October 29, 1947, Richard Dreyfuss did extensive theatre work before breaking into small television roles. In 1967, he made his film debut with bit parts in The Graduate and Valley of the Dolls, and a major role in The Young Runaways (1968) followed. But his breakthrough role wouldn't come until 1973, when he portrayed sensitive high school graduate Curt Henderson in the nostalgia hit American Graffiti.<p>Next came roles in back-to-back mega-hits for Steven Spielberg -- Jaws and Close Encounters of the Third Kind. Dreyfuss also was memorable as fidgety actor Elliot Garfield in The Goodbye Girl, a role that made him one of the youngest Best Actor Oscar winners in history. He was nominated again for Mr. Holland's Opus (1995).<p>Dreyfuss's other films include Down and Out in Beverly Hills, Stakeout, What About Bob?, Krippendorf's Tribe and Silver City. ]]></bio><link href="http://api.netflix.com/catalog/people/25823/filmography" rel="http://schemas.netflix.com/catalog/titles.filmography" title="filmography"></link><link href="http://www.netflix.com/RoleDisplay/Richard_Dreyfuss/25823" rel="alternate" title="web page"></link></person>
|
5
|
+
<person><id>http://api.netflix.com/catalog/people/20000031</id><name>Robert Shaw</name><link href="http://api.netflix.com/catalog/people/20000031/filmography" rel="http://schemas.netflix.com/catalog/titles.filmography" title="filmography"></link><link href="http://www.netflix.com/RoleDisplay/Robert_Shaw/20000031" rel="alternate" title="web page"></link></person>
|
6
|
+
<person><id>http://api.netflix.com/catalog/people/33466</id><name>Lorraine Gary</name><link href="http://api.netflix.com/catalog/people/33466/filmography" rel="http://schemas.netflix.com/catalog/titles.filmography" title="filmography"></link><link href="http://www.netflix.com/RoleDisplay/Lorraine_Gary/33466" rel="alternate" title="web page"></link></person>
|
7
|
+
<person><id>http://api.netflix.com/catalog/people/36048</id><name>Carl Gottlieb</name><link href="http://api.netflix.com/catalog/people/36048/filmography" rel="http://schemas.netflix.com/catalog/titles.filmography" title="filmography"></link><link href="http://www.netflix.com/RoleDisplay/Carl_Gottlieb/36048" rel="alternate" title="web page"></link></person>
|
8
|
+
<person><id>http://api.netflix.com/catalog/people/20008412</id><name>Jeffrey Kramer</name><link href="http://api.netflix.com/catalog/people/20008412/filmography" rel="http://schemas.netflix.com/catalog/titles.filmography" title="filmography"></link><link href="http://www.netflix.com/RoleDisplay/Jeffrey_Kramer/20008412" rel="alternate" title="web page"></link></person>
|
9
|
+
<person><id>http://api.netflix.com/catalog/people/20008413</id><name>Susan Backlinie</name><link href="http://api.netflix.com/catalog/people/20008413/filmography" rel="http://schemas.netflix.com/catalog/titles.filmography" title="filmography"></link><link href="http://www.netflix.com/RoleDisplay/Susan_Backlinie/20008413" rel="alternate" title="web page"></link></person>
|
10
|
+
</people>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<?xml version="1.0" standalone="yes"?>
|
2
|
+
<people>
|
3
|
+
<person>
|
4
|
+
<id>http://api.netflix.com/catalog/people/87835</id>
|
5
|
+
<name>Steven Spielberg</name>
|
6
|
+
<bio>
|
7
|
+
<![CDATA[One of the most successful filmmakers in history, Steven Spielberg was born December 18, 1946, in Cincinnati, Ohio. He made 8mm home movies during his youth and spent many years directing for television after dropping out of college.<p>His 1971 television movie Duel hinted at the suspense level of later films such as Jaws (1975), but Close Encounters of the Third Kind (1977) earned him his first Oscar nomination for directing. Although films such as the Indiana Jones trilogy and E.T.: The Extra-Terrestrial (1982) were hits with audiences, it wasn't until The Color Purple (1985) that he tackled more serious subjects.<p>In 1993, Spielberg directed the Holocaust drama Schindler's List, for which he won his first Oscar for Best Director; he won again for Saving Private Ryan (1998). Spielberg also has tackled more traditional fare such as Catch Me If You Can (2002) and The Terminal (2004). His broad resume and depth of talent garnered him the Cecil B. DeMille Award in 2009.]]>
|
8
|
+
</bio>
|
9
|
+
<link href="http://api.netflix.com/catalog/people/87835/filmography"
|
10
|
+
rel="http://schemas.netflix.com/catalog/titles.filmography"
|
11
|
+
title="filmography"></link>
|
12
|
+
<link href="http://www.netflix.com/RoleDisplay/Steven_Spielberg/87835"
|
13
|
+
rel="alternate" title="web page"></link>
|
14
|
+
</person>
|
15
|
+
</people>
|
@@ -0,0 +1,56 @@
|
|
1
|
+
<?xml version="1.0" standalone="yes"?>
|
2
|
+
<catalog_title>
|
3
|
+
<id>http://api.netflix.com/catalog/titles/movies/60001220</id>
|
4
|
+
<title short="Jaws" regular="Jaws"></title>
|
5
|
+
<box_art small="http://cdn-0.nflximg.com/us/boxshots/tiny/60001220.jpg"
|
6
|
+
medium="http://cdn-0.nflximg.com/us/boxshots/small/60001220.jpg"
|
7
|
+
large="http://cdn-0.nflximg.com/us/boxshots/large/60001220.jpg">
|
8
|
+
</box_art>
|
9
|
+
<link href="http://api.netflix.com/catalog/titles/movies/60001220/synopsis"
|
10
|
+
rel="http://schemas.netflix.com/catalog/titles/synopsis"
|
11
|
+
title="synopsis"></link>
|
12
|
+
<link href="http://api.netflix.com/catalog/titles/movies/60001220/bonus_materials"
|
13
|
+
rel="http://schemas.netflix.com/catalog/titles/bonus_materials"
|
14
|
+
title="bonus materials"></link>
|
15
|
+
<release_year>1975</release_year>
|
16
|
+
<category scheme="http://api.netflix.com/categories/mpaa_ratings"
|
17
|
+
label="PG" term="PG"></category>
|
18
|
+
<category scheme="http://api.netflix.com/categories/genres"
|
19
|
+
label="Thrillers" term="Thrillers"></category>
|
20
|
+
<category scheme="http://api.netflix.com/categories/genres"
|
21
|
+
label="Classic Thrillers" term="Classic Thrillers"></category>
|
22
|
+
<category scheme="http://api.netflix.com/categories/genres"
|
23
|
+
label="Action Thrillers" term="Action Thrillers"></category>
|
24
|
+
<category scheme="http://api.netflix.com/categories/genres"
|
25
|
+
label="Suspense" term="Suspense"></category>
|
26
|
+
<category scheme="http://api.netflix.com/categories/genres"
|
27
|
+
label="Blockbusters" term="Blockbusters"></category>
|
28
|
+
<category scheme="http://api.netflix.com/categories/genres"
|
29
|
+
label="Universal Studios Home Entertainment"
|
30
|
+
term="Universal Studios Home Entertainment"></category>
|
31
|
+
<runtime>7500</runtime>
|
32
|
+
<link href="http://api.netflix.com/catalog/titles/movies/60001220/cast"
|
33
|
+
rel="http://schemas.netflix.com/catalog/people.cast"
|
34
|
+
title="cast"></link>
|
35
|
+
<link href="http://api.netflix.com/catalog/titles/movies/60001220/directors"
|
36
|
+
rel="http://schemas.netflix.com/catalog/people.directors"
|
37
|
+
title="directors"></link>
|
38
|
+
<link href="http://api.netflix.com/catalog/titles/movies/60001220/format_availability"
|
39
|
+
rel="http://schemas.netflix.com/catalog/titles/format_availability"
|
40
|
+
title="formats"></link>
|
41
|
+
<link href="http://api.netflix.com/catalog/titles/movies/60001220/awards"
|
42
|
+
rel="http://schemas.netflix.com/catalog/titles/awards"
|
43
|
+
title="awards"></link>
|
44
|
+
<link href="http://api.netflix.com/catalog/titles/movies/60001220/screen_formats"
|
45
|
+
rel="http://schemas.netflix.com/catalog/titles/screen_formats"
|
46
|
+
title="screen formats"></link>
|
47
|
+
<link href="http://api.netflix.com/catalog/titles/movies/60001220/languages_and_audio"
|
48
|
+
rel="http://schemas.netflix.com/catalog/titles/languages_and_audio"
|
49
|
+
title="languages and audio"></link>
|
50
|
+
<average_rating>3.9</average_rating>
|
51
|
+
<link href="http://api.netflix.com/catalog/titles/movies/60001220/similars"
|
52
|
+
rel="http://schemas.netflix.com/catalog/titles.similars"
|
53
|
+
title="similars"></link>
|
54
|
+
<link href="http://www.netflix.com/Movie/Jaws/60001220"
|
55
|
+
rel="alternate" title="web page"></link>
|
56
|
+
</catalog_title>
|
@@ -0,0 +1,3 @@
|
|
1
|
+
<?xml version="1.0" standalone="yes"?>
|
2
|
+
|
3
|
+
<synopsis><![CDATA[Joyce Carol Oates' classic short story "Where Are You Going, Where Have You Been?" serves as the inspiration for this disturbing drama, winner of the Grand Jury Prize at the 1986 Sundance Film Festival. When sultry teen Connie (<a href="http://www.netflix.com/RoleDisplay/Laura_Dern/23978">Laura Dern</a>) discovers her sexuality, the object of her affection isn't someone her age but rather the much older, mysterious Arnold Friend (<a href="http://www.netflix.com/RoleDisplay/Treat_Williams/99725">Treat Williams</a>) -- who may not have the purest intentions. ]]></synopsis>
|
@@ -0,0 +1,69 @@
|
|
1
|
+
<?xml version="1.0" standalone="yes"?>
|
2
|
+
<catalog_titles>
|
3
|
+
<link href="http://api.netflix.com/catalog/titles/index"
|
4
|
+
rel="http://schemas.netflix.com/catalog/titles/index"
|
5
|
+
title="index"></link>
|
6
|
+
<link href="http://api.netflix.com/catalog/titles/autocomplete"
|
7
|
+
rel="http://schemas.netflix.com/catalog/titles/autocomplete"
|
8
|
+
title="autocomplete"></link>
|
9
|
+
<url_template>
|
10
|
+
http://api.netflix.com/catalog/titles?{-join|&|term|start_index|max_results}</url_template>
|
11
|
+
<number_of_results>291</number_of_results>
|
12
|
+
<start_index>0</start_index>
|
13
|
+
<results_per_page>1</results_per_page>
|
14
|
+
<catalog_title>
|
15
|
+
<id>http://api.netflix.com/catalog/titles/movies/60001220</id>
|
16
|
+
<title short="Jaws" regular="Jaws"></title>
|
17
|
+
<box_art small="http://cdn-0.nflximg.com/us/boxshots/tiny/60001220.jpg"
|
18
|
+
medium="http://cdn-0.nflximg.com/us/boxshots/small/60001220.jpg"
|
19
|
+
large="http://cdn-0.nflximg.com/us/boxshots/large/60001220.jpg">
|
20
|
+
</box_art>
|
21
|
+
<link href="http://api.netflix.com/catalog/titles/movies/60001220/synopsis"
|
22
|
+
rel="http://schemas.netflix.com/catalog/titles/synopsis"
|
23
|
+
title="synopsis"></link>
|
24
|
+
<link href="http://api.netflix.com/catalog/titles/movies/60001220/bonus_materials"
|
25
|
+
rel="http://schemas.netflix.com/catalog/titles/bonus_materials"
|
26
|
+
title="bonus materials"></link>
|
27
|
+
<release_year>1975</release_year>
|
28
|
+
<category scheme="http://api.netflix.com/categories/mpaa_ratings"
|
29
|
+
label="PG" term="PG"></category>
|
30
|
+
<category scheme="http://api.netflix.com/categories/genres"
|
31
|
+
label="Thrillers" term="Thrillers"></category>
|
32
|
+
<category scheme="http://api.netflix.com/categories/genres"
|
33
|
+
label="Classic Thrillers" term="Classic Thrillers"></category>
|
34
|
+
<category scheme="http://api.netflix.com/categories/genres"
|
35
|
+
label="Action Thrillers" term="Action Thrillers"></category>
|
36
|
+
<category scheme="http://api.netflix.com/categories/genres"
|
37
|
+
label="Suspense" term="Suspense"></category>
|
38
|
+
<category scheme="http://api.netflix.com/categories/genres"
|
39
|
+
label="Blockbusters" term="Blockbusters"></category>
|
40
|
+
<category scheme="http://api.netflix.com/categories/genres"
|
41
|
+
label="Universal Studios Home Entertainment"
|
42
|
+
term="Universal Studios Home Entertainment"></category>
|
43
|
+
<runtime>7500</runtime>
|
44
|
+
<link href="http://api.netflix.com/catalog/titles/movies/60001220/cast"
|
45
|
+
rel="http://schemas.netflix.com/catalog/people.cast"
|
46
|
+
title="cast"></link>
|
47
|
+
<link href="http://api.netflix.com/catalog/titles/movies/60001220/directors"
|
48
|
+
rel="http://schemas.netflix.com/catalog/people.directors"
|
49
|
+
title="directors"></link>
|
50
|
+
<link href="http://api.netflix.com/catalog/titles/movies/60001220/format_availability"
|
51
|
+
rel="http://schemas.netflix.com/catalog/titles/format_availability"
|
52
|
+
title="formats"></link>
|
53
|
+
<link href="http://api.netflix.com/catalog/titles/movies/60001220/awards"
|
54
|
+
rel="http://schemas.netflix.com/catalog/titles/awards"
|
55
|
+
title="awards"></link>
|
56
|
+
<link href="http://api.netflix.com/catalog/titles/movies/60001220/screen_formats"
|
57
|
+
rel="http://schemas.netflix.com/catalog/titles/screen_formats"
|
58
|
+
title="screen formats"></link>
|
59
|
+
<link href="http://api.netflix.com/catalog/titles/movies/60001220/languages_and_audio"
|
60
|
+
rel="http://schemas.netflix.com/catalog/titles/languages_and_audio"
|
61
|
+
title="languages and audio"></link>
|
62
|
+
<average_rating>3.9</average_rating>
|
63
|
+
<link href="http://api.netflix.com/catalog/titles/movies/60001220/similars"
|
64
|
+
rel="http://schemas.netflix.com/catalog/titles.similars"
|
65
|
+
title="similars"></link>
|
66
|
+
<link href="http://www.netflix.com/Movie/Jaws/60001220"
|
67
|
+
rel="alternate" title="web page"></link>
|
68
|
+
</catalog_title>
|
69
|
+
</catalog_titles>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FormatBuilderTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_that_current_formats_are_parsed_from_full_catalog
|
6
|
+
data = title_with_formats
|
7
|
+
formats = FormatBuilder.from_movie(data)
|
8
|
+
assert_included formats, 'current_format'
|
9
|
+
assert_included formats, 'no_availability_format'
|
10
|
+
assert_not_included formats, 'future_format'
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_that_format_links_are_followed
|
14
|
+
|
15
|
+
NetFlix::Request.expects(:new).with(:url => 'http://api.netflix.com/catalog/titles/movies/60031755/format_availability').returns(stub_everything(:send => '<xml/>'))
|
16
|
+
|
17
|
+
FormatBuilder.from_movie( title_with_link_to_formats )
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_that_cast_list_contains_current_formats
|
21
|
+
formats = FormatBuilder.from_xml(delivery_format_list)
|
22
|
+
assert_included formats, 'current_format'
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_that_format_list_does_not_contain_future_formats
|
26
|
+
formats = FormatBuilder.from_xml(delivery_format_list)
|
27
|
+
assert_not_included formats, 'future_format'
|
28
|
+
end
|
29
|
+
|
30
|
+
def delivery_format_list
|
31
|
+
%|<delivery_formats>
|
32
|
+
<availability available_from="#{(Time.now - 2.days).to_i}">
|
33
|
+
<category scheme="http://api.netflix.com/categories/title_formats" label="current_format" term="current_format"></category>
|
34
|
+
</availability>
|
35
|
+
<availability available_from="#{(Time.now + 2.days).to_i}">
|
36
|
+
<category scheme="http://api.netflix.com/categories/title_formats" label="future_format" term="future_format"></category>
|
37
|
+
</availability>
|
38
|
+
</delivery_formats
|
39
|
+
|
|
40
|
+
end
|
41
|
+
|
42
|
+
def title_with_link_to_formats
|
43
|
+
xml = '<catalog_title><link href="http://api.netflix.com/catalog/titles/movies/60031755/format_availability" rel="http://schemas.netflix.com/catalog/titles/format_availability" title="formats"></link></catalog_title>'
|
44
|
+
Nokogiri.XML(xml).search('//catalog_title')
|
45
|
+
end
|
46
|
+
|
47
|
+
def title_with_formats
|
48
|
+
|
49
|
+
xml = %|<title_index_item>
|
50
|
+
<delivery_formats>
|
51
|
+
<availability available_from="#{(Time.now + 2.days).to_i}">
|
52
|
+
<category
|
53
|
+
label="future_format" term="future_format"></category>
|
54
|
+
</availability>
|
55
|
+
<availability available_from="#{(Time.now - 2.days).to_i}">
|
56
|
+
<category scheme="http://api.netflix.com/categories/title_formats" label="current_format" term="current_format"></category>
|
57
|
+
</availability>
|
58
|
+
<availability>
|
59
|
+
<category scheme="http://api.netflix.com/categories/title_formats" label="no_availability_format" term="no_availability_format"></category>
|
60
|
+
</availability>
|
61
|
+
</delivery_formats>
|
62
|
+
</title_index_item>
|
63
|
+
|
|
64
|
+
|
65
|
+
Nokogiri.XML(xml).search('//title_index_item')
|
66
|
+
end
|
67
|
+
end
|
data/test/movie_test.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
class NetFlix::MovieTest < Test::Unit::TestCase
|
3
|
+
def setup
|
4
|
+
@movie = NetFlix::Movie.new(load_fixture_file('movies.xml'))
|
5
|
+
end
|
6
|
+
context "rating" do
|
7
|
+
should "be the rating of the movie" do
|
8
|
+
assert_equal @movie.rating, 'PG'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "release_year" do
|
13
|
+
should "be the release year" do
|
14
|
+
assert_equal @movie.release_year, '1975'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "directors" do
|
19
|
+
should "be the an array with the name of a director" do
|
20
|
+
mock_next_response("http://api.netflix.com/catalog/titles/movies/60001220/directors", 'directors.xml' )
|
21
|
+
assert_equal [ "Steven Spielberg" ], @movie.directors
|
22
|
+
end
|
23
|
+
context "element missing" do
|
24
|
+
should "be an empty array" do
|
25
|
+
movie_xml = Nokogiri.parse(load_fixture_file('movies.xml'))
|
26
|
+
links = movie_xml / "//link"
|
27
|
+
links.remove
|
28
|
+
@movie = NetFlix::Movie.new(movie_xml)
|
29
|
+
assert_equal [], @movie.directors
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "actors" do
|
35
|
+
setup do
|
36
|
+
mock_next_response("http://api.netflix.com/catalog/titles/movies/60001220/cast", 'cast.xml')
|
37
|
+
end
|
38
|
+
should "be an array of actor names" do
|
39
|
+
['Roy Scheider','Richard Dreyfuss'].each do |actor|
|
40
|
+
assert @movie.actors.include?(actor)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "find" do
|
46
|
+
should "return an array of movies" do
|
47
|
+
NetFlix::Request.expects(:new).returns(stub(:send => load_fixture_file('titles.xml')))
|
48
|
+
NetFlix::Movie.find( :term => 'pants' ).each do |movie|
|
49
|
+
assert_equal NetFlix::Movie, movie.class
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class NetflixTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_that_http_method_is_validated
|
6
|
+
assert_equal false, NetFlix::Request.new(:http_method => 'Thing').valid?
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_that_http_method_knows_valid_values
|
10
|
+
assert_equal true, NetFlix::Request.new(:http_method => 'POST').valid?
|
11
|
+
assert_equal true, NetFlix::Request.new(:http_method => 'GET').valid?
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_that_parameters_appear_alphabetically_in_parameter_string
|
15
|
+
assert_equal 'key_a=value1&key_b=value2', NetFlix::Request.new(:parameters => {'key_b' => 'value2', 'key_a' => 'value1'}).parameter_string
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_that_authenticator_receives_copy_of_request
|
19
|
+
request = NetFlix::Request.new(:parameters => {'key1' => '2'})
|
20
|
+
NetFlix::Authenticator.expects(:new).with(has_entry(:request, request)).returns(stub_everything)
|
21
|
+
Net::HTTP.stubs(:get)
|
22
|
+
|
23
|
+
request.send
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_that_request_is_logged_when_sent
|
27
|
+
request = NetFlix::Request.new(:url => 'some_url', :parameters => {'logme' => 'please'})
|
28
|
+
NetFlix.expects(:log).with('some_url?logme=please')
|
29
|
+
request.log
|
30
|
+
end
|
31
|
+
|
32
|
+
context :encoding do
|
33
|
+
should "encode parameter values" do
|
34
|
+
request = NetFlix::Request.new(:url => 'some_url', :parameters => {'term' => 'with spaces'})
|
35
|
+
assert_match /with%20spaces/, request.target.to_s
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'ruby-debug'
|
5
|
+
require 'mocha'
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
|
+
require 'flix4r'
|
10
|
+
|
11
|
+
class Test::Unit::TestCase
|
12
|
+
def load_fixture_file( file_name )
|
13
|
+
File.open( File.join(File.dirname(__FILE__), 'fixtures', file_name )).read
|
14
|
+
end
|
15
|
+
|
16
|
+
def mock_next_response( url, fixture_file_name )
|
17
|
+
NetFlix::Request.expects(:new).with(:url => url ).returns(stub(:send => load_fixture_file(fixture_file_name)))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
module Test::Unit::Assertions
|
21
|
+
|
22
|
+
def assert_included(items, needle, custom_message = nil)
|
23
|
+
raise 'First argument for assert_included must be an array' unless items.is_a? Array
|
24
|
+
|
25
|
+
message = build_message custom_message, "Expected #{items.inspect} to contain #{needle.inspect} but it did not."
|
26
|
+
|
27
|
+
assert_block message do
|
28
|
+
items.include? needle
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def assert_not_included(items, needle, custom_message = nil)
|
33
|
+
message = build_message custom_message, "Did not expect #{items.inspect} to contain #{needle.inspect}, but it did."
|
34
|
+
|
35
|
+
assert_block message do
|
36
|
+
not items.include? needle
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/test/title_test.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
class TitleTest < Test::Unit::TestCase
|
3
|
+
|
4
|
+
=begin
|
5
|
+
def test_that_title_can_go_to_and_from_json
|
6
|
+
expected = NetFlix::Title.new(load_fixture_file('titles.xml'))
|
7
|
+
|
8
|
+
actual = NetFlix::Title.from_json( expected.to_json )
|
9
|
+
|
10
|
+
assert_equal expected.id, actual.id
|
11
|
+
assert_equal expected.delivery_formats, actual.delivery_formats
|
12
|
+
end
|
13
|
+
=end
|
14
|
+
|
15
|
+
context "autocomplete" do
|
16
|
+
|
17
|
+
should "return an array of titles" do
|
18
|
+
NetFlix::Request.expects(:new).returns(stub( :send => load_fixture_file('autocomplete.xml' )))
|
19
|
+
|
20
|
+
assert_equal ["Love Wrecked", "Lovesickness", "Loverboy" ], NetFlix::Title.autocomplete( 'ignored' )
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "instance methods" do
|
25
|
+
setup do
|
26
|
+
@title = NetFlix::Title.parse(load_fixture_file('titles.xml')).first
|
27
|
+
end
|
28
|
+
context "title" do
|
29
|
+
should "be the title of the movie" do
|
30
|
+
assert_equal @title.title, 'Jaws'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
context "images" do
|
34
|
+
should "return an image url for the sizes small, medium, and large" do
|
35
|
+
%w{ small medium large }.each do |size|
|
36
|
+
assert_nothing_raised 'valid url' do
|
37
|
+
URI::parse(@title.images[size])
|
38
|
+
end
|
39
|
+
assert_match(/\.jpg$/, @title.images[size], 'looks like an image')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "synopsis" do
|
45
|
+
should "default to blank" do
|
46
|
+
assert_equal NetFlix::Title.new('').synopsis, ''
|
47
|
+
end
|
48
|
+
should "make a request for the synopsis" do
|
49
|
+
mock_next_response("http://api.netflix.com/catalog/titles/movies/60001220/synopsis", 'synopsis.xml')
|
50
|
+
@title.synopsis
|
51
|
+
end
|
52
|
+
should "parse it out all awesomely" do
|
53
|
+
mock_next_response("http://api.netflix.com/catalog/titles/movies/60001220/synopsis", 'synopsis.xml')
|
54
|
+
assert_equal @title.synopsis, "Joyce Carol Oates' classic short story \"Where Are You Going, Where Have You Been?\" serves as the inspiration for this disturbing drama, winner of the Grand Jury Prize at the 1986 Sundance Film Festival. When sultry teen Connie (<a href=\"http://www.netflix.com/RoleDisplay/Laura_Dern/23978\">Laura Dern</a>) discovers her sexuality, the object of her affection isn't someone her age but rather the much older, mysterious Arnold Friend (<a href=\"http://www.netflix.com/RoleDisplay/Treat_Williams/99725\">Treat Williams</a>) -- who may not have the purest intentions. "
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flix4r
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Dunn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-05 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: brianpatrickdunn@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- .document
|
27
|
+
- .gitignore
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- flix4r.gemspec
|
33
|
+
- init.rb
|
34
|
+
- lib/flix4r.rb
|
35
|
+
- lib/net_flix.rb
|
36
|
+
- lib/net_flix/authenticator.rb
|
37
|
+
- lib/net_flix/builders/actor_builder.rb
|
38
|
+
- lib/net_flix/builders/format_builder.rb
|
39
|
+
- lib/net_flix/credentials.rb
|
40
|
+
- lib/net_flix/movie.rb
|
41
|
+
- lib/net_flix/request.rb
|
42
|
+
- lib/net_flix/television.rb
|
43
|
+
- lib/net_flix/title.rb
|
44
|
+
- lib/valuable.rb
|
45
|
+
- test/actor_builder_test.rb
|
46
|
+
- test/authenticator_test.rb
|
47
|
+
- test/credentials_test.rb
|
48
|
+
- test/fixtures/autocomplete.xml
|
49
|
+
- test/fixtures/cast.xml
|
50
|
+
- test/fixtures/directors.xml
|
51
|
+
- test/fixtures/movies.xml
|
52
|
+
- test/fixtures/synopsis.xml
|
53
|
+
- test/fixtures/titles.xml
|
54
|
+
- test/format_builder_test.rb
|
55
|
+
- test/movie_test.rb
|
56
|
+
- test/request_test.rb
|
57
|
+
- test/test_helper.rb
|
58
|
+
- test/title_test.rb
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/briandunn/flix4r
|
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: "a port of the google code project: http://code.google.com/p/flix4r/"
|
87
|
+
test_files:
|
88
|
+
- test/actor_builder_test.rb
|
89
|
+
- test/authenticator_test.rb
|
90
|
+
- test/credentials_test.rb
|
91
|
+
- test/format_builder_test.rb
|
92
|
+
- test/movie_test.rb
|
93
|
+
- test/request_test.rb
|
94
|
+
- test/test_helper.rb
|
95
|
+
- test/title_test.rb
|