slainer68_youtube_it 2.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.
Files changed (48) hide show
  1. data/Gemfile +10 -0
  2. data/Gemfile.lock +27 -0
  3. data/Manifest.txt +37 -0
  4. data/README.rdoc +270 -0
  5. data/Rakefile +53 -0
  6. data/VERSION +1 -0
  7. data/lib/youtube_it/chain_io.rb +76 -0
  8. data/lib/youtube_it/client.rb +447 -0
  9. data/lib/youtube_it/middleware/faraday_authheader.rb +24 -0
  10. data/lib/youtube_it/middleware/faraday_oauth.rb +21 -0
  11. data/lib/youtube_it/middleware/faraday_oauth2.rb +13 -0
  12. data/lib/youtube_it/middleware/faraday_youtubeit.rb +30 -0
  13. data/lib/youtube_it/model/activity.rb +17 -0
  14. data/lib/youtube_it/model/author.rb +13 -0
  15. data/lib/youtube_it/model/category.rb +11 -0
  16. data/lib/youtube_it/model/comment.rb +16 -0
  17. data/lib/youtube_it/model/contact.rb +19 -0
  18. data/lib/youtube_it/model/content.rb +18 -0
  19. data/lib/youtube_it/model/message.rb +12 -0
  20. data/lib/youtube_it/model/playlist.rb +11 -0
  21. data/lib/youtube_it/model/rating.rb +23 -0
  22. data/lib/youtube_it/model/subscription.rb +7 -0
  23. data/lib/youtube_it/model/thumbnail.rb +17 -0
  24. data/lib/youtube_it/model/user.rb +27 -0
  25. data/lib/youtube_it/model/video.rb +239 -0
  26. data/lib/youtube_it/parser.rb +534 -0
  27. data/lib/youtube_it/record.rb +12 -0
  28. data/lib/youtube_it/request/base_search.rb +72 -0
  29. data/lib/youtube_it/request/error.rb +15 -0
  30. data/lib/youtube_it/request/standard_search.rb +43 -0
  31. data/lib/youtube_it/request/user_search.rb +47 -0
  32. data/lib/youtube_it/request/video_search.rb +102 -0
  33. data/lib/youtube_it/request/video_upload.rb +538 -0
  34. data/lib/youtube_it/response/video_search.rb +41 -0
  35. data/lib/youtube_it/version.rb +4 -0
  36. data/lib/youtube_it.rb +83 -0
  37. data/slainer68_youtube_it.gemspec +102 -0
  38. data/test/files/recorded_response.xml +1 -0
  39. data/test/files/youtube_video_response.xml +53 -0
  40. data/test/helper.rb +9 -0
  41. data/test/test.mov +0 -0
  42. data/test/test_chain_io.rb +63 -0
  43. data/test/test_client.rb +435 -0
  44. data/test/test_field_search.rb +48 -0
  45. data/test/test_video.rb +48 -0
  46. data/test/test_video_feed_parser.rb +271 -0
  47. data/test/test_video_search.rb +141 -0
  48. metadata +172 -0
@@ -0,0 +1,41 @@
1
+ class YouTubeIt
2
+ module Response
3
+ class VideoSearch < YouTubeIt::Record
4
+ # *String*:: Unique feed identifying url.
5
+ attr_reader :feed_id
6
+
7
+ # *Fixnum*:: Number of results per page.
8
+ attr_reader :max_result_count
9
+
10
+ # *Fixnum*:: 1-based offset index into the full result set.
11
+ attr_reader :offset
12
+
13
+ # *Fixnum*:: Total number of results available for the original request.
14
+ attr_reader :total_result_count
15
+
16
+ # *Time*:: Date and time at which the feed was last updated
17
+ attr_reader :updated_at
18
+
19
+ # *Array*:: Array of YouTubeIt::Model::Video records
20
+ attr_reader :videos
21
+
22
+ def current_page
23
+ ((offset - 1) / max_result_count) + 1
24
+ end
25
+
26
+ # current_page + 1 or nil if there is no next page
27
+ def next_page
28
+ current_page < total_pages ? (current_page + 1) : nil
29
+ end
30
+
31
+ # current_page - 1 or nil if there is no previous page
32
+ def previous_page
33
+ current_page > 1 ? (current_page - 1) : nil
34
+ end
35
+
36
+ def total_pages
37
+ (total_result_count / max_result_count.to_f).ceil
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,4 @@
1
+ class YouTubeIt
2
+ VERSION = '1.4.3'
3
+ end
4
+
data/lib/youtube_it.rb ADDED
@@ -0,0 +1,83 @@
1
+ require 'logger'
2
+ require 'open-uri'
3
+ require 'net/https'
4
+ require 'digest/md5'
5
+ require 'rexml/document'
6
+ require 'builder'
7
+ require 'oauth'
8
+ require 'faraday'
9
+
10
+ class YouTubeIt
11
+
12
+ # Base error class for the extension
13
+ class Error < RuntimeError
14
+ attr_reader :code
15
+ def initialize(msg, code = 0)
16
+ super(msg)
17
+ @code = code
18
+ end
19
+ end
20
+
21
+ def self.esc(s) #:nodoc:
22
+ # URI encodes correctly Unicode characters
23
+ URI.encode(s.to_s.tr(' ','+'))
24
+ end
25
+
26
+ # Set the logger for the library
27
+ def self.logger=(any_logger)
28
+ @logger = any_logger
29
+ end
30
+
31
+ # Get the logger for the library (by default will log to STDOUT). TODO: this is where we grab the Rails logger too
32
+ def self.logger
33
+ @logger ||= create_default_logger
34
+ end
35
+
36
+ # Gets mixed into the classes to provide the logger method
37
+ module Logging #:nodoc:
38
+
39
+ # Return the base logger set for the library
40
+ def logger
41
+ YouTubeIt.logger
42
+ end
43
+ end
44
+
45
+ private
46
+ def self.create_default_logger
47
+ logger = Logger.new(STDOUT)
48
+ logger.level = Logger::DEBUG
49
+ logger
50
+ end
51
+ end
52
+
53
+ %w(
54
+ version
55
+ client
56
+ record
57
+ parser
58
+ model/author
59
+ model/category
60
+ model/comment
61
+ model/contact
62
+ model/content
63
+ model/message
64
+ model/playlist
65
+ model/rating
66
+ model/subscription
67
+ model/thumbnail
68
+ model/user
69
+ model/video
70
+ model/activity
71
+ request/base_search
72
+ request/error
73
+ request/user_search
74
+ request/standard_search
75
+ request/video_upload
76
+ request/video_search
77
+ response/video_search
78
+ middleware/faraday_authheader.rb
79
+ middleware/faraday_oauth.rb
80
+ middleware/faraday_oauth2.rb
81
+ middleware/faraday_youtubeit.rb
82
+ chain_io
83
+ ).each{|m| require File.dirname(__FILE__) + '/youtube_it/' + m }
@@ -0,0 +1,102 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
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 = "slainer68_youtube_it"
8
+ s.version = "2.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["kylejginavan", "chebyte", "mseppae", "slainer68"]
12
+ s.date = "2012-01-11"
13
+ s.description = "Upload, delete, update, comment on youtube videos all from one gem."
14
+ s.email = "slainer68@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ "Gemfile",
20
+ "Gemfile.lock",
21
+ "Manifest.txt",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/youtube_it.rb",
26
+ "lib/youtube_it/chain_io.rb",
27
+ "lib/youtube_it/client.rb",
28
+ "lib/youtube_it/middleware/faraday_authheader.rb",
29
+ "lib/youtube_it/middleware/faraday_oauth.rb",
30
+ "lib/youtube_it/middleware/faraday_oauth2.rb",
31
+ "lib/youtube_it/middleware/faraday_youtubeit.rb",
32
+ "lib/youtube_it/model/activity.rb",
33
+ "lib/youtube_it/model/author.rb",
34
+ "lib/youtube_it/model/category.rb",
35
+ "lib/youtube_it/model/comment.rb",
36
+ "lib/youtube_it/model/contact.rb",
37
+ "lib/youtube_it/model/content.rb",
38
+ "lib/youtube_it/model/message.rb",
39
+ "lib/youtube_it/model/playlist.rb",
40
+ "lib/youtube_it/model/rating.rb",
41
+ "lib/youtube_it/model/subscription.rb",
42
+ "lib/youtube_it/model/thumbnail.rb",
43
+ "lib/youtube_it/model/user.rb",
44
+ "lib/youtube_it/model/video.rb",
45
+ "lib/youtube_it/parser.rb",
46
+ "lib/youtube_it/record.rb",
47
+ "lib/youtube_it/request/base_search.rb",
48
+ "lib/youtube_it/request/error.rb",
49
+ "lib/youtube_it/request/standard_search.rb",
50
+ "lib/youtube_it/request/user_search.rb",
51
+ "lib/youtube_it/request/video_search.rb",
52
+ "lib/youtube_it/request/video_upload.rb",
53
+ "lib/youtube_it/response/video_search.rb",
54
+ "lib/youtube_it/version.rb",
55
+ "slainer68_youtube_it.gemspec",
56
+ "test/files/recorded_response.xml",
57
+ "test/files/youtube_video_response.xml",
58
+ "test/helper.rb",
59
+ "test/test.mov",
60
+ "test/test_chain_io.rb",
61
+ "test/test_client.rb",
62
+ "test/test_field_search.rb",
63
+ "test/test_video.rb",
64
+ "test/test_video_feed_parser.rb",
65
+ "test/test_video_search.rb"
66
+ ]
67
+ s.homepage = "http://github.com/slainer68/youtube_it"
68
+ s.require_paths = ["lib"]
69
+ s.rubygems_version = "1.8.11"
70
+ s.summary = "The most complete Ruby wrapper for youtube api's"
71
+
72
+ if s.respond_to? :specification_version then
73
+ s.specification_version = 3
74
+
75
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
76
+ s.add_runtime_dependency(%q<oauth>, [">= 0"])
77
+ s.add_runtime_dependency(%q<simple_oauth>, [">= 0"])
78
+ s.add_runtime_dependency(%q<faraday>, [">= 0"])
79
+ s.add_runtime_dependency(%q<builder>, [">= 0"])
80
+ s.add_runtime_dependency(%q<oauth2>, [">= 0"])
81
+ s.add_runtime_dependency(%q<faraday>, [">= 0.7.3"])
82
+ s.add_runtime_dependency(%q<builder>, [">= 0"])
83
+ else
84
+ s.add_dependency(%q<oauth>, [">= 0"])
85
+ s.add_dependency(%q<simple_oauth>, [">= 0"])
86
+ s.add_dependency(%q<faraday>, [">= 0"])
87
+ s.add_dependency(%q<builder>, [">= 0"])
88
+ s.add_dependency(%q<oauth2>, [">= 0"])
89
+ s.add_dependency(%q<faraday>, [">= 0.7.3"])
90
+ s.add_dependency(%q<builder>, [">= 0"])
91
+ end
92
+ else
93
+ s.add_dependency(%q<oauth>, [">= 0"])
94
+ s.add_dependency(%q<simple_oauth>, [">= 0"])
95
+ s.add_dependency(%q<faraday>, [">= 0"])
96
+ s.add_dependency(%q<builder>, [">= 0"])
97
+ s.add_dependency(%q<oauth2>, [">= 0"])
98
+ s.add_dependency(%q<faraday>, [">= 0.7.3"])
99
+ s.add_dependency(%q<builder>, [">= 0"])
100
+ end
101
+ end
102
+
@@ -0,0 +1 @@
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>
@@ -0,0 +1,53 @@
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 ADDED
@@ -0,0 +1,9 @@
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 ADDED
Binary file
@@ -0,0 +1,63 @@
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
@@ -0,0 +1,435 @@
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_add_and_delete_new_playlist
257
+ result = @client.add_playlist(:title => "youtube_it test4!", :description => "test playlist")
258
+ assert result.title, "youtube_it test!"
259
+ sleep 4
260
+ assert @client.delete_playlist(result.playlist_id)
261
+ end
262
+
263
+ def test_should_update_playlist
264
+ playlist = @client.add_playlist(:title => "youtube_it test!", :description => "test playlist")
265
+ playlist_updated = @client.update_playlist(playlist.playlist_id, :title => "title changed")
266
+ assert_equal playlist_updated.title, "title changed"
267
+ assert @client.delete_playlist(playlist.playlist_id)
268
+ end
269
+
270
+ def test_should_list_playlist_for_user
271
+ result = @client.playlists('chebyte')
272
+ assert result.last.title, "rock"
273
+ end
274
+
275
+ def test_should_determine_if_widescreen_video_is_widescreen
276
+ widescreen_id = 'QqQVll-MP3I'
277
+
278
+ video = @client.video_by(widescreen_id)
279
+ assert video.widescreen?
280
+ end
281
+
282
+ def test_get_current_user
283
+ assert_equal @client.current_user, 'tubeit20101'
284
+ end
285
+
286
+ def test_should_get_my_videos
287
+ video = @client.video_upload(File.open("test/test.mov"), OPTIONS)
288
+ assert_valid_video video
289
+ result = @client.my_videos
290
+ assert_equal result.videos.first.unique_id, video.unique_id
291
+ @client.video_delete(video.unique_id)
292
+ end
293
+
294
+ def test_should_get_my_video
295
+ video = @client.video_upload(File.open("test/test.mov"), OPTIONS)
296
+ assert_valid_video video
297
+ result = @client.my_video(video.unique_id)
298
+ assert_equal result.unique_id, video.unique_id
299
+ @client.video_delete(video.unique_id)
300
+ end
301
+
302
+ def test_should_add_like_to_video
303
+ r = @client.like_video("CE62FSEoY28")
304
+ assert_equal r[:code], 201
305
+ @client.dislike_video("CE62FSEoY28")
306
+ end
307
+
308
+ def test_should_dislike_to_video
309
+ @client.like_video("CE62FSEoY28")
310
+ r = @client.dislike_video("CE62FSEoY28")
311
+ assert_equal r[:code], 201
312
+ end
313
+
314
+
315
+ def test_should_subscribe_to_channel
316
+ r = @client.subscribe_channel("TheWoWArthas")
317
+ assert_equal r[:code], 201
318
+ assert_equal @client.subscriptions.first.title, "Videos published by : TheWoWArthas"
319
+ @client.unsubscribe_channel(@client.subscriptions.first.id)
320
+ end
321
+
322
+ def test_should_unsubscribe_to_channel
323
+ @client.subscribe_channel("TheWoWArthas")
324
+ r = @client.unsubscribe_channel(@client.subscriptions.first.id)
325
+ assert_equal r[:code], 200
326
+ end
327
+
328
+ def test_should_list_subscriptions
329
+ @client.subscribe_channel("TheWoWArthas")
330
+ assert @client.subscriptions.count == 1
331
+ assert_equal @client.subscriptions.first.title, "Videos published by : TheWoWArthas"
332
+ @client.unsubscribe_channel(@client.subscriptions.first.id)
333
+ end
334
+
335
+ def test_should_get_profile
336
+ profile = @client.profile
337
+ assert_equal profile.username, "tubeit20101"
338
+ end
339
+
340
+ def test_should_add_and_delete_video_to_favorite
341
+ video_id ="j5raG94IGCc"
342
+ result = @client.add_favorite(video_id)
343
+ assert_equal result[:code], 201
344
+ sleep 4
345
+ assert @client.delete_favorite(video_id)
346
+ end
347
+
348
+ def test_esc
349
+ result = YouTubeIt.esc("спят усталые игрушки")
350
+ assert result, "спят+усталые+игрушки"
351
+ end
352
+
353
+ def test_unicode_query
354
+ videos = @client.videos_by(:query => 'спят усталые игрушки').videos
355
+ assert videos.map(&:unique_id).include?("w-7BT2CFYNU")
356
+ end
357
+
358
+ def test_return_video_by_url
359
+ video = @client.video_by("https://www.youtube.com/watch?v=EkF4JD2rO3Q")
360
+ assert_valid_video video
361
+ end
362
+
363
+ private
364
+
365
+ def assert_valid_video (video)
366
+ # check general attributes
367
+ assert_instance_of YouTubeIt::Model::Video, video
368
+ assert_instance_of Fixnum, video.duration
369
+ assert_instance_of String, video.html_content if video.html_content
370
+
371
+ # validate media content records
372
+ video.media_content.each do |media_content|
373
+ assert_valid_url media_content.url
374
+ assert_instance_of YouTubeIt::Model::Video::Format, media_content.format
375
+ assert_instance_of String, media_content.mime_type
376
+ assert_match(/^[^\/]+\/[^\/]+$/, media_content.mime_type)
377
+ end
378
+
379
+ default_content = video.default_media_content
380
+ if default_content
381
+ assert_instance_of YouTubeIt::Model::Content, default_content
382
+ assert default_content.is_default?
383
+ end
384
+
385
+ # validate keywords
386
+ video.keywords.each { |kw| assert_instance_of(String, kw) }
387
+
388
+ # http://www.youtube.com/watch?v=IHVaXG1thXM
389
+ assert_valid_url video.player_url
390
+ assert_instance_of Time, video.published_at
391
+
392
+ # validate optionally-present rating
393
+ if video.rating
394
+ assert_instance_of YouTubeIt::Model::Rating, video.rating
395
+ assert_instance_of Float, video.rating.average
396
+ assert_instance_of Fixnum, video.rating.max
397
+ assert_instance_of Fixnum, video.rating.min
398
+ assert_instance_of Fixnum, video.rating.rater_count
399
+ end
400
+
401
+ # validate thumbnails
402
+ assert(video.thumbnails.size > 0)
403
+
404
+ assert_not_nil video.title
405
+ assert_instance_of String, video.title
406
+ assert(video.title.length > 0)
407
+
408
+ assert_instance_of Time, video.updated_at
409
+ # http://gdata.youtube.com/feeds/videos/IHVaXG1thXM
410
+ assert_valid_url video.unique_id
411
+ assert_instance_of Fixnum, video.view_count
412
+ assert_instance_of Fixnum, video.favorite_count
413
+
414
+ # validate author
415
+ assert_instance_of YouTubeIt::Model::Author, video.author
416
+ assert_instance_of String, video.author.name
417
+ assert(video.author.name.length > 0)
418
+ assert_valid_url video.author.uri
419
+
420
+ # validate categories
421
+ video.categories.each do |cat|
422
+ assert_instance_of YouTubeIt::Model::Category, cat
423
+ assert_instance_of String, cat.label
424
+ assert_instance_of String, cat.term
425
+ end
426
+ end
427
+
428
+ def assert_valid_url (url)
429
+ URI::parse(url)
430
+ return true
431
+ rescue
432
+ return false
433
+ end
434
+ end
435
+