youtube-g 0.4.1 → 0.4.9.9

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.
@@ -1,23 +1,41 @@
1
1
  class YouTubeG
2
2
  module Response
3
3
  class VideoSearch < YouTubeG::Record
4
- # the unique feed identifying url
5
- attr_reader :feed_id
4
+ # *String*:: Unique feed identifying url.
5
+ attr_reader :feed_id
6
6
 
7
- # the number of results per page
7
+ # *Fixnum*:: Number of results per page.
8
8
  attr_reader :max_result_count
9
9
 
10
- # the 1-based offset index into the full result set
10
+ # *Fixnum*:: 1-based offset index into the full result set.
11
11
  attr_reader :offset
12
12
 
13
- # the total number of results available for the original request
13
+ # *Fixnum*:: Total number of results available for the original request.
14
14
  attr_reader :total_result_count
15
15
 
16
- # the date and time at which the feed was last updated
16
+ # *Time*:: Date and time at which the feed was last updated
17
17
  attr_reader :updated_at
18
18
 
19
- # the list of Video records
19
+ # *Array*:: Array of YouTubeG::Model::Video records
20
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
21
39
  end
22
40
  end
23
41
  end
@@ -12,7 +12,7 @@ class TestClient < Test::Unit::TestCase
12
12
  def test_should_respond_to_a_basic_query
13
13
  response = @client.videos_by(:query => "penguin")
14
14
 
15
- assert_equal "http://gdata.youtube.com/feeds/api/videos?start-index=1&max-results=25&vq=penguin", response.feed_id
15
+ assert_equal "http://gdata.youtube.com/feeds/api/videos", response.feed_id
16
16
  assert_equal 25, response.max_result_count
17
17
  assert_equal 25, response.videos.length
18
18
  assert_equal 1, response.offset
@@ -22,10 +22,40 @@ class TestClient < Test::Unit::TestCase
22
22
  response.videos.each { |v| assert_valid_video v }
23
23
  end
24
24
 
25
+ def test_should_respond_to_a_basic_query_with_offset_and_max_results
26
+ response = @client.videos_by(:query => "penguin", :offset => 15, :max_results => 30)
27
+
28
+ assert_equal "http://gdata.youtube.com/feeds/api/videos", response.feed_id
29
+ assert_equal 30, response.max_result_count
30
+ assert_equal 30, response.videos.length
31
+ assert_equal 15, response.offset
32
+ assert(response.total_result_count > 100)
33
+ assert_instance_of Time, response.updated_at
34
+
35
+ response.videos.each { |v| assert_valid_video v }
36
+ end
37
+
38
+ def test_should_respond_to_a_basic_query_with_paging
39
+ response = @client.videos_by(:query => "penguin")
40
+ assert_equal "http://gdata.youtube.com/feeds/api/videos", response.feed_id
41
+ assert_equal 25, response.max_result_count
42
+ assert_equal 1, response.offset
43
+
44
+ response = @client.videos_by(:query => "penguin", :page => 2)
45
+ assert_equal "http://gdata.youtube.com/feeds/api/videos", response.feed_id
46
+ assert_equal 25, response.max_result_count
47
+ assert_equal 26, response.offset
48
+
49
+ response2 = @client.videos_by(:query => "penguin", :page => 3)
50
+ assert_equal "http://gdata.youtube.com/feeds/api/videos", response2.feed_id
51
+ assert_equal 25, response2.max_result_count
52
+ assert_equal 51, response2.offset
53
+ end
54
+
25
55
  def test_should_get_videos_for_multiword_metasearch_query
26
56
  response = @client.videos_by(:query => 'christina ricci')
27
57
 
28
- assert_equal "http://gdata.youtube.com/feeds/api/videos?start-index=1&max-results=25&vq=christina+ricci", response.feed_id
58
+ assert_equal "http://gdata.youtube.com/feeds/api/videos", response.feed_id
29
59
  assert_equal 25, response.max_result_count
30
60
  assert_equal 25, response.videos.length
31
61
  assert_equal 1, response.offset
@@ -35,6 +65,13 @@ class TestClient < Test::Unit::TestCase
35
65
  response.videos.each { |v| assert_valid_video v }
36
66
  end
37
67
 
68
+ def test_should_handle_video_not_yet_viewed
69
+ response = @client.videos_by(:query => "YnqHZDh_t2Q")
70
+
71
+ assert_equal 1, response.videos.length
72
+ response.videos.each { |v| assert_valid_video v }
73
+ end
74
+
38
75
  # TODO: this doesn't work because the returned feed is in an unknown format
39
76
  # def test_should_get_video_for_search_by_video_id
40
77
  # response = @client.videos_by(:video_id => "T7YazwP8GtY")
@@ -94,6 +131,13 @@ class TestClient < Test::Unit::TestCase
94
131
  response = @client.videos_by(:user => 'liz')
95
132
  response.videos.each { |v| assert_valid_video v }
96
133
  end
134
+
135
+ def test_should_get_videos_by_user_with_pagination_and_ordering
136
+ response = @client.videos_by(:user => 'liz', :page => 2, :per_page => '2', :order_by => 'published')
137
+ response.videos.each { |v| assert_valid_video v }
138
+ assert_equal 3, response.offset
139
+ assert_equal 2, response.max_result_count
140
+ end
97
141
 
98
142
  # HTTP 403 Error
99
143
  # def test_should_get_favorite_videos_by_user
@@ -102,19 +146,18 @@ class TestClient < Test::Unit::TestCase
102
146
  # end
103
147
 
104
148
  def test_should_get_videos_for_query_search_with_categories_excluded
105
- response = @client.videos_by(:query => 'bench press', :categories => { :exclude => [:comedy, :entertainment] },
106
- :max_results => 10)
107
- assert_equal "<object width=\"425\" height=\"350\">\n <param name=\"movie\" value=\"http://www.youtube.com/v/BlDWdfTAx8o\"></param>\n <param name=\"wmode\" value=\"transparent\"></param>\n <embed src=\"http://www.youtube.com/v/BlDWdfTAx8o\" type=\"application/x-shockwave-flash\" \n wmode=\"transparent\" width=\"425\" height=\"350\"></embed>\n</object>\n", response.videos.first.embed_html
108
- response.videos.each { |v| assert_valid_video v }
109
- end
110
-
111
- def test_should_be_able_to_pass_in_logger
112
- @client = YouTubeG::Client.new(Logger.new(STDOUT))
113
- assert_not_nil @client.logger
149
+ video = @client.video_by("EkF4JD2rO3Q")
150
+ assert_equal "<object width=\"425\" height=\"350\">\n <param name=\"movie\" value=\"http://www.youtube.com/v/EkF4JD2rO3Q\"></param>\n <param name=\"wmode\" value=\"transparent\"></param>\n <embed src=\"http://www.youtube.com/v/EkF4JD2rO3Q\" type=\"application/x-shockwave-flash\" \n wmode=\"transparent\" width=\"425\" height=\"350\"></embed>\n</object>\n", video.embed_html
151
+ assert_valid_video video
114
152
  end
115
153
 
116
- def test_should_create_logger_if_not_passed_in
154
+ def test_should_disable_debug_if_debug_is_set_to_false
117
155
  @client = YouTubeG::Client.new
156
+ assert_nil @client.logger
157
+ end
158
+
159
+ def test_should_enable_logger_if_debug_is_true
160
+ @client = YouTubeG::Client.new(true)
118
161
  assert_not_nil @client.logger
119
162
  end
120
163
 
@@ -122,19 +165,22 @@ class TestClient < Test::Unit::TestCase
122
165
  response = @client.videos_by(:query => "avril lavigne girlfriend")
123
166
 
124
167
  video = response.videos.first
125
- assert !video.can_embed?
168
+ assert !video.embeddable?
126
169
  end
127
170
 
128
171
  def test_should_determine_if_embeddable_video_is_embeddable
129
172
  response = @client.videos_by(:query => "strongbad")
130
173
 
131
174
  video = response.videos.first
132
- assert video.can_embed?
175
+ assert video.embeddable?
133
176
  end
134
177
 
135
178
  def test_should_retrieve_video_by_id
136
179
  video = @client.video_by("http://gdata.youtube.com/feeds/videos/EkF4JD2rO3Q")
137
180
  assert_valid_video video
181
+
182
+ video = @client.video_by("EkF4JD2rO3Q")
183
+ assert_valid_video video
138
184
  end
139
185
 
140
186
  private
@@ -5,7 +5,6 @@ require 'pp'
5
5
  require 'youtube_g'
6
6
 
7
7
  class TestVideo < Test::Unit::TestCase
8
-
9
8
  def test_should_extract_unique_id_from_video_id
10
9
  video = YouTubeG::Model::Video.new(:video_id => "http://gdata.youtube.com/feeds/videos/ZTUVgYoeN_o")
11
10
  assert_equal "ZTUVgYoeN_o", video.unique_id
@@ -15,4 +14,29 @@ class TestVideo < Test::Unit::TestCase
15
14
  video = YouTubeG::Model::Video.new(:video_id => "http://gdata.youtube.com/feeds/videos/BDqs-OZWw9o")
16
15
  assert_equal "BDqs-OZWw9o", video.unique_id
17
16
  end
17
+
18
+ def test_should_have_related_videos
19
+ video = YouTubeG::Model::Video.new(:video_id => "http://gdata.youtube.com/feeds/videos/BDqs-OZWw9o")
20
+ response = video.related
21
+
22
+ assert_equal "http://gdata.youtube.com/feeds/api/videos/BDqs-OZWw9o/related", response.feed_id
23
+ assert_equal 25, response.max_result_count
24
+ assert_equal 25, response.videos.length
25
+ assert_equal 1, response.offset
26
+ assert(response.total_result_count > 0)
27
+ assert_instance_of Time, response.updated_at
28
+ end
29
+
30
+ def test_should_have_response_videos
31
+ video = YouTubeG::Model::Video.new(:video_id => "http://gdata.youtube.com/feeds/videos/BDqs-OZWw9o")
32
+ response = video.responses
33
+
34
+ assert_equal "http://gdata.youtube.com/feeds/api/videos/BDqs-OZWw9o/responses", response.feed_id
35
+ assert_equal 25, response.max_result_count
36
+ assert_equal 25, response.videos.length
37
+ assert_equal 1, response.offset
38
+ assert(response.total_result_count > 0)
39
+ assert_instance_of Time, response.updated_at
40
+ end
41
+
18
42
  end
@@ -51,23 +51,37 @@ class TestVideoSearch < Test::Unit::TestCase
51
51
  assert_equal "http://gdata.youtube.com/feeds/api/videos/-/Music/classic/rock/?max-results=2", request.url
52
52
  end
53
53
 
54
+ def test_should_build_author_query_url
55
+ request = YouTubeG::Request::VideoSearch.new(:author => "davidguetta")
56
+ assert_equal "http://gdata.youtube.com/feeds/api/videos?author=davidguetta", request.url
57
+ end
54
58
  # -- Standard Feeds --------------------------------------------------------------------------------
55
59
 
56
60
  def test_should_build_url_for_most_viewed
57
61
  request = YouTubeG::Request::StandardSearch.new(:most_viewed)
58
62
  assert_equal "http://gdata.youtube.com/feeds/api/standardfeeds/most_viewed", request.url
59
63
  end
64
+
65
+ def test_should_build_url_for_top_rated_for_today
66
+ request = YouTubeG::Request::StandardSearch.new(:top_rated, :time => :today)
67
+ assert_equal "http://gdata.youtube.com/feeds/api/standardfeeds/top_rated?time=today", request.url
68
+ end
69
+
70
+ def test_should_build_url_for_most_viewed_offset_and_max_results_without_time
71
+ request = YouTubeG::Request::StandardSearch.new(:top_rated, :offset => 5, :max_results => 10)
72
+ assert_equal "http://gdata.youtube.com/feeds/api/standardfeeds/top_rated?max-results=10&start-index=5", request.url
73
+ end
74
+
75
+ def test_should_build_url_for_most_viewed_offset_and_max_results_with_time
76
+ request = YouTubeG::Request::StandardSearch.new(:top_rated, :offset => 5, :max_results => 10, :time => :today)
77
+ assert_equal "http://gdata.youtube.com/feeds/api/standardfeeds/top_rated?max-results=10&start-index=5&time=today", request.url
78
+ end
60
79
 
61
80
  def test_should_raise_exception_for_invalid_type
62
81
  assert_raise RuntimeError do
63
82
  request = YouTubeG::Request::StandardSearch.new(:most_viewed_yo)
64
83
  end
65
84
  end
66
-
67
- def test_should_build_url_for_top_rated_for_today
68
- request = YouTubeG::Request::StandardSearch.new(:top_rated, :time => :today)
69
- assert_equal "http://gdata.youtube.com/feeds/api/standardfeeds/top_rated?time=today", request.url
70
- end
71
85
 
72
86
  # -- Complex Video Queries -------------------------------------------------------------------------
73
87
 
@@ -97,7 +111,7 @@ class TestVideoSearch < Test::Unit::TestCase
97
111
  request = YouTubeG::Request::VideoSearch.new(:query => 'bench press',
98
112
  :categories => { :exclude => [:comedy, :entertainment] },
99
113
  :max_results => 10)
100
- assert_equal "http://gdata.youtube.com/feeds/api/videos/-/-Comedy/-Entertainment/?vq=bench+press&max-results=10", request.url
114
+ assert_equal "http://gdata.youtube.com/feeds/api/videos/-/-Comedy/-Entertainment/?max-results=10&vq=bench+press", request.url
101
115
  end
102
116
 
103
117
  # -- User Queries ---------------------------------------------------------------------------------
@@ -107,8 +121,18 @@ class TestVideoSearch < Test::Unit::TestCase
107
121
  assert_equal "http://gdata.youtube.com/feeds/api/users/liz/uploads", request.url
108
122
  end
109
123
 
124
+ def test_should_build_url_for_videos_by_user_paginate_and_order
125
+ request = YouTubeG::Request::UserSearch.new(:user => 'liz', :offset => 20, :max_results => 10, :order_by => 'published')
126
+ assert_equal "http://gdata.youtube.com/feeds/api/users/liz/uploads?max-results=10&orderby=published&start-index=20", request.url
127
+ end
128
+
110
129
  def test_should_build_url_for_favorite_videos_by_user
111
130
  request = YouTubeG::Request::UserSearch.new(:favorites, :user => 'liz')
112
131
  assert_equal "http://gdata.youtube.com/feeds/api/users/liz/favorites", request.url
113
132
  end
133
+
134
+ def test_should_build_url_for_favorite_videos_by_user_paginate
135
+ request = YouTubeG::Request::UserSearch.new(:favorites, :user => 'liz', :offset => 20, :max_results => 10)
136
+ assert_equal "http://gdata.youtube.com/feeds/api/users/liz/favorites?max-results=10&start-index=20", request.url
137
+ end
114
138
  end
@@ -0,0 +1,52 @@
1
+ spec = Gem::Specification.new do |s|
2
+ s.name = 'youtube-g'
3
+ s.version = '0.4.9.9'
4
+ s.date = '2008-09-01'
5
+ s.summary = 'An object-oriented Ruby wrapper for the YouTube GData API'
6
+ s.email = "ruby-youtube-library@googlegroups.com"
7
+ s.homepage = "http://youtube-g.rubyforge.org/"
8
+ s.description = "An object-oriented Ruby wrapper for the YouTube GData API"
9
+ s.has_rdoc = true
10
+ s.authors = ["Shane Vitarana", "Walter Korman", "Aman Gupta", "Filip H.F. Slagter"]
11
+
12
+ # ruby -rpp -e "pp Dir['**/*.*'].map"
13
+ s.files = [
14
+ "History.txt",
15
+ "lib/youtube_g/client.rb",
16
+ "lib/youtube_g/logger.rb",
17
+ "lib/youtube_g/model/author.rb",
18
+ "lib/youtube_g/model/category.rb",
19
+ "lib/youtube_g/model/contact.rb",
20
+ "lib/youtube_g/model/content.rb",
21
+ "lib/youtube_g/model/playlist.rb",
22
+ "lib/youtube_g/model/rating.rb",
23
+ "lib/youtube_g/model/thumbnail.rb",
24
+ "lib/youtube_g/model/user.rb",
25
+ "lib/youtube_g/model/video.rb",
26
+ "lib/youtube_g/parser.rb",
27
+ "lib/youtube_g/record.rb",
28
+ "lib/youtube_g/request/base_search.rb",
29
+ "lib/youtube_g/request/standard_search.rb",
30
+ "lib/youtube_g/request/user_search.rb",
31
+ "lib/youtube_g/request/video_search.rb",
32
+ "lib/youtube_g/request/video_upload.rb",
33
+ "lib/youtube_g/response/video_search.rb",
34
+ "lib/youtube_g.rb",
35
+ "Manifest.txt",
36
+ "README.txt",
37
+ "test/test_client.rb",
38
+ "test/test_video.rb",
39
+ "test/test_video_search.rb",
40
+ "TODO.txt",
41
+ "youtube-g.gemspec"
42
+ ]
43
+
44
+ s.test_files = [
45
+ "test/test_client.rb",
46
+ "test/test_video.rb",
47
+ "test/test_video_search.rb"
48
+ ]
49
+
50
+ s.rdoc_options = ["--main", "README.txt"]
51
+ s.extra_rdoc_files = ["History.txt", "README.txt"]
52
+ end
metadata CHANGED
@@ -1,41 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: youtube-g
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.4.1
7
- date: 2008-02-11 00:00:00 -06:00
8
- summary: Ruby client for the YouTube GData API
9
- require_paths:
10
- - lib
11
- email: shanev@gmail.com
12
- homepage: http://rubyforge.org/projects/youtube-g/
13
- rubyforge_project: youtube-g
14
- description: "youtube-g is a pure Ruby client for the YouTube GData API. It provides an easy way to access the latest YouTube video search results from your own programs. In comparison with the earlier Youtube search interfaces, this new API and library offers much-improved flexibility around executing complex search queries to obtain well-targeted video search results. More detail on the underlying source Google-provided API is available at: http://code.google.com/apis/youtube/overview.html == FEATURES/PROBLEMS: * Aims to be in parity with Google's YouTube GData API. Core functionality is currently present -- work is in progress to fill in the rest. == SYNOPSIS: Create a client: require 'rubygems' require 'youtube_g' client = YouTubeG::Client.new Basic queries: client.videos_by(:query => \"penguin\") client.videos_by(:tags => ['tiger', 'leopard']) client.videos_by(:categories => [:news, :sports]) client.videos_by(:categories => [:news, :sports], :tags => ['soccer', 'football']) client.videos_by(:user => 'liz') Standard feeds: client.videos_by(:most_viewed) client.videos_by(:top_rated, :time => :today) Advanced queries (with boolean operators OR (either), AND (include), NOT (exclude)): client.videos_by(:categories => { :either => [:news, :sports], :exclude => [:comedy] }, :tags => { :include => ['football'], :exclude => ['soccer'] })"
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.4.9.9
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Shane Vitarana
31
8
  - Walter Korman
32
- files:
9
+ - Aman Gupta
10
+ - Filip H.F. Slagter
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+
15
+ date: 2008-09-01 00:00:00 -07:00
16
+ default_executable:
17
+ dependencies: []
18
+
19
+ description: An object-oriented Ruby wrapper for the YouTube GData API
20
+ email: ruby-youtube-library@googlegroups.com
21
+ executables: []
22
+
23
+ extensions: []
24
+
25
+ extra_rdoc_files:
33
26
  - History.txt
34
- - Manifest.txt
35
27
  - README.txt
36
- - Rakefile
37
- - TODO.txt
38
- - lib/youtube_g.rb
28
+ files:
29
+ - History.txt
39
30
  - lib/youtube_g/client.rb
40
31
  - lib/youtube_g/logger.rb
41
32
  - lib/youtube_g/model/author.rb
@@ -49,36 +40,48 @@ files:
49
40
  - lib/youtube_g/model/video.rb
50
41
  - lib/youtube_g/parser.rb
51
42
  - lib/youtube_g/record.rb
43
+ - lib/youtube_g/request/base_search.rb
44
+ - lib/youtube_g/request/standard_search.rb
45
+ - lib/youtube_g/request/user_search.rb
52
46
  - lib/youtube_g/request/video_search.rb
47
+ - lib/youtube_g/request/video_upload.rb
53
48
  - lib/youtube_g/response/video_search.rb
49
+ - lib/youtube_g.rb
50
+ - Manifest.txt
51
+ - README.txt
54
52
  - test/test_client.rb
55
53
  - test/test_video.rb
56
54
  - test/test_video_search.rb
57
- test_files:
58
- - test/test_client.rb
59
- - test/test_video.rb
60
- - test/test_video_search.rb
55
+ - TODO.txt
56
+ - youtube-g.gemspec
57
+ has_rdoc: true
58
+ homepage: http://youtube-g.rubyforge.org/
59
+ post_install_message:
61
60
  rdoc_options:
62
61
  - --main
63
62
  - README.txt
64
- extra_rdoc_files:
65
- - History.txt
66
- - Manifest.txt
67
- - README.txt
68
- - TODO.txt
69
- executables: []
70
-
71
- extensions: []
72
-
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
73
77
  requirements: []
74
78
 
75
- dependencies:
76
- - !ruby/object:Gem::Dependency
77
- name: hoe
78
- version_requirement:
79
- version_requirements: !ruby/object:Gem::Version::Requirement
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- version: 1.5.0
84
- version:
79
+ rubyforge_project:
80
+ rubygems_version: 1.2.0
81
+ signing_key:
82
+ specification_version: 2
83
+ summary: An object-oriented Ruby wrapper for the YouTube GData API
84
+ test_files:
85
+ - test/test_client.rb
86
+ - test/test_video.rb
87
+ - test/test_video_search.rb