tmm1-youtube-g 0.4.9.1 → 0.5.0

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.
data/History.txt CHANGED
@@ -1,4 +1,6 @@
1
- == trunk
1
+ == 0.4.9.9 / 2008-09-01
2
+
3
+ * Add Geodata information (thanks Jose Galisteo)
2
4
  * Added :page and :per_page options, this allows easier usage of the will_paginate
3
5
  plugin with the library. The :offset and :max_results options are no longer available. [Daniel Insley]
4
6
  * Added ability to get video responses on the instances of the YouTube::Model::Video object. [Daniel Insley]
data/Manifest.txt ADDED
@@ -0,0 +1,28 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ TODO.txt
6
+ lib/youtube_g.rb
7
+ lib/youtube_g/client.rb
8
+ lib/youtube_g/logger.rb
9
+ lib/youtube_g/model/author.rb
10
+ lib/youtube_g/model/category.rb
11
+ lib/youtube_g/model/contact.rb
12
+ lib/youtube_g/model/content.rb
13
+ lib/youtube_g/model/playlist.rb
14
+ lib/youtube_g/model/rating.rb
15
+ lib/youtube_g/model/thumbnail.rb
16
+ lib/youtube_g/model/user.rb
17
+ lib/youtube_g/model/video.rb
18
+ lib/youtube_g/parser.rb
19
+ lib/youtube_g/record.rb
20
+ lib/youtube_g/request/base_search.rb
21
+ lib/youtube_g/request/standard_search.rb
22
+ lib/youtube_g/request/user_search.rb
23
+ lib/youtube_g/request/video_search.rb
24
+ lib/youtube_g/request/video_upload.rb
25
+ lib/youtube_g/response/video_search.rb
26
+ test/test_client.rb
27
+ test/test_video.rb
28
+ test/test_video_search.rb
data/README.txt CHANGED
@@ -37,6 +37,7 @@ Basic queries:
37
37
  client.videos_by(:categories => [:news, :sports])
38
38
  client.videos_by(:categories => [:news, :sports], :tags => ['soccer', 'football'])
39
39
  client.videos_by(:user => 'liz')
40
+ client.videos_by(:favorites, :user => 'liz')
40
41
 
41
42
  Standard feeds:
42
43
 
data/lib/youtube_g.rb CHANGED
@@ -25,5 +25,5 @@ require File.dirname(__FILE__) + '/youtube_g/request/video_search'
25
25
  require File.dirname(__FILE__) + '/youtube_g/response/video_search'
26
26
 
27
27
  class YouTubeG #:nodoc:
28
- VERSION = '0.4.5'
28
+ VERSION = '0.5.0'
29
29
  end
@@ -35,10 +35,10 @@ class YouTubeG
35
35
  # YouTubeG::Response::VideoSearch
36
36
  def videos_by(params, options={})
37
37
  request_params = params.respond_to?(:to_hash) ? params : options
38
- request_params[:page] ||= 1
38
+ request_params[:page] = integer_or_default(request_params[:page], 1)
39
39
 
40
40
  unless request_params[:max_results]
41
- request_params[:max_results] = request_params[:per_page] || 25
41
+ request_params[:max_results] = integer_or_default(request_params[:per_page], 25)
42
42
  end
43
43
 
44
44
  unless request_params[:offset]
@@ -48,7 +48,7 @@ class YouTubeG
48
48
  if params.respond_to?(:to_hash) and not params[:user]
49
49
  request = YouTubeG::Request::VideoSearch.new(request_params)
50
50
  elsif (params.respond_to?(:to_hash) && params[:user]) || (params == :favorites)
51
- request = YouTubeG::Request::UserSearch.new(request_params, options)
51
+ request = YouTubeG::Request::UserSearch.new(params, request_params)
52
52
  else
53
53
  request = YouTubeG::Request::StandardSearch.new(params, request_params)
54
54
  end
@@ -77,5 +77,9 @@ class YouTubeG
77
77
  page == 1 ? 1 : ((per_page * page) - per_page + 1)
78
78
  end
79
79
 
80
+ def integer_or_default(value, default)
81
+ value = value.to_i
82
+ value > 0 ? value : default
83
+ end
80
84
  end
81
85
  end
@@ -108,6 +108,12 @@ class YouTubeG
108
108
 
109
109
  # *Fixnum*:: Number of times that the video has been viewed
110
110
  attr_reader :view_count
111
+
112
+ # Geodata
113
+ attr_reader :where
114
+ attr_reader :position
115
+ attr_reader :latitude
116
+ attr_reader :longitude
111
117
 
112
118
  attr_reader :statistics
113
119
 
@@ -91,6 +91,11 @@ class YouTubeG
91
91
  noembed = entry.elements["yt:noembed"] ? true : false
92
92
  racy = entry.elements["media:rating"] ? true : false
93
93
 
94
+ if where = entry.elements["georss:where"]
95
+ position = where.elements["gml:Point"].elements["gml:pos"].text
96
+ latitude, longitude = position.split(" ")
97
+ end
98
+
94
99
  YouTubeG::Model::Video.new(
95
100
  :video_id => video_id,
96
101
  :published_at => published_at,
@@ -108,7 +113,11 @@ class YouTubeG
108
113
  :rating => rating,
109
114
  :view_count => view_count,
110
115
  :noembed => noembed,
111
- :racy => racy)
116
+ :racy => racy,
117
+ :where => where,
118
+ :position => position,
119
+ :latitude => latitude,
120
+ :longitude => longitude)
112
121
  end
113
122
 
114
123
  def parse_media_content (media_content_element)
@@ -24,7 +24,7 @@ class YouTubeG
24
24
  # pair for which the value is non-nil
25
25
  u = '?'
26
26
  item_count = 0
27
- params.keys.each do |key|
27
+ params.keys.sort.each do |key|
28
28
  value = params[key]
29
29
  next if value.nil?
30
30
 
@@ -1,10 +1,27 @@
1
1
  class YouTubeG
2
2
  module Request #:nodoc:
3
3
  class UserSearch < BaseSearch #:nodoc:
4
+ attr_reader :max_results # max_results
5
+ attr_reader :order_by # orderby, ([relevance], viewCount, published, rating)
6
+ attr_reader :offset # start-index
7
+
4
8
  def initialize(params, options={})
9
+ @max_results, @order_by, @offset = nil
5
10
  @url = base_url
6
- return @url << "#{options[:user]}/favorites" if params == :favorites
7
- @url << "#{params[:user]}/uploads" if params[:user]
11
+
12
+ if params == :favorites
13
+ @url << "#{options[:user]}/favorites"
14
+ set_instance_variables(options)
15
+ elsif params[:user] && options[:favorites]
16
+ @url << "#{params[:user]}/favorites"
17
+ set_instance_variables(params)
18
+ break
19
+ elsif params[:user]
20
+ @url << "#{params[:user]}/uploads"
21
+ set_instance_variables(params)
22
+ end
23
+
24
+ @url << build_query_params(to_youtube_params)
8
25
  end
9
26
 
10
27
  private
@@ -12,6 +29,14 @@ class YouTubeG
12
29
  def base_url #:nodoc:
13
30
  super << "users/"
14
31
  end
32
+
33
+ def to_youtube_params #:nodoc:
34
+ {
35
+ 'max-results' => @max_results,
36
+ 'orderby' => @order_by,
37
+ 'start-index' => @offset
38
+ }
39
+ end
15
40
  end
16
41
 
17
42
  end
@@ -18,6 +18,24 @@ class YouTubeG
18
18
 
19
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
data/test/test_client.rb CHANGED
@@ -52,7 +52,6 @@ class TestClient < Test::Unit::TestCase
52
52
  assert_equal 51, response2.offset
53
53
  end
54
54
 
55
-
56
55
  def test_should_get_videos_for_multiword_metasearch_query
57
56
  response = @client.videos_by(:query => 'christina ricci')
58
57
 
@@ -132,6 +131,13 @@ class TestClient < Test::Unit::TestCase
132
131
  response = @client.videos_by(:user => 'liz')
133
132
  response.videos.each { |v| assert_valid_video v }
134
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
135
141
 
136
142
  # HTTP 403 Error
137
143
  # def test_should_get_favorite_videos_by_user
@@ -139,6 +145,12 @@ class TestClient < Test::Unit::TestCase
139
145
  # response.videos.each { |v| assert_valid_video v }
140
146
  # end
141
147
 
148
+ def test_should_get_favorite_videos_by_user
149
+ response = @client.videos_by(:favorites, :user => 'drnicwilliams')
150
+ assert_equal "http://gdata.youtube.com/feeds/api/users/drnicwilliams/favorites", response.feed_id
151
+ response.videos.each { |v| assert_valid_video v }
152
+ end
153
+
142
154
  def test_should_get_videos_for_query_search_with_categories_excluded
143
155
  video = @client.video_by("EkF4JD2rO3Q")
144
156
  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
@@ -74,7 +74,7 @@ class TestVideoSearch < Test::Unit::TestCase
74
74
 
75
75
  def test_should_build_url_for_most_viewed_offset_and_max_results_with_time
76
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?time=today&max-results=10&start-index=5", request.url
77
+ assert_equal "http://gdata.youtube.com/feeds/api/standardfeeds/top_rated?max-results=10&start-index=5&time=today", request.url
78
78
  end
79
79
 
80
80
  def test_should_raise_exception_for_invalid_type
@@ -111,7 +111,7 @@ class TestVideoSearch < Test::Unit::TestCase
111
111
  request = YouTubeG::Request::VideoSearch.new(:query => 'bench press',
112
112
  :categories => { :exclude => [:comedy, :entertainment] },
113
113
  :max_results => 10)
114
- 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
115
115
  end
116
116
 
117
117
  # -- User Queries ---------------------------------------------------------------------------------
@@ -121,8 +121,18 @@ class TestVideoSearch < Test::Unit::TestCase
121
121
  assert_equal "http://gdata.youtube.com/feeds/api/users/liz/uploads", request.url
122
122
  end
123
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
+
124
129
  def test_should_build_url_for_favorite_videos_by_user
125
130
  request = YouTubeG::Request::UserSearch.new(:favorites, :user => 'liz')
126
131
  assert_equal "http://gdata.youtube.com/feeds/api/users/liz/favorites", request.url
127
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
128
138
  end
data/youtube-g.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'youtube-g'
3
- s.version = '0.4.9.1'
4
- s.date = '2008-06-08'
3
+ s.version = '0.5.0'
4
+ s.date = '2009-01-07'
5
5
  s.summary = 'An object-oriented Ruby wrapper for the YouTube GData API'
6
6
  s.email = "ruby-youtube-library@googlegroups.com"
7
7
  s.homepage = "http://youtube-g.rubyforge.org/"
@@ -12,32 +12,33 @@ spec = Gem::Specification.new do |s|
12
12
  # ruby -rpp -e "pp Dir['**/*.*'].map"
13
13
  s.files = [
14
14
  "History.txt",
15
- "README.txt",
16
- "TODO.txt",
17
- "lib/youtube_g/client.rb",
18
- "lib/youtube_g/logger.rb",
19
- "lib/youtube_g/model/author.rb",
20
- "lib/youtube_g/model/category.rb",
21
- "lib/youtube_g/model/contact.rb",
22
- "lib/youtube_g/model/content.rb",
23
- "lib/youtube_g/model/playlist.rb",
24
- "lib/youtube_g/model/rating.rb",
25
- "lib/youtube_g/model/thumbnail.rb",
26
- "lib/youtube_g/model/user.rb",
27
- "lib/youtube_g/model/video.rb",
28
- "lib/youtube_g/parser.rb",
29
- "lib/youtube_g/record.rb",
30
- "lib/youtube_g/request/base_search.rb",
31
- "lib/youtube_g/request/standard_search.rb",
32
- "lib/youtube_g/request/user_search.rb",
33
- "lib/youtube_g/request/video_search.rb",
34
- "lib/youtube_g/request/video_upload.rb",
35
- "lib/youtube_g/response/video_search.rb",
36
- "lib/youtube_g.rb",
37
- "test/test_client.rb",
38
- "test/test_video.rb",
39
- "test/test_video_search.rb",
40
- "youtube-g.gemspec"
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"
41
42
  ]
42
43
 
43
44
  s.test_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tmm1-youtube-g
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Vitarana
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2008-06-08 00:00:00 -07:00
15
+ date: 2009-01-07 00:00:00 -08:00
16
16
  default_executable:
17
17
  dependencies: []
18
18
 
@@ -27,8 +27,6 @@ extra_rdoc_files:
27
27
  - README.txt
28
28
  files:
29
29
  - History.txt
30
- - README.txt
31
- - TODO.txt
32
30
  - lib/youtube_g/client.rb
33
31
  - lib/youtube_g/logger.rb
34
32
  - lib/youtube_g/model/author.rb
@@ -49,9 +47,12 @@ files:
49
47
  - lib/youtube_g/request/video_upload.rb
50
48
  - lib/youtube_g/response/video_search.rb
51
49
  - lib/youtube_g.rb
50
+ - Manifest.txt
51
+ - README.txt
52
52
  - test/test_client.rb
53
53
  - test/test_video.rb
54
54
  - test/test_video_search.rb
55
+ - TODO.txt
55
56
  - youtube-g.gemspec
56
57
  has_rdoc: true
57
58
  homepage: http://youtube-g.rubyforge.org/