youtube_it 2.1.4 → 2.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile DELETED
@@ -1,58 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :test)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "youtube_it"
18
- gem.summary = %Q{The most complete Ruby wrapper for youtube api's}
19
- gem.description = %Q{Upload, delete, update, comment on youtube videos all from one gem.}
20
- gem.email = "kylejginavan@gmail.com"
21
- gem.homepage = "http://github.com/kylejginavan/youtube_it"
22
- gem.authors = ["kylejginavan","chebyte", "mseppae"]
23
- # dependencies defined in Gemfile
24
- end
25
- Jeweler::RubygemsDotOrgTasks.new
26
-
27
- require 'rake/testtask'
28
- Rake::TestTask.new(:test) do |test|
29
- test.libs << 'test'
30
- test.pattern = 'test/**/test_*.rb'
31
- test.verbose = true
32
- end
33
-
34
- begin
35
- require 'rcov/rcovtask'
36
- Rcov::RcovTask.new do |test|
37
- test.libs << 'test'
38
- test.pattern = 'test/**/test_*.rb'
39
- test.verbose = true
40
- end
41
- rescue LoadError
42
- task :rcov do
43
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
44
- end
45
- end
46
-
47
- task :default => :test
48
-
49
- require 'rake/rdoctask'
50
- Rake::RDocTask.new do |rdoc|
51
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
52
-
53
- rdoc.rdoc_dir = 'rdoc'
54
- rdoc.title = "constantations #{version}"
55
- rdoc.rdoc_files.include('README*')
56
- rdoc.rdoc_files.include('lib/**/*.rb')
57
- end
58
-
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 2.1.4
@@ -1 +0,0 @@
1
- <?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:app='http://www.w3.org/2007/app' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007'><entry gd:etag='W/&quot;C08NSH47eCp7ImA9WhZXGUU.&quot;'><id>tag:youtube.com,2008:video:z8zIecfFRjM</id><published>2011-01-28T20:32:47.000Z</published><updated>2011-05-09T22:58:19.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/><category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Music' label='Music'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='School Jam USA'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='lennon bus live'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='lennon bus'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='lennon'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='john lennon'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='ac/dc'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='motley crue'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='namm 2011'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='namm'/><title>Lennon Bus Live: Peligro - "Hollywood Red"</title><content type='application/x-shockwave-flash' src='http://www.youtube.com/v/z8zIecfFRjM?f=videos&amp;app=youtube_gdata'/><link rel='alternate' type='text/html' href='http://www.youtube.com/watch?v=z8zIecfFRjM&amp;feature=youtube_gdata'/><link rel='http://gdata.youtube.com/schemas/2007#video.responses' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/z8zIecfFRjM/responses?v=2'/><link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/z8zIecfFRjM/related?v=2'/><link rel='http://gdata.youtube.com/schemas/2007#mobile' type='text/html' href='http://m.youtube.com/details?v=z8zIecfFRjM'/><link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/z8zIecfFRjM?v=2'/><author><name>johnlennonbus</name><uri>http://gdata.youtube.com/feeds/api/users/johnlennonbus</uri></author><yt:accessControl action='comment' permission='allowed'/><yt:accessControl action='commentVote' permission='allowed'/><yt:accessControl action='videoRespond' permission='moderated'/><yt:accessControl action='rate' permission='allowed'/><yt:accessControl action='embed' permission='allowed'/><yt:accessControl action='list' permission='allowed'/><yt:accessControl action='syndicate' permission='allowed'/><gd:comments><gd:feedLink href='http://gdata.youtube.com/feeds/api/videos/z8zIecfFRjM/comments?v=2' countHint='28'/></gd:comments><yt:location>Anaheim, Ca</yt:location><media:group><media:category label='Music' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Music</media:category><media:content url='http://www.youtube.com/v/z8zIecfFRjM?f=videos&amp;app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefault='true' expression='full' duration='192' yt:format='5'/><media:content url='rtsp://v6.cache2.c.youtube.com/CiILENy73wIaGQkzRsXHecjMzxMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='192' yt:format='1'/><media:content url='rtsp://v3.cache5.c.youtube.com/CiILENy73wIaGQkzRsXHecjMzxMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='192' yt:format='6'/><media:credit role='uploader' scheme='urn:youtube'>johnlennonbus</media:credit><media:description type='plain'>At NAMM 2011, School Jam USA winners Peligro had the opportunity to come aboard the John Lennon Educational Tour Bus to record a song and shoot a music video. These young rockers would not seem out of place alongside AC/DC or Mötley Crüe. Be Sure to check them out as they rock out during a Lennon Bus Live Session, performing their hit, Hollywood Red</media:description><media:keywords>School Jam USA, lennon bus live, lennon bus, lennon, john lennon, ac/dc, motley crue, namm 2011, namm</media:keywords><media:player url='http://www.youtube.com/watch?v=z8zIecfFRjM&amp;feature=youtube_gdata_player'/><media:thumbnail url='http://i.ytimg.com/vi/z8zIecfFRjM/default.jpg' height='90' width='120' time='00:01:36' yt:name='default'/><media:thumbnail url='http://i.ytimg.com/vi/z8zIecfFRjM/hqdefault.jpg' height='360' width='480' yt:name='hqdefault'/><media:thumbnail url='http://i.ytimg.com/vi/z8zIecfFRjM/1.jpg' height='90' width='120' time='00:00:48' yt:name='start'/><media:thumbnail url='http://i.ytimg.com/vi/z8zIecfFRjM/2.jpg' height='90' width='120' time='00:01:36' yt:name='middle'/><media:thumbnail url='http://i.ytimg.com/vi/z8zIecfFRjM/3.jpg' height='90' width='120' time='00:02:24' yt:name='end'/><media:title type='plain'>Lennon Bus Live: Peligro - "Hollywood Red"</media:title><yt:aspectRatio>widescreen</yt:aspectRatio><yt:duration seconds='192'/><yt:uploaded>2011-01-28T20:32:47.000Z</yt:uploaded><yt:videoid>z8zIecfFRjM</yt:videoid></media:group><gd:rating average='4.894737' max='5' min='1' numRaters='38' rel='http://schemas.google.com/g/2005#overall'/><yt:recorded>2011-01-16</yt:recorded><yt:statistics favoriteCount='21' viewCount='3648'/><yt:rating numDislikes='1' numLikes='37'/></entry></feed>
@@ -1,53 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:yt="http://gdata.youtube.com/schemas/2007" gd:etag="W/&quot;A0UBR347eCp7ImA9Wx9bFEs.&quot;">
3
- <id>tag:youtube.com,2008:video:AbC123DeFgH</id>
4
- <published>2010-12-29T13:57:49.000Z</published>
5
- <updated>2011-02-23T13:54:16.000Z</updated>
6
- <category scheme="http://schemas.google.com/g/2005#kind" term="http://gdata.youtube.com/schemas/2007#video"/>
7
- <category scheme="http://gdata.youtube.com/schemas/2007/categories.cat" term="Test" label="Test"/>
8
- <category scheme="http://gdata.youtube.com/schemas/2007/keywords.cat" term="test"/>
9
- <title>YouTube Test Video</title>
10
- <content type="application/x-shockwave-flash" src="http://www.youtube.com/v/YTAbC123DeF?f=videos&amp;app=youtube_gdata"/>
11
- <link rel="alternate" type="text/html" href="http://www.youtube.com/watch?v=AbC123DeFgH&amp;feature=youtube_gdata"/>
12
- <link rel="http://gdata.youtube.com/schemas/2007#video.responses" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/AbC123DeFgH/responses?v=2"/>
13
- <link rel="http://gdata.youtube.com/schemas/2007#video.related" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/AbC123DeFgH/related?v=2"/>
14
- <link rel="http://gdata.youtube.com/schemas/2007#mobile" type="text/html" href="http://m.youtube.com/details?v=AbC123DeFgH"/>
15
- <link rel="self" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/AbC123DeFgH?v=2"/>
16
- <author>
17
- <name>Test user</name>
18
- <uri>http://gdata.youtube.com/feeds/api/users/test_user</uri>
19
- </author>
20
- <yt:accessControl action="comment" permission="allowed"/>
21
- <yt:accessControl action="commentVote" permission="allowed"/>
22
- <yt:accessControl action="videoRespond" permission="moderated"/>
23
- <yt:accessControl action="rate" permission="allowed"/>
24
- <yt:accessControl action="embed" permission="allowed"/>
25
- <yt:accessControl action="list" permission="allowed"/>
26
- <yt:accessControl action="syndicate" permission="allowed"/>
27
- <gd:comments>
28
- <gd:feedLink href="http://gdata.youtube.com/feeds/api/videos/AbC123DeFgH/comments?v=2" countHint="1000"/>
29
- </gd:comments>
30
- <media:group>
31
- <media:category label="Sports" scheme="http://gdata.youtube.com/schemas/2007/categories.cat">Test</media:category>
32
- <media:content url="http://www.youtube.com/v/AbC123DeFgH?f=videos&amp;app=youtube_gdata" type="application/x-shockwave-flash" medium="video" isDefault="true" expression="full" duration="356" yt:format="5"/>
33
- <media:content url="rtsp://v7.cache6.c.youtube.com/TESTCACHE/0/0/0/video.3gp" type="video/3gpp" medium="video" expression="full" duration="356" yt:format="1"/>
34
- <media:content url="rtsp://v8.cache7.c.youtube.com/TESTCACHE/0/0/0/video.3gp" type="video/3gpp" medium="video" expression="full" duration="356" yt:format="6"/>
35
- <media:credit role="uploader" scheme="urn:youtube" yt:type="partner">Test user</media:credit>
36
- <media:description type="plain">Youtube Test Video</media:description>
37
- <media:keywords>Test, Youtube, Youtube_it, Ruby</media:keywords>
38
- <media:player url="http://www.youtube.com/watch?v=AbC123DeFgH&amp;feature=youtube_gdata_player"/>
39
- <media:thumbnail url="http://i.ytimg.com/vi/AbC123DeFgH/default.jpg" height="90" width="120" time="00:02:58" yt:name="default"/>
40
- <media:thumbnail url="http://i.ytimg.com/vi/AbC123DeFgH/hqdefault.jpg" height="360" width="480" yt:name="hqdefault"/>
41
- <media:thumbnail url="http://i.ytimg.com/vi/AbC123DeFgH/1.jpg" height="90" width="120" time="00:01:29" yt:name="start"/>
42
- <media:thumbnail url="http://i.ytimg.com/vi/AbC123DeFgH/2.jpg" height="90" width="120" time="00:02:58" yt:name="middle"/>
43
- <media:thumbnail url="http://i.ytimg.com/vi/AbC123DeFgH/3.jpg" height="90" width="120" time="00:04:27" yt:name="end"/>
44
- <media:title type="plain">Ich sterbe für YouTube</media:title>
45
- <yt:aspectRatio>widescreen</yt:aspectRatio>
46
- <yt:duration seconds="356"/>
47
- <yt:uploaded>2010-12-29T13:57:49.000Z</yt:uploaded>
48
- <yt:videoid>AbC123DeFgH</yt:videoid>
49
- </media:group>
50
- <gd:rating average="4.305027" max="5" min="1" numRaters="2049" rel="http://schemas.google.com/g/2005#overall"/>
51
- <yt:statistics favoriteCount="200" viewCount="240000"/>
52
- <yt:rating numDislikes="350" numLikes="1700"/>
53
- </entry>
data/test/helper.rb DELETED
@@ -1,9 +0,0 @@
1
- require 'rubygems'
2
- require 'date'
3
- require 'test/unit'
4
- require 'pp'
5
- require 'open-uri'
6
- require File.dirname(__FILE__) + '/../lib/youtube_it'
7
-
8
- YouTubeIt.logger.level = Logger::ERROR
9
-
data/test/test.mov DELETED
Binary file
@@ -1,63 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/helper')
2
-
3
- class TestChainIO < Test::Unit::TestCase
4
- def setup
5
- @klass = YouTubeIt::ChainIO # save typing
6
- end
7
-
8
- def test_should_support_read_from_one_io
9
- io = @klass.new "abcd"
10
- assert io.respond_to?(:read)
11
- assert_equal "ab", io.read(2)
12
- assert_equal "cd", io.read(2)
13
- assert_equal false, io.read(2)
14
- end
15
-
16
- def test_should_skip_over_depleted_streams
17
- io = @klass.new '', '', '', '', 'ab'
18
- assert_equal 'ab', io.read(2)
19
- end
20
-
21
- def test_should_read_across_nultiple_streams_with_large_offset
22
- io = @klass.new 'abc', '', 'def', '', 'ghij'
23
- assert_equal 'abcdefgh', io.read(8)
24
- end
25
-
26
- def test_should_return_false_for_empty_items
27
- io = @klass.new '', '', '', '', ''
28
- assert_equal false, io.read(8)
29
- end
30
-
31
- def test_should_support_overzealous_read
32
- io = @klass.new "ab"
33
- assert_equal "ab", io.read(5000)
34
- end
35
-
36
- def test_should_predict_expected_length
37
- io = @klass.new "ab", "cde"
38
- assert_equal 5, io.expected_length
39
- end
40
-
41
- def test_should_predict_expected_length_with_prepositioned_io
42
- first_buf = StringIO.new("ab")
43
- first_buf.read(1)
44
-
45
- io = @klass.new first_buf, "cde"
46
- assert_equal 4, io.expected_length
47
- end
48
-
49
- def test_should_predict_expected_length_with_file_handle
50
- test_size = File.size(__FILE__)
51
- first_buf = StringIO.new("ab")
52
- first_buf.read(1)
53
-
54
- io = @klass.new File.open(__FILE__), first_buf
55
- assert_equal test_size + 1, io.expected_length
56
- end
57
-
58
- def test_greedy
59
- io = YouTubeIt::GreedyChainIO.new("a" * (1024 * 513))
60
- chunk = io.read(123)
61
- assert_equal 1024 * 512, chunk.length, "Should have read the first 512 KB chunk at once instead"
62
- end
63
- end
data/test/test_client.rb DELETED
@@ -1,454 +0,0 @@
1
- #encoding: utf-8
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/helper')
4
-
5
- class TestClient < Test::Unit::TestCase
6
-
7
- OPTIONS = {:title => "test title",
8
- :description => "test description",
9
- :category => 'People',
10
- :keywords => %w[test]}
11
- ACCOUNT = {:user => "tubeit20101", :passwd => "youtube_it", :dev_key => "AI39si411VBmO4Im9l0rfRsORXDI6F5AX5NlTIA4uHSWqa-Cgf-jUQG-6osUBB3PTLawLHlkKXPLr3B0pNcGU9wkNd11gIgdPg" }
12
- RAILS_ENV = "test"
13
-
14
- def setup
15
- #clientlogin
16
- @client = YouTubeIt::Client.new(:username => ACCOUNT[:user], :password => ACCOUNT[:passwd] , :dev_key => ACCOUNT[:dev_key])
17
- #authsub
18
- #@client = YouTubeIt::AuthSubClient.new(:token => "1/vqYlJytmn4eWRjJnORHT94mENNfZzZsLutMOrvvygB4" , :dev_key => ACCOUNT[:dev_key])
19
- end
20
-
21
- def test_should_respond_to_a_basic_query
22
- response = @client.videos_by(:query => "penguin")
23
-
24
- assert_equal "tag:youtube.com,2008:videos", response.feed_id
25
- assert_equal 25, response.max_result_count
26
- assert_equal 25, response.videos.length
27
- assert_equal 1, response.offset
28
- assert(response.total_result_count > 100)
29
- assert_instance_of Time, response.updated_at
30
-
31
- response.videos.each { |v| assert_valid_video v }
32
- end
33
-
34
- def test_should_respond_to_a_basic_query_with_offset_and_max_results
35
- response = @client.videos_by(:query => "penguin", :offset => 15, :max_results => 30)
36
-
37
- assert_equal "tag:youtube.com,2008:videos", response.feed_id
38
- assert_equal 30, response.max_result_count
39
- assert_equal 30, response.videos.length
40
- assert_equal 15, response.offset
41
- assert(response.total_result_count > 100)
42
- assert_instance_of Time, response.updated_at
43
-
44
- response.videos.each { |v| assert_valid_video v }
45
- end
46
-
47
- def test_should_respond_to_a_basic_query_with_paging
48
- response = @client.videos_by(:query => "penguin")
49
- assert_equal "tag:youtube.com,2008:videos", response.feed_id
50
- assert_equal 25, response.max_result_count
51
- assert_equal 1, response.offset
52
-
53
- response = @client.videos_by(:query => "penguin", :page => 2)
54
- assert_equal "tag:youtube.com,2008:videos", response.feed_id
55
- assert_equal 25, response.max_result_count
56
- assert_equal 26, response.offset
57
-
58
- response2 = @client.videos_by(:query => "penguin", :page => 3)
59
- assert_equal "tag:youtube.com,2008:videos", response2.feed_id
60
- assert_equal 25, response2.max_result_count
61
- assert_equal 51, response2.offset
62
- end
63
-
64
- def test_should_get_videos_for_multiword_metasearch_query
65
- response = @client.videos_by(:query => 'christina ricci')
66
-
67
- assert_equal "tag:youtube.com,2008:videos", response.feed_id
68
- assert_equal 25, response.max_result_count
69
- assert_equal 25, response.videos.length
70
- assert_equal 1, response.offset
71
- assert(response.total_result_count > 100)
72
- assert_instance_of Time, response.updated_at
73
-
74
- response.videos.each { |v| assert_valid_video v }
75
- end
76
-
77
- def test_should_handle_video_not_yet_viewed
78
- response = @client.videos_by(:query => "CE62FSEoY28")
79
-
80
- assert_equal 1, response.videos.length
81
- response.videos.each { |v| assert_valid_video v }
82
- end
83
-
84
- def test_should_get_videos_for_one_tag
85
- response = @client.videos_by(:tags => ['panther'])
86
- response.videos.each { |v| assert_valid_video v }
87
- end
88
-
89
- def test_should_get_videos_for_multiple_tags
90
- response = @client.videos_by(:tags => ['tiger', 'leopard'])
91
- response.videos.each { |v| assert_valid_video v }
92
- end
93
-
94
- def test_should_get_videos_for_one_category
95
- response = @client.videos_by(:categories => [:news])
96
- response.videos.each { |v| assert_valid_video v }
97
- end
98
-
99
- def test_should_get_videos_for_multiple_categories
100
- response = @client.videos_by(:categories => [:news, :sports])
101
- response.videos.each { |v| assert_valid_video v }
102
- end
103
-
104
- # TODO: Need to do more specific checking in these tests
105
- # Currently, if a URL is valid, and videos are found, the test passes regardless of search criteria
106
- def test_should_get_videos_for_categories_and_tags
107
- response = @client.videos_by(:categories => [:news, :sports], :tags => ['soccer', 'football'])
108
- response.videos.each { |v| assert_valid_video v }
109
- end
110
-
111
- def test_should_get_most_viewed_videos
112
- response = @client.videos_by(:most_viewed)
113
- response.videos.each { |v| assert_valid_video v }
114
- end
115
-
116
- def test_should_get_top_rated_videos_for_today
117
- response = @client.videos_by(:top_rated, :time => :today)
118
- response.videos.each { |v| assert_valid_video v }
119
- end
120
-
121
- def test_should_get_videos_for_categories_and_tags_with_category_boolean_operators
122
- response = @client.videos_by(:categories => { :either => [:news, :sports], :exclude => [:comedy] },
123
- :tags => { :include => ['football'], :exclude => ['soccer'] })
124
- response.videos.each { |v| assert_valid_video v }
125
- end
126
-
127
- def test_should_get_videos_for_categories_and_tags_with_tag_boolean_operators
128
- response = @client.videos_by(:categories => { :either => [:news, :sports], :exclude => [:comedy] },
129
- :tags => { :either => ['football', 'soccer', 'polo'] })
130
- response.videos.each { |v| assert_valid_video v }
131
- end
132
-
133
- def test_should_get_videos_by_user
134
- response = @client.videos_by(:user => 'liz')
135
- response.videos.each { |v| assert_valid_video v }
136
- end
137
-
138
- def test_should_get_videos_by_user_with_pagination_and_ordering
139
- response = @client.videos_by(:user => 'liz', :page => 2, :per_page => '2', :order_by => 'published')
140
- response.videos.each { |v| assert_valid_video v }
141
- assert_equal 3, response.offset
142
- assert_equal 2, response.max_result_count
143
- end
144
-
145
-
146
- def test_should_get_favorite_videos_by_user
147
- response = @client.videos_by(:favorites, :user => 'drnicwilliams')
148
- assert_equal "tag:youtube.com,2008:user:drnicwilliams:favorites", response.feed_id
149
- assert_valid_video response.videos.first
150
- end
151
-
152
- def test_should_get_videos_for_query_search_with_categories_excluded
153
- video = @client.video_by("EkF4JD2rO3Q")
154
- assert_equal "<object width=\"425\" height=\"350\">\n <param name=\"movie\" value=\"http://www.youtube.com/v/EkF4JD2rO3Q&feature=youtube_gdata_player\"></param>\n <param name=\"wmode\" value=\"transparent\"></param>\n <embed src=\"http://www.youtube.com/v/EkF4JD2rO3Q&feature=youtube_gdata_player\" type=\"application/x-shockwave-flash\"\n wmode=\"transparent\" width=\"425\" height=\"350\"></embed>\n</object>\n", video.embed_html
155
- assert_valid_video video
156
- end
157
-
158
- def test_should_get_video_from_user
159
- video = @client.video_by_user("chebyte","FQK1URcxmb4")
160
- assert_equal "<object width=\"425\" height=\"350\">\n <param name=\"movie\" value=\"http://www.youtube.com/v/FQK1URcxmb4&feature=youtube_gdata_player\"></param>\n <param name=\"wmode\" value=\"transparent\"></param>\n <embed src=\"http://www.youtube.com/v/FQK1URcxmb4&feature=youtube_gdata_player\" type=\"application/x-shockwave-flash\"\n wmode=\"transparent\" width=\"425\" height=\"350\"></embed>\n</object>\n", video.embed_html
161
- assert_valid_video video
162
- end
163
-
164
- def test_should_always_return_a_logger
165
- @client = YouTubeIt::Client.new
166
- assert_not_nil @client.logger
167
- end
168
-
169
- def test_should_not_bail_if_debug_is_true
170
- assert_nothing_raised { YouTubeIt::Client.new(:debug => true) }
171
- end
172
-
173
- def test_should_determine_if_embeddable_video_is_embeddable
174
- response = @client.videos_by(:query => "strongbad")
175
-
176
- video = response.videos.first
177
- assert video.embeddable?
178
- end
179
-
180
- def test_should_retrieve_video_by_id
181
- video = @client.video_by("http://gdata.youtube.com/feeds/videos/EkF4JD2rO3Q")
182
- assert_valid_video video
183
-
184
- video = @client.video_by("EkF4JD2rO3Q")
185
- assert_valid_video video
186
- end
187
-
188
- def test_return_upload_info_for_upload_from_browser
189
- response = @client.upload_token(OPTIONS)
190
- assert response.kind_of?(Hash)
191
- assert_equal response.size, 2
192
- response.each do |k,v|
193
- assert v
194
- end
195
- end
196
-
197
- def test_should_upload_a_video
198
- video = @client.video_upload(File.open("test/test.mov"), OPTIONS)
199
- assert_valid_video video
200
- @client.video_delete(video.unique_id)
201
- end
202
-
203
- def test_should_update_a_video
204
- OPTIONS[:title] = "title changed"
205
- video = @client.video_upload(File.open("test/test.mov"), OPTIONS)
206
- updated_video = @client.video_update(video.unique_id, OPTIONS)
207
- assert updated_video.title == "title changed"
208
- @client.video_delete(video.unique_id)
209
- end
210
-
211
- def test_should_delete_video
212
- video = @client.video_upload(File.open("test/test.mov"), OPTIONS)
213
- assert_valid_video video
214
- assert @client.video_delete(video.unique_id)
215
- end
216
-
217
- def test_should_denied_comments
218
- video = @client.video_upload(File.open("test/test.mov"), OPTIONS.merge(:comment => "denied"))
219
- assert_valid_video video
220
- doc = open("http://www.youtube.com/watch?v=#{video.unique_id}").read
221
- assert "Adding comments has been disabled for this video.", doc.match("Adding comments has been disabled for this video.")[0]
222
- @client.video_delete(video.unique_id)
223
- end
224
-
225
- def test_should_denied_rate
226
- video = @client.video_upload(File.open("test/test.mov"), OPTIONS.merge(:rate => "denied"))
227
- assert_valid_video video
228
- doc = open("http://www.youtube.com/watch?v=#{video.unique_id}").read
229
- assert "Ratings have been disabled for this video.", doc.match("Ratings have been disabled for this video.")[0]
230
- @client.video_delete(video.unique_id)
231
- end
232
-
233
- def test_should_denied_embed
234
- video = @client.video_upload(File.open("test/test.mov"), OPTIONS.merge(:embed => "denied"))
235
- assert video.noembed
236
- @client.video_delete(video.unique_id)
237
- end
238
-
239
-
240
- def test_should_add_new_comment
241
- video = @client.video_upload(File.open("test/test.mov"), OPTIONS)
242
- @client.add_comment(video.unique_id, "test comment")
243
- comment = @client.comments(video.unique_id).first.content
244
- assert comment, "test comment"
245
- @client.video_delete(video.unique_id)
246
- end
247
-
248
- def test_should_add_and_delete_video_from_playlist
249
- playlist = @client.add_playlist(:title => "youtube_it test!", :description => "test playlist")
250
- video = @client.add_video_to_playlist(playlist.playlist_id,"CE62FSEoY28")
251
- assert_equal video[:code].to_i, 201
252
- assert @client.delete_video_from_playlist(playlist.playlist_id, video[:playlist_entry_id])
253
- assert @client.delete_playlist(playlist.playlist_id)
254
- end
255
-
256
- def test_should_return_unique_id_from_playlist
257
- playlist = @client.add_playlist(:title => "youtube_it test!", :description => "test playlist")
258
- video = @client.add_video_to_playlist(playlist.playlist_id,"CE62FSEoY28")
259
-
260
- assert_equal "CE62FSEoY28", playlist.videos.last.unique_id
261
-
262
- assert @client.delete_video_from_playlist(playlist.playlist_id, video[:playlist_entry_id])
263
- assert @client.delete_playlist(playlist.playlist_id)
264
- end
265
-
266
- def test_should_add_and_delete_new_playlist
267
- result = @client.add_playlist(:title => "youtube_it test4!", :description => "test playlist")
268
- assert result.title, "youtube_it test!"
269
- sleep 4
270
- assert @client.delete_playlist(result.playlist_id)
271
- end
272
-
273
- def test_should_update_playlist
274
- playlist = @client.add_playlist(:title => "youtube_it test!", :description => "test playlist")
275
- playlist_updated = @client.update_playlist(playlist.playlist_id, :title => "title changed")
276
- assert_equal playlist_updated.title, "title changed"
277
- assert @client.delete_playlist(playlist.playlist_id)
278
- end
279
-
280
- def test_should_list_playlist_for_user
281
- result = @client.playlists('chebyte')
282
- assert result.last.title, "rock"
283
- end
284
-
285
- def test_should_determine_if_widescreen_video_is_widescreen
286
- widescreen_id = 'QqQVll-MP3I'
287
-
288
- video = @client.video_by(widescreen_id)
289
- assert video.widescreen?
290
- end
291
-
292
- def test_get_current_user
293
- assert_equal @client.current_user, 'tubeit20101'
294
- end
295
-
296
- def test_should_get_my_videos
297
- video = @client.video_upload(File.open("test/test.mov"), OPTIONS)
298
- assert_valid_video video
299
- result = @client.my_videos
300
- assert_equal result.videos.first.unique_id, video.unique_id
301
- @client.video_delete(video.unique_id)
302
- end
303
-
304
- def test_should_get_my_video
305
- video = @client.video_upload(File.open("test/test.mov"), OPTIONS)
306
- assert_valid_video video
307
- result = @client.my_video(video.unique_id)
308
- assert_equal result.unique_id, video.unique_id
309
- @client.video_delete(video.unique_id)
310
- end
311
-
312
- def test_should_add_like_to_video
313
- r = @client.like_video("CE62FSEoY28")
314
- assert_equal r[:code], 201
315
- @client.dislike_video("CE62FSEoY28")
316
- end
317
-
318
- def test_should_dislike_to_video
319
- @client.like_video("CE62FSEoY28")
320
- r = @client.dislike_video("CE62FSEoY28")
321
- assert_equal r[:code], 201
322
- end
323
-
324
-
325
- def test_should_subscribe_to_channel
326
- r = @client.subscribe_channel("TheWoWArthas")
327
- sleep(4)
328
- assert_equal r[:code], 201
329
- assert_equal @client.subscriptions.first.title, "Videos published by: TheWoWArthas"
330
- @client.unsubscribe_channel(@client.subscriptions.first.id)
331
- end
332
-
333
- def test_should_unsubscribe_to_channel
334
- @client.subscribe_channel("TheWoWArthas")
335
- sleep(4)
336
- r = @client.unsubscribe_channel(@client.subscriptions.first.id)
337
- assert_equal r[:code], 200
338
- end
339
-
340
- def test_should_list_subscriptions
341
- @client.subscribe_channel("TheWoWArthas")
342
- sleep(4)
343
- assert @client.subscriptions.count == 1
344
- assert_equal @client.subscriptions.first.title, "Videos published by: TheWoWArthas"
345
- @client.unsubscribe_channel(@client.subscriptions.first.id)
346
- end
347
-
348
- def test_should_get_profile
349
- profile = @client.profile
350
- assert_equal profile.username, "tubeit20101"
351
- end
352
-
353
- def test_should_add_and_delete_video_to_favorite
354
- video_id ="j5raG94IGCc"
355
- result = @client.add_favorite(video_id)
356
- assert_equal result[:code], 201
357
- sleep 4
358
- assert @client.delete_favorite(video_id)
359
- end
360
-
361
- def test_esc
362
- result = YouTubeIt.esc("спят усталые игрушки")
363
- assert result, "спят+усталые+игрушки"
364
- end
365
-
366
- def test_unicode_query
367
- videos = @client.videos_by(:query => 'спят усталые игрушки').videos
368
- assert videos.map(&:unique_id).include?("w-7BT2CFYNU")
369
- end
370
-
371
- def test_return_video_by_url
372
- video = @client.video_by("https://www.youtube.com/watch?v=EkF4JD2rO3Q")
373
- assert_valid_video video
374
- end
375
-
376
- def test_configure_faraday_adapter
377
- assert YouTubeIt.adapter == Faraday.default_adapter
378
- YouTubeIt.adapter = :net_http
379
- assert YouTubeIt.adapter == :net_http
380
- end
381
-
382
- private
383
-
384
- def assert_valid_video (video)
385
- # check general attributes
386
- assert_instance_of YouTubeIt::Model::Video, video
387
- assert_instance_of Fixnum, video.duration
388
- assert_instance_of String, video.html_content if video.html_content
389
-
390
- # validate media content records
391
- video.media_content.each do |media_content|
392
- assert_valid_url media_content.url
393
- assert_instance_of YouTubeIt::Model::Video::Format, media_content.format
394
- assert_instance_of String, media_content.mime_type
395
- assert_match(/^[^\/]+\/[^\/]+$/, media_content.mime_type)
396
- end
397
-
398
- default_content = video.default_media_content
399
- if default_content
400
- assert_instance_of YouTubeIt::Model::Content, default_content
401
- assert default_content.is_default?
402
- end
403
-
404
- # validate keywords
405
- video.keywords.each { |kw| assert_instance_of(String, kw) }
406
-
407
- # http://www.youtube.com/watch?v=IHVaXG1thXM
408
- assert_valid_url video.player_url
409
- assert_instance_of Time, video.published_at
410
-
411
- # validate optionally-present rating
412
- if video.rating
413
- assert_instance_of YouTubeIt::Model::Rating, video.rating
414
- assert_instance_of Float, video.rating.average
415
- assert_instance_of Fixnum, video.rating.max
416
- assert_instance_of Fixnum, video.rating.min
417
- assert_instance_of Fixnum, video.rating.rater_count
418
- end
419
-
420
- # validate thumbnails
421
- assert(video.thumbnails.size > 0)
422
-
423
- assert_not_nil video.title
424
- assert_instance_of String, video.title
425
- assert(video.title.length > 0)
426
-
427
- assert_instance_of Time, video.updated_at
428
- # http://gdata.youtube.com/feeds/videos/IHVaXG1thXM
429
- assert_valid_url video.unique_id
430
- assert_instance_of Fixnum, video.view_count
431
- assert_instance_of Fixnum, video.favorite_count
432
-
433
- # validate author
434
- assert_instance_of YouTubeIt::Model::Author, video.author
435
- assert_instance_of String, video.author.name
436
- assert(video.author.name.length > 0)
437
- assert_valid_url video.author.uri
438
-
439
- # validate categories
440
- video.categories.each do |cat|
441
- assert_instance_of YouTubeIt::Model::Category, cat
442
- assert_instance_of String, cat.label
443
- assert_instance_of String, cat.term
444
- end
445
- end
446
-
447
- def assert_valid_url (url)
448
- URI::parse(url)
449
- return true
450
- rescue
451
- return false
452
- end
453
- end
454
-