youtube_it 0.0.8 → 1.0.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/.gitignore +1 -1
- data/Rakefile +1 -0
- data/VERSION +1 -2
- data/lib/youtube_it.rb +1 -0
- data/lib/youtube_it/client.rb +21 -5
- data/lib/youtube_it/request/video_search.rb +5 -2
- data/lib/youtube_it/request/video_upload.rb +164 -124
- data/test/test_client.rb +61 -60
- data/test/test_video_search.rb +31 -24
- data/youtube_it.gemspec +6 -2
- metadata +19 -5
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -9,6 +9,7 @@ begin
|
|
9
9
|
gem.description = %Q{Upload, delete, update, comment on youtube videos all from one gem.}
|
10
10
|
gem.email = "kylejginavan@gmail.com"
|
11
11
|
gem.homepage = "http://github.com/kylejginavan/youtube_it"
|
12
|
+
gem.add_dependency('oauth','>=0.4.4')
|
12
13
|
gem.authors = ["chebyte","kylejginavan"]
|
13
14
|
end
|
14
15
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
0.0
|
2
|
-
|
1
|
+
1.0.0
|
data/lib/youtube_it.rb
CHANGED
data/lib/youtube_it/client.rb
CHANGED
@@ -180,12 +180,28 @@ class YouTubeIt
|
|
180
180
|
end
|
181
181
|
|
182
182
|
class OAuthClient < Client
|
183
|
-
def initialize
|
184
|
-
|
183
|
+
def initialize *params
|
184
|
+
if params.first.is_a?(Hash)
|
185
|
+
hash_options = params.first
|
186
|
+
@consumer_key = hash_options[:consumer_key]
|
187
|
+
@consumer_secret = hash_options[:consumer_secret]
|
188
|
+
@user = hash_options[:username]
|
189
|
+
@dev_key = hash_options[:dev_key]
|
190
|
+
@client_id = hash_options[:client_id] || "youtube_it"
|
191
|
+
@legacy_debug_flag = hash_options[:debug]
|
192
|
+
else
|
193
|
+
puts "* warning: the method YouTubeIt::OAuthClient.new(consumer_key, consumer_secrect, dev_key) is depricated, use YouTubeIt::OAuthClient.new(:consumer_key => 'consumer key', :consumer_secret => 'consumer secret', :dev_key => 'dev_key')"
|
194
|
+
@consumer_key = params.shift
|
195
|
+
@consumer_secret = params.shift
|
196
|
+
@dev_key = params.shift
|
197
|
+
@user = params.shift
|
198
|
+
@client_id = params.shift || "youtube_it"
|
199
|
+
@legacy_debug_flag = params.shift
|
200
|
+
end
|
185
201
|
end
|
186
202
|
|
187
203
|
def consumer
|
188
|
-
@consumer ||= OAuth::Consumer.new(@consumer_key,@consumer_secret,{
|
204
|
+
@consumer ||= ::OAuth::Consumer.new(@consumer_key,@consumer_secret,{
|
189
205
|
:site=>"https://www.google.com",
|
190
206
|
:request_token_path=>"/accounts/OAuthGetRequestToken",
|
191
207
|
:authorize_path=>"/accounts/OAuthAuthorizeToken",
|
@@ -197,11 +213,11 @@ class YouTubeIt
|
|
197
213
|
end
|
198
214
|
|
199
215
|
def access_token
|
200
|
-
@access_token = OAuth::AccessToken.new(consumer, @atoken, @asecret)
|
216
|
+
@access_token = ::OAuth::AccessToken.new(consumer, @atoken, @asecret)
|
201
217
|
end
|
202
218
|
|
203
219
|
def authorize_from_request(rtoken,rsecret,verifier)
|
204
|
-
request_token = OAuth::RequestToken.new(consumer,rtoken,rsecret)
|
220
|
+
request_token = ::OAuth::RequestToken.new(consumer,rtoken,rsecret)
|
205
221
|
access_token = request_token.get_access_token({:oauth_verifier => verifier})
|
206
222
|
@atoken,@asecret = access_token.token, access_token.secret
|
207
223
|
end
|
@@ -14,6 +14,8 @@ class YouTubeIt
|
|
14
14
|
attr_reader :video_format # format (1=mobile devices)
|
15
15
|
attr_reader :racy # racy ([exclude], include)
|
16
16
|
attr_reader :author
|
17
|
+
attr_reader :lang # lt
|
18
|
+
|
17
19
|
|
18
20
|
def initialize(params={})
|
19
21
|
# Initialize our various member data to avoid warnings and so we'll
|
@@ -21,7 +23,7 @@ class YouTubeIt
|
|
21
23
|
@max_results, @order_by,
|
22
24
|
@offset, @query,
|
23
25
|
@response_format, @video_format,
|
24
|
-
@racy, @author = nil
|
26
|
+
@racy, @author, @lang = nil
|
25
27
|
@url = base_url
|
26
28
|
@dev_key = params[:dev_key] if params[:dev_key]
|
27
29
|
|
@@ -56,7 +58,8 @@ class YouTubeIt
|
|
56
58
|
'alt' => @response_format,
|
57
59
|
'format' => @video_format,
|
58
60
|
'racy' => @racy,
|
59
|
-
'author' => @author
|
61
|
+
'author' => @author,
|
62
|
+
'lr' => @lang
|
60
63
|
}
|
61
64
|
end
|
62
65
|
|
@@ -51,40 +51,38 @@ class YouTubeIt
|
|
51
51
|
# errors, containing the key and its error code.
|
52
52
|
#
|
53
53
|
# When the authentication credentials are incorrect, an AuthenticationError will be raised.
|
54
|
-
def upload
|
55
|
-
response =
|
56
|
-
@opts
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
54
|
+
def upload(data, opts = {})
|
55
|
+
response = nil
|
56
|
+
@opts = { :mime_type => 'video/mp4',
|
57
|
+
:title => '',
|
58
|
+
:description => '',
|
59
|
+
:category => '',
|
60
|
+
:keywords => [] }.merge(opts)
|
61
61
|
|
62
62
|
@opts[:filename] ||= generate_uniq_filename_from(data)
|
63
63
|
|
64
64
|
post_body_io = generate_upload_io(video_xml, data)
|
65
65
|
|
66
|
-
|
66
|
+
upload_header = {
|
67
67
|
"Slug" => "#{@opts[:filename]}",
|
68
68
|
"Content-Type" => "multipart/related; boundary=#{boundary}",
|
69
|
-
"Content-Length" => "#{post_body_io.expected_length}",
|
70
|
-
# "Transfer-Encoding" => "chunked" # We will stream instead of posting at once
|
69
|
+
"Content-Length" => "#{post_body_io.expected_length}",
|
71
70
|
}
|
72
71
|
|
73
72
|
if @access_token.nil?
|
74
|
-
|
73
|
+
upload_header.merge!(authorization_headers).delete("GData-Version")
|
75
74
|
http = Net::HTTP.new(uploads_url)
|
76
75
|
http.set_debug_output(logger) if @http_debugging
|
77
|
-
path = '/feeds/api/users
|
76
|
+
path = '/feeds/api/users/default/uploads'
|
78
77
|
http.start do | session |
|
79
|
-
|
80
|
-
post = Net::HTTP::Post.new(path, upload_headers)
|
78
|
+
post = Net::HTTP::Post.new(path, upload_header)
|
81
79
|
post.body_stream = post_body_io
|
82
80
|
response = session.request(post)
|
83
81
|
end
|
84
82
|
else
|
85
|
-
|
86
|
-
url = 'http://%s/feeds/api/users
|
87
|
-
response = @access_token.post(url, post_body_io,
|
83
|
+
upload_header.merge!(authorization_headers_for_oauth).delete("GData-Version")
|
84
|
+
url = 'http://%s/feeds/api/users/default/uploads' % uploads_url
|
85
|
+
response = @access_token.post(url, post_body_io, upload_header)
|
88
86
|
end
|
89
87
|
raise_on_faulty_response(response)
|
90
88
|
return YouTubeIt::Parser::VideoFeedParser.new(response.body).parse
|
@@ -99,18 +97,14 @@ class YouTubeIt
|
|
99
97
|
# :private
|
100
98
|
# When the authentication credentials are incorrect, an AuthenticationError will be raised.
|
101
99
|
def update(video_id, options)
|
102
|
-
response =
|
100
|
+
response = nil
|
103
101
|
@opts = options
|
104
|
-
|
105
102
|
update_body = video_xml
|
106
|
-
|
107
103
|
update_header = {
|
108
|
-
"GData-Version" => "2",
|
109
104
|
"Content-Type" => "application/atom+xml",
|
110
105
|
"Content-Length" => "#{update_body.length}",
|
111
106
|
}
|
112
|
-
|
113
|
-
update_url = "/feeds/api/users/#{@user}/uploads/#{video_id}"
|
107
|
+
update_url = "/feeds/api/users/default/uploads/%s" % video_id
|
114
108
|
|
115
109
|
if @access_token.nil?
|
116
110
|
update_header.merge!(authorization_headers)
|
@@ -118,8 +112,8 @@ class YouTubeIt
|
|
118
112
|
response = session.put(update_url, update_body, update_header)
|
119
113
|
end
|
120
114
|
else
|
121
|
-
|
122
|
-
response = @access_token.put("http
|
115
|
+
update_header.merge!(authorization_headers_for_oauth)
|
116
|
+
response = @access_token.put("http://%s%s" % [base_url,update_url], update_body, update_header)
|
123
117
|
end
|
124
118
|
|
125
119
|
raise_on_faulty_response(response)
|
@@ -128,65 +122,74 @@ class YouTubeIt
|
|
128
122
|
|
129
123
|
# Delete a video on YouTube
|
130
124
|
def delete(video_id)
|
125
|
+
response = nil
|
131
126
|
delete_header = {
|
132
127
|
"Content-Type" => "application/atom+xml; charset=UTF-8",
|
133
128
|
"Content-Length" => "0",
|
134
129
|
}
|
135
|
-
|
136
|
-
delete_url = "/feeds/api/users/#{@user}/uploads/#{video_id}"
|
130
|
+
delete_url = "/feeds/api/users/default/uploads/%s" % video_id
|
137
131
|
|
138
132
|
if @access_token.nil?
|
139
133
|
delete_header.merge!(authorization_headers)
|
140
134
|
http_connection do |session|
|
141
135
|
response = session.delete(delete_url, delete_header)
|
142
|
-
raise_on_faulty_response(response)
|
143
136
|
end
|
144
137
|
else
|
145
|
-
|
146
|
-
response = @access_token.delete("http
|
147
|
-
raise_on_faulty_response(response)
|
138
|
+
delete_header.merge!(authorization_headers_for_oauth)
|
139
|
+
response = @access_token.delete("http://%s%s" % [base_url,delete_url], delete_header)
|
148
140
|
end
|
149
|
-
|
141
|
+
raise_on_faulty_response(response)
|
150
142
|
return true
|
151
143
|
end
|
152
144
|
|
153
145
|
def get_upload_token(options, nexturl)
|
154
|
-
|
155
|
-
|
146
|
+
response = nil
|
147
|
+
@opts = options
|
156
148
|
token_body = video_xml
|
157
|
-
token_header =
|
149
|
+
token_header = {
|
158
150
|
"Content-Type" => "application/atom+xml; charset=UTF-8",
|
159
151
|
"Content-Length" => "#{token_body.length}",
|
160
|
-
}
|
152
|
+
}
|
161
153
|
token_url = "/action/GetUploadToken"
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
154
|
+
|
155
|
+
if @access_token.nil?
|
156
|
+
token_header.merge!(authorization_headers)
|
157
|
+
http_connection do |session|
|
158
|
+
response = session.post(token_url, token_body, token_header)
|
159
|
+
end
|
160
|
+
else
|
161
|
+
token_header.merge!(authorization_headers_for_oauth)
|
162
|
+
response = @access_token.post("http://%s%s" % [base_url, token_url], token_body, token_header)
|
168
163
|
end
|
164
|
+
raise_on_faulty_response(response)
|
165
|
+
return {:url => "#{response.body[/<url>(.+)<\/url>/, 1]}?nexturl=#{nexturl}",
|
166
|
+
:token => response.body[/<token>(.+)<\/token>/, 1]}
|
169
167
|
end
|
170
168
|
|
171
169
|
def add_comment(video_id, comment)
|
172
|
-
|
173
|
-
|
174
|
-
|
170
|
+
response = nil
|
171
|
+
comment_body = video_xml_for(:comment => comment)
|
172
|
+
comment_header = {
|
175
173
|
"Content-Type" => "application/atom+xml",
|
176
174
|
"Content-Length" => "#{comment_body.length}",
|
177
|
-
}
|
178
|
-
|
179
|
-
comment_url = "/feeds/api/videos/#{video_id}/comments"
|
175
|
+
}
|
176
|
+
comment_url = "/feeds/api/videos/%s/comments" % video_id
|
180
177
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
178
|
+
if @access_token.nil?
|
179
|
+
comment_header.merge!(authorization_headers)
|
180
|
+
http_connection do |session|
|
181
|
+
response = session.post(comment_url, comment_body, comment_header)
|
182
|
+
end
|
183
|
+
else
|
184
|
+
comment_header.merge!(authorization_headers_for_oauth)
|
185
|
+
response = @access_token.post("http://%s%s" % [base_url, comment_url], comment_body, comment_header)
|
185
186
|
end
|
187
|
+
raise_on_faulty_response(response)
|
188
|
+
{:code => response.code, :body => response.body}
|
186
189
|
end
|
187
190
|
|
188
191
|
def comments(video_id)
|
189
|
-
comment_url = "/feeds/api/videos
|
192
|
+
comment_url = "/feeds/api/videos/%s/comments" % video_id
|
190
193
|
http_connection do |session|
|
191
194
|
response = session.get(comment_url)
|
192
195
|
raise_on_faulty_response(response)
|
@@ -195,39 +198,50 @@ class YouTubeIt
|
|
195
198
|
end
|
196
199
|
|
197
200
|
def add_favorite(video_id)
|
201
|
+
response = nil
|
198
202
|
favorite_body = video_xml_for(:favorite => video_id)
|
199
|
-
favorite_header =
|
200
|
-
"GData-Version" => "2",
|
203
|
+
favorite_header = {
|
201
204
|
"Content-Type" => "application/atom+xml",
|
202
205
|
"Content-Length" => "#{favorite_body.length}",
|
203
|
-
}
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
206
|
+
}
|
207
|
+
favorite_url = "/feeds/api/users/default/favorites"
|
208
|
+
|
209
|
+
if @access_token.nil?
|
210
|
+
favorite_header.merge!(authorization_headers)
|
211
|
+
http_connection do |session|
|
212
|
+
response = session.post(favorite_url, favorite_body, favorite_header)
|
213
|
+
end
|
214
|
+
else
|
215
|
+
favorite_header.merge!(authorization_headers_for_oauth)
|
216
|
+
response = @access_token.post("http://%s%s" % [base_url, favorite_url], favorite_body, favorite_header)
|
211
217
|
end
|
218
|
+
raise_on_faulty_response(response)
|
219
|
+
{:code => response.code, :body => response.body}
|
212
220
|
end
|
213
221
|
|
214
222
|
def delete_favorite(video_id)
|
215
|
-
|
223
|
+
response = nil
|
224
|
+
favorite_header = {
|
216
225
|
"Content-Type" => "application/atom+xml; charset=UTF-8",
|
217
226
|
"Content-Length" => "0",
|
218
|
-
}
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
227
|
+
}
|
228
|
+
favorite_url = "/feeds/api/users/default/favorites/%s" % video_id
|
229
|
+
|
230
|
+
if @access_token.nil?
|
231
|
+
favorite_header.merge!(authorization_headers).delete("GData-Version")
|
232
|
+
http_connection do |session|
|
233
|
+
response = session.delete(favorite_url, favorite_header)
|
234
|
+
end
|
235
|
+
else
|
236
|
+
favorite_header.merge!(authorization_headers_for_oauth).delete("GData-Version")
|
237
|
+
response = @access_token.delete("http://%s%s" % [base_url, favorite_url], favorite_header)
|
226
238
|
end
|
239
|
+
raise_on_faulty_response(response)
|
240
|
+
return true
|
227
241
|
end
|
228
242
|
|
229
243
|
def playlist(playlist_id)
|
230
|
-
playlist_url = "/feeds/api/playlists
|
244
|
+
playlist_url = "/feeds/api/playlists/%s?v=2" % playlist_id
|
231
245
|
http_connection do |session|
|
232
246
|
response = session.get(playlist_url)
|
233
247
|
raise_on_faulty_response(response)
|
@@ -236,7 +250,7 @@ class YouTubeIt
|
|
236
250
|
end
|
237
251
|
|
238
252
|
def playlists
|
239
|
-
playlist_url = "/feeds/api/users
|
253
|
+
playlist_url = "/feeds/api/users/default/playlists?v=2"
|
240
254
|
http_connection do |session|
|
241
255
|
response = session.get(playlist_url)
|
242
256
|
raise_on_faulty_response(response)
|
@@ -245,89 +259,113 @@ class YouTubeIt
|
|
245
259
|
end
|
246
260
|
|
247
261
|
def add_playlist(options)
|
262
|
+
response = nil
|
248
263
|
playlist_body = video_xml_for_playlist(options)
|
249
|
-
playlist_header =
|
250
|
-
"GData-Version" => "2",
|
264
|
+
playlist_header = {
|
251
265
|
"Content-Type" => "application/atom+xml",
|
252
266
|
"Content-Length" => "#{playlist_body.length}",
|
253
|
-
}
|
254
|
-
|
255
|
-
playlist_url = "/feeds/api/users/#{@user}/playlists"
|
267
|
+
}
|
268
|
+
playlist_url = "/feeds/api/users/default/playlists"
|
256
269
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
270
|
+
if @access_token.nil?
|
271
|
+
playlist_header.merge!(authorization_headers)
|
272
|
+
http_connection do |session|
|
273
|
+
response = session.post(playlist_url, playlist_body, playlist_header)
|
274
|
+
end
|
275
|
+
else
|
276
|
+
playlist_header.merge!(authorization_headers_for_oauth)
|
277
|
+
response = @access_token.post("http://%s%s" % [base_url, playlist_url], playlist_body, playlist_header)
|
261
278
|
end
|
279
|
+
raise_on_faulty_response(response)
|
280
|
+
return YouTubeIt::Parser::PlaylistFeedParser.new(response).parse
|
262
281
|
end
|
263
282
|
|
264
283
|
def add_video_to_playlist(playlist_id, video_id)
|
284
|
+
response = nil
|
265
285
|
playlist_body = video_xml_for(:playlist => video_id)
|
266
|
-
playlist_header =
|
267
|
-
"GData-Version" => "2",
|
286
|
+
playlist_header = {
|
268
287
|
"Content-Type" => "application/atom+xml",
|
269
288
|
"Content-Length" => "#{playlist_body.length}",
|
270
|
-
}
|
271
|
-
|
272
|
-
playlist_url = "/feeds/api/playlists/#{playlist_id}"
|
289
|
+
}
|
290
|
+
playlist_url = "/feeds/api/playlists/%s" % playlist_id
|
273
291
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
292
|
+
if @access_token.nil?
|
293
|
+
playlist_header.merge!(authorization_headers)
|
294
|
+
http_connection do |session|
|
295
|
+
response = session.post(playlist_url, playlist_body, playlist_header)
|
296
|
+
end
|
297
|
+
else
|
298
|
+
playlist_header.merge!(authorization_headers_for_oauth)
|
299
|
+
response = @access_token.post("http://%s%s" % [base_url, playlist_url], playlist_body, playlist_header)
|
278
300
|
end
|
301
|
+
raise_on_faulty_response(response)
|
302
|
+
{:code => response.code, :body => response.body, :playlist_entry_id => playlist_entry_id_from_playlist(response.body)}
|
279
303
|
end
|
280
304
|
|
281
305
|
def update_playlist(playlist_id, options)
|
306
|
+
response = nil
|
282
307
|
playlist_body = video_xml_for_playlist(options)
|
283
|
-
playlist_header =
|
284
|
-
"GData-Version" => "2",
|
308
|
+
playlist_header = {
|
285
309
|
"Content-Type" => "application/atom+xml",
|
286
310
|
"Content-Length" => "#{playlist_body.length}",
|
287
|
-
}
|
288
|
-
playlist_url = "/feeds/api/users
|
311
|
+
}
|
312
|
+
playlist_url = "/feeds/api/users/default/playlists/%s" % playlist_id
|
289
313
|
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
314
|
+
if @access_token.nil?
|
315
|
+
playlist_header.merge!(authorization_headers)
|
316
|
+
http_connection do |session|
|
317
|
+
response = session.put(playlist_url, playlist_body, playlist_header)
|
318
|
+
end
|
319
|
+
else
|
320
|
+
playlist_header.merge!(authorization_headers_for_oauth)
|
321
|
+
response = @access_token.put("http://%s%s" % [base_url, playlist_url], playlist_body, playlist_header)
|
294
322
|
end
|
323
|
+
raise_on_faulty_response(response)
|
324
|
+
return YouTubeIt::Parser::PlaylistFeedParser.new(response).parse
|
295
325
|
end
|
296
326
|
|
297
|
-
|
298
327
|
def delete_video_from_playlist(playlist_id, playlist_entry_id)
|
328
|
+
response = nil
|
299
329
|
playlist_header = {
|
300
330
|
"Content-Type" => "application/atom+xml",
|
301
|
-
"GData-Version" => "2",
|
302
|
-
"X-GData-Key" => "key=#{@dev_key}",
|
303
|
-
"Authorization" => "GoogleLogin auth=#{auth_token}",
|
304
331
|
}
|
332
|
+
playlist_url = "/feeds/api/playlists/%s/%s" % [playlist_id, playlist_entry_id]
|
305
333
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
334
|
+
if @access_token.nil?
|
335
|
+
playlist_header.merge!(authorization_headers)
|
336
|
+
http_connection do |session|
|
337
|
+
response = session.delete(playlist_url, playlist_header)
|
338
|
+
end
|
339
|
+
else
|
340
|
+
playlist_header.merge!(authorization_headers_for_oauth)
|
341
|
+
response = @access_token.delete("http://%s%s" % [base_url, playlist_url], playlist_header)
|
312
342
|
end
|
343
|
+
raise_on_faulty_response(response)
|
344
|
+
return true
|
313
345
|
end
|
314
346
|
|
315
347
|
def delete_playlist(playlist_id)
|
316
|
-
|
348
|
+
response = nil
|
349
|
+
playlist_header = {
|
317
350
|
"Content-Type" => "application/atom+xml; charset=UTF-8",
|
318
|
-
|
319
|
-
|
351
|
+
}
|
352
|
+
playlist_url = "/feeds/api/users/default/playlists/%s" % playlist_id
|
320
353
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
354
|
+
if @access_token.nil?
|
355
|
+
playlist_header.merge!(authorization_headers)
|
356
|
+
http_connection do |session|
|
357
|
+
response = session.delete(playlist_url, playlist_header)
|
358
|
+
end
|
359
|
+
else
|
360
|
+
playlist_header.merge!(authorization_headers_for_oauth)
|
361
|
+
response = @access_token.delete("http://%s%s" % [base_url, playlist_url], playlist_header)
|
326
362
|
end
|
363
|
+
raise_on_faulty_response(response)
|
364
|
+
return true
|
327
365
|
end
|
328
366
|
|
329
367
|
def favorites
|
330
|
-
favorite_url = "/feeds/api/users
|
368
|
+
favorite_url = "/feeds/api/users/default/favorites"
|
331
369
|
http_connection do |session|
|
332
370
|
response = session.get(favorite_url)
|
333
371
|
raise_on_faulty_response(response)
|
@@ -349,9 +387,11 @@ class YouTubeIt
|
|
349
387
|
"An43094fu"
|
350
388
|
end
|
351
389
|
|
352
|
-
def
|
390
|
+
def authorization_headers_for_oauth
|
353
391
|
{
|
354
|
-
"X-GData-
|
392
|
+
"X-GData-Client" => "#{@client_id}",
|
393
|
+
"X-GData-Key" => "key=#{@dev_key}",
|
394
|
+
"GData-Version" => "2",
|
355
395
|
}
|
356
396
|
end
|
357
397
|
|
@@ -359,7 +399,8 @@ class YouTubeIt
|
|
359
399
|
{
|
360
400
|
"Authorization" => "GoogleLogin auth=#{auth_token}",
|
361
401
|
"X-GData-Client" => "#{@client_id}",
|
362
|
-
"X-GData-Key" => "key=#{@dev_key}"
|
402
|
+
"X-GData-Key" => "key=#{@dev_key}",
|
403
|
+
"GData-Version" => "2",
|
363
404
|
}
|
364
405
|
end
|
365
406
|
|
@@ -495,5 +536,4 @@ class YouTubeIt
|
|
495
536
|
end
|
496
537
|
end
|
497
538
|
end
|
498
|
-
end
|
499
|
-
|
539
|
+
end
|
data/test/test_client.rb
CHANGED
@@ -15,170 +15,170 @@ class TestClient < Test::Unit::TestCase
|
|
15
15
|
|
16
16
|
def test_should_respond_to_a_basic_query
|
17
17
|
response = @client.videos_by(:query => "penguin")
|
18
|
-
|
18
|
+
|
19
19
|
assert_equal "http://gdata.youtube.com/feeds/api/videos", response.feed_id
|
20
20
|
assert_equal 25, response.max_result_count
|
21
21
|
assert_equal 25, response.videos.length
|
22
22
|
assert_equal 1, response.offset
|
23
23
|
assert(response.total_result_count > 100)
|
24
24
|
assert_instance_of Time, response.updated_at
|
25
|
-
|
25
|
+
|
26
26
|
response.videos.each { |v| assert_valid_video v }
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def test_should_respond_to_a_basic_query_with_offset_and_max_results
|
30
30
|
response = @client.videos_by(:query => "penguin", :offset => 15, :max_results => 30)
|
31
|
-
|
31
|
+
|
32
32
|
assert_equal "http://gdata.youtube.com/feeds/api/videos", response.feed_id
|
33
33
|
assert_equal 30, response.max_result_count
|
34
34
|
assert_equal 30, response.videos.length
|
35
35
|
assert_equal 15, response.offset
|
36
36
|
assert(response.total_result_count > 100)
|
37
37
|
assert_instance_of Time, response.updated_at
|
38
|
-
|
38
|
+
|
39
39
|
response.videos.each { |v| assert_valid_video v }
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def test_should_respond_to_a_basic_query_with_paging
|
43
43
|
response = @client.videos_by(:query => "penguin")
|
44
44
|
assert_equal "http://gdata.youtube.com/feeds/api/videos", response.feed_id
|
45
45
|
assert_equal 25, response.max_result_count
|
46
46
|
assert_equal 1, response.offset
|
47
|
-
|
47
|
+
|
48
48
|
response = @client.videos_by(:query => "penguin", :page => 2)
|
49
49
|
assert_equal "http://gdata.youtube.com/feeds/api/videos", response.feed_id
|
50
50
|
assert_equal 25, response.max_result_count
|
51
51
|
assert_equal 26, response.offset
|
52
|
-
|
52
|
+
|
53
53
|
response2 = @client.videos_by(:query => "penguin", :page => 3)
|
54
54
|
assert_equal "http://gdata.youtube.com/feeds/api/videos", response2.feed_id
|
55
55
|
assert_equal 25, response2.max_result_count
|
56
56
|
assert_equal 51, response2.offset
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def test_should_get_videos_for_multiword_metasearch_query
|
60
60
|
response = @client.videos_by(:query => 'christina ricci')
|
61
|
-
|
61
|
+
|
62
62
|
assert_equal "http://gdata.youtube.com/feeds/api/videos", response.feed_id
|
63
63
|
assert_equal 25, response.max_result_count
|
64
64
|
assert_equal 25, response.videos.length
|
65
65
|
assert_equal 1, response.offset
|
66
66
|
assert(response.total_result_count > 100)
|
67
67
|
assert_instance_of Time, response.updated_at
|
68
|
-
|
68
|
+
|
69
69
|
response.videos.each { |v| assert_valid_video v }
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
def test_should_handle_video_not_yet_viewed
|
73
73
|
response = @client.videos_by(:query => "YnqHZDh_t2Q")
|
74
|
-
|
74
|
+
|
75
75
|
assert_equal 1, response.videos.length
|
76
76
|
response.videos.each { |v| assert_valid_video v }
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
def test_should_get_videos_for_one_tag
|
80
80
|
response = @client.videos_by(:tags => ['panther'])
|
81
81
|
response.videos.each { |v| assert_valid_video v }
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
def test_should_get_videos_for_multiple_tags
|
85
85
|
response = @client.videos_by(:tags => ['tiger', 'leopard'])
|
86
86
|
response.videos.each { |v| assert_valid_video v }
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
def test_should_get_videos_for_one_category
|
90
90
|
response = @client.videos_by(:categories => [:news])
|
91
91
|
response.videos.each { |v| assert_valid_video v }
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
def test_should_get_videos_for_multiple_categories
|
95
95
|
response = @client.videos_by(:categories => [:news, :sports])
|
96
96
|
response.videos.each { |v| assert_valid_video v }
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
# TODO: Need to do more specific checking in these tests
|
100
100
|
# Currently, if a URL is valid, and videos are found, the test passes regardless of search criteria
|
101
101
|
def test_should_get_videos_for_categories_and_tags
|
102
102
|
response = @client.videos_by(:categories => [:news, :sports], :tags => ['soccer', 'football'])
|
103
103
|
response.videos.each { |v| assert_valid_video v }
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
def test_should_get_most_viewed_videos
|
107
107
|
response = @client.videos_by(:most_viewed)
|
108
108
|
response.videos.each { |v| assert_valid_video v }
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
def test_should_get_top_rated_videos_for_today
|
112
112
|
response = @client.videos_by(:top_rated, :time => :today)
|
113
113
|
response.videos.each { |v| assert_valid_video v }
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
def test_should_get_videos_for_categories_and_tags_with_category_boolean_operators
|
117
117
|
response = @client.videos_by(:categories => { :either => [:news, :sports], :exclude => [:comedy] },
|
118
118
|
:tags => { :include => ['football'], :exclude => ['soccer'] })
|
119
119
|
response.videos.each { |v| assert_valid_video v }
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
def test_should_get_videos_for_categories_and_tags_with_tag_boolean_operators
|
123
123
|
response = @client.videos_by(:categories => { :either => [:news, :sports], :exclude => [:comedy] },
|
124
124
|
:tags => { :either => ['football', 'soccer', 'polo'] })
|
125
125
|
response.videos.each { |v| assert_valid_video v }
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
def test_should_get_videos_by_user
|
129
129
|
response = @client.videos_by(:user => 'liz')
|
130
130
|
response.videos.each { |v| assert_valid_video v }
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
def test_should_get_videos_by_user_with_pagination_and_ordering
|
134
134
|
response = @client.videos_by(:user => 'liz', :page => 2, :per_page => '2', :order_by => 'published')
|
135
135
|
response.videos.each { |v| assert_valid_video v }
|
136
136
|
assert_equal 3, response.offset
|
137
137
|
assert_equal 2, response.max_result_count
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
def test_should_get_favorite_videos_by_user
|
141
141
|
response = @client.videos_by(:favorites, :user => 'drnicwilliams')
|
142
142
|
assert_equal "http://gdata.youtube.com/feeds/api/users/drnicwilliams/favorites", response.feed_id
|
143
143
|
response.videos.each { |v| assert_valid_video v }
|
144
144
|
end
|
145
|
-
|
145
|
+
|
146
146
|
def test_should_get_videos_for_query_search_with_categories_excluded
|
147
147
|
video = @client.video_by("EkF4JD2rO3Q")
|
148
148
|
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
|
149
149
|
assert_valid_video video
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
def test_should_get_video_from_user
|
153
153
|
video = @client.video_by_user("chebyte","FQK1URcxmb4")
|
154
154
|
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
|
155
155
|
assert_valid_video video
|
156
156
|
end
|
157
|
-
|
157
|
+
|
158
158
|
def test_should_always_return_a_logger
|
159
159
|
@client = YouTubeIt::Client.new
|
160
160
|
assert_not_nil @client.logger
|
161
161
|
end
|
162
|
-
|
162
|
+
|
163
163
|
def test_should_not_bail_if_debug_is_true
|
164
164
|
assert_nothing_raised { YouTubeIt::Client.new(:debug => true) }
|
165
165
|
end
|
166
|
-
|
166
|
+
|
167
167
|
def test_should_determine_if_embeddable_video_is_embeddable
|
168
168
|
response = @client.videos_by(:query => "strongbad")
|
169
|
-
|
169
|
+
|
170
170
|
video = response.videos.first
|
171
171
|
assert video.embeddable?
|
172
172
|
end
|
173
|
-
|
173
|
+
|
174
174
|
def test_should_retrieve_video_by_id
|
175
175
|
video = @client.video_by("http://gdata.youtube.com/feeds/videos/EkF4JD2rO3Q")
|
176
176
|
assert_valid_video video
|
177
|
-
|
177
|
+
|
178
178
|
video = @client.video_by("EkF4JD2rO3Q")
|
179
179
|
assert_valid_video video
|
180
180
|
end
|
181
|
-
|
181
|
+
|
182
182
|
def test_return_upload_info_for_upload_from_browser
|
183
183
|
response = @client.upload_token(OPTIONS)
|
184
184
|
assert response.kind_of?(Hash)
|
@@ -187,13 +187,13 @@ class TestClient < Test::Unit::TestCase
|
|
187
187
|
assert v
|
188
188
|
end
|
189
189
|
end
|
190
|
-
|
190
|
+
|
191
191
|
def test_should_upload_a_video
|
192
192
|
video = @client.video_upload(File.open("test/test.mov"), OPTIONS)
|
193
193
|
assert_valid_video video
|
194
194
|
@client.video_delete(video.unique_id)
|
195
195
|
end
|
196
|
-
|
196
|
+
|
197
197
|
def test_should_update_a_video
|
198
198
|
OPTIONS[:title] = "title changed"
|
199
199
|
video = @client.video_upload(File.open("test/test.mov"), OPTIONS)
|
@@ -201,13 +201,13 @@ class TestClient < Test::Unit::TestCase
|
|
201
201
|
assert updated_video.title == "title changed"
|
202
202
|
@client.video_delete(video.unique_id)
|
203
203
|
end
|
204
|
-
|
204
|
+
|
205
205
|
def test_should_delete_video
|
206
206
|
video = @client.video_upload(File.open("test/test.mov"), OPTIONS)
|
207
207
|
assert_valid_video video
|
208
208
|
assert @client.video_delete(video.unique_id)
|
209
209
|
end
|
210
|
-
|
210
|
+
|
211
211
|
def test_should_denied_comments
|
212
212
|
video = @client.video_upload(File.open("test/test.mov"), OPTIONS.merge(:comment => "denied"))
|
213
213
|
assert_valid_video video
|
@@ -215,7 +215,7 @@ class TestClient < Test::Unit::TestCase
|
|
215
215
|
doc.css('.comments-disabled').each{|tag| assert (tag.content.strip == "All Comments\n \n Adding comments has been disabled for this video.")}
|
216
216
|
@client.video_delete(video.unique_id)
|
217
217
|
end
|
218
|
-
|
218
|
+
|
219
219
|
def test_should_denied_rate
|
220
220
|
video = @client.video_upload(File.open("test/test.mov"), OPTIONS.merge(:rate => "denied"))
|
221
221
|
assert_valid_video video
|
@@ -223,20 +223,20 @@ class TestClient < Test::Unit::TestCase
|
|
223
223
|
doc.css('#watch-like').each{|tag|; assert (tag.attributes["title"].to_s == "Ratings have been disabled for this video.")}
|
224
224
|
@client.video_delete(video.unique_id)
|
225
225
|
end
|
226
|
-
|
226
|
+
|
227
227
|
def test_should_denied_embed
|
228
228
|
video = @client.video_upload(File.open("test/test.mov"), OPTIONS.merge(:embed => "denied"))
|
229
229
|
assert video.noembed
|
230
230
|
@client.video_delete(video.unique_id)
|
231
231
|
end
|
232
|
-
|
232
|
+
|
233
233
|
def test_should_add_new_comment
|
234
234
|
video_id ="H1TrfM3xbgc"
|
235
235
|
@client.add_comment(video_id, "test comment")
|
236
236
|
comment = @client.comments(video_id)[:body]
|
237
237
|
assert comment.match(/test comment/)
|
238
238
|
end
|
239
|
-
|
239
|
+
|
240
240
|
def test_shoul_add_and_delete_video_to_favorite
|
241
241
|
video_id ="H1TrfM3xbgc"
|
242
242
|
result = @client.add_favorite(video_id)
|
@@ -244,7 +244,7 @@ class TestClient < Test::Unit::TestCase
|
|
244
244
|
sleep 4
|
245
245
|
assert @client.delete_favorite(video_id)
|
246
246
|
end
|
247
|
-
|
247
|
+
|
248
248
|
def test_should_add_and_del_video_from_playlist
|
249
249
|
playlist = @client.add_playlist(:title => "youtube_it test!", :description => "test playlist")
|
250
250
|
video = @client.add_video_to_playlist(playlist.playlist_id,"iKqJ8z1DPrQ")
|
@@ -252,35 +252,36 @@ class TestClient < Test::Unit::TestCase
|
|
252
252
|
assert @client.delete_video_from_playlist(playlist.playlist_id, video[:playlist_entry_id])
|
253
253
|
assert @client.delete_playlist(playlist.playlist_id)
|
254
254
|
end
|
255
|
-
|
255
|
+
|
256
256
|
def test_should_add_and_del_new_playlist
|
257
257
|
result = @client.add_playlist(:title => "youtube_it test!", :description => "test playlist")
|
258
258
|
assert result.title, "youtube_it test!"
|
259
|
+
sleep 4
|
259
260
|
assert @client.delete_playlist(result.playlist_id)
|
260
261
|
end
|
261
|
-
|
262
|
+
|
262
263
|
def test_should_update_playlist
|
263
264
|
playlist = @client.add_playlist(:title => "youtube_it test!", :description => "test playlist")
|
264
265
|
playlist_updated = @client.update_playlist(playlist.playlist_id, :title => "title changed")
|
265
266
|
assert_equal playlist_updated.title, "title changed"
|
266
267
|
assert @client.delete_playlist(playlist.playlist_id)
|
267
268
|
end
|
268
|
-
|
269
|
+
|
269
270
|
def test_should_determine_if_widescreen_video_is_widescreen
|
270
271
|
widescreen_id = 'QqQVll-MP3I'
|
271
|
-
|
272
|
+
|
272
273
|
video = @client.video_by(widescreen_id)
|
273
274
|
assert video.widescreen?
|
274
275
|
end
|
275
|
-
|
276
|
+
|
276
277
|
private
|
277
|
-
|
278
|
+
|
278
279
|
def assert_valid_video (video)
|
279
280
|
# check general attributes
|
280
281
|
assert_instance_of YouTubeIt::Model::Video, video
|
281
282
|
assert_instance_of Fixnum, video.duration
|
282
283
|
assert_instance_of String, video.html_content if video.html_content
|
283
|
-
|
284
|
+
|
284
285
|
# validate media content records
|
285
286
|
video.media_content.each do |media_content|
|
286
287
|
assert_valid_url media_content.url
|
@@ -288,20 +289,20 @@ class TestClient < Test::Unit::TestCase
|
|
288
289
|
assert_instance_of String, media_content.mime_type
|
289
290
|
assert_match(/^[^\/]+\/[^\/]+$/, media_content.mime_type)
|
290
291
|
end
|
291
|
-
|
292
|
+
|
292
293
|
default_content = video.default_media_content
|
293
294
|
if default_content
|
294
295
|
assert_instance_of YouTubeIt::Model::Content, default_content
|
295
296
|
assert default_content.is_default?
|
296
297
|
end
|
297
|
-
|
298
|
+
|
298
299
|
# validate keywords
|
299
300
|
video.keywords.each { |kw| assert_instance_of(String, kw) }
|
300
|
-
|
301
|
+
|
301
302
|
# http://www.youtube.com/watch?v=IHVaXG1thXM
|
302
303
|
assert_valid_url video.player_url
|
303
304
|
assert_instance_of Time, video.published_at
|
304
|
-
|
305
|
+
|
305
306
|
# validate optionally-present rating
|
306
307
|
if video.rating
|
307
308
|
assert_instance_of YouTubeIt::Model::Rating, video.rating
|
@@ -310,26 +311,26 @@ class TestClient < Test::Unit::TestCase
|
|
310
311
|
assert_instance_of Fixnum, video.rating.min
|
311
312
|
assert_instance_of Fixnum, video.rating.rater_count
|
312
313
|
end
|
313
|
-
|
314
|
+
|
314
315
|
# validate thumbnails
|
315
316
|
assert(video.thumbnails.size > 0)
|
316
|
-
|
317
|
+
|
317
318
|
assert_not_nil video.title
|
318
319
|
assert_instance_of String, video.title
|
319
320
|
assert(video.title.length > 0)
|
320
|
-
|
321
|
+
|
321
322
|
assert_instance_of Time, video.updated_at
|
322
323
|
# http://gdata.youtube.com/feeds/videos/IHVaXG1thXM
|
323
324
|
assert_valid_url video.unique_id
|
324
325
|
assert_instance_of Fixnum, video.view_count
|
325
326
|
assert_instance_of Fixnum, video.favorite_count
|
326
|
-
|
327
|
+
|
327
328
|
# validate author
|
328
329
|
assert_instance_of YouTubeIt::Model::Author, video.author
|
329
330
|
assert_instance_of String, video.author.name
|
330
331
|
assert(video.author.name.length > 0)
|
331
332
|
assert_valid_url video.author.uri
|
332
|
-
|
333
|
+
|
333
334
|
# validate categories
|
334
335
|
video.categories.each do |cat|
|
335
336
|
assert_instance_of YouTubeIt::Model::Category, cat
|
@@ -337,7 +338,7 @@ class TestClient < Test::Unit::TestCase
|
|
337
338
|
assert_instance_of String, cat.term
|
338
339
|
end
|
339
340
|
end
|
340
|
-
|
341
|
+
|
341
342
|
def assert_valid_url (url)
|
342
343
|
URI::parse(url)
|
343
344
|
return true
|
data/test/test_video_search.rb
CHANGED
@@ -6,12 +6,12 @@ class TestVideoSearch < Test::Unit::TestCase
|
|
6
6
|
request = YouTubeIt::Request::VideoSearch.new(:query => "penguin")
|
7
7
|
assert_equal "http://gdata.youtube.com/feeds/api/videos?vq=penguin", request.url
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def test_should_build_multiword_metasearch_query_url
|
11
11
|
request = YouTubeIt::Request::VideoSearch.new(:query => 'christina ricci')
|
12
12
|
assert_equal "http://gdata.youtube.com/feeds/api/videos?vq=christina+ricci", request.url
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def test_should_build_video_id_url
|
16
16
|
request = YouTubeIt::Request::VideoSearch.new(:video_id => 'T7YazwP8GtY')
|
17
17
|
assert_equal "http://gdata.youtube.com/feeds/api/videos/T7YazwP8GtY", request.url
|
@@ -21,56 +21,62 @@ class TestVideoSearch < Test::Unit::TestCase
|
|
21
21
|
request = YouTubeIt::Request::VideoSearch.new(:tags => ['panther'])
|
22
22
|
assert_equal "http://gdata.youtube.com/feeds/api/videos/-/panther/", request.url
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def test_should_build_multiple_tags_query_url
|
26
26
|
request = YouTubeIt::Request::VideoSearch.new(:tags => ['tiger', 'leopard'])
|
27
27
|
assert_equal "http://gdata.youtube.com/feeds/api/videos/-/tiger/leopard/", request.url
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def test_should_build_one_category_query_url
|
31
31
|
request = YouTubeIt::Request::VideoSearch.new(:categories => [:news])
|
32
32
|
assert_equal "http://gdata.youtube.com/feeds/api/videos/-/News/", request.url
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def test_should_build_multiple_categories_query_url
|
36
36
|
request = YouTubeIt::Request::VideoSearch.new(:categories => [:news, :sports])
|
37
37
|
assert_equal "http://gdata.youtube.com/feeds/api/videos/-/News/Sports/", request.url
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def test_should_build_categories_and_tags_query_url
|
41
41
|
request = YouTubeIt::Request::VideoSearch.new(:categories => [:news, :sports], :tags => ['soccer', 'football'])
|
42
42
|
assert_equal "http://gdata.youtube.com/feeds/api/videos/-/News/Sports/soccer/football/", request.url
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def test_should_build_categories_and_tags_url_with_max_results
|
46
46
|
request = YouTubeIt::Request::VideoSearch.new(:categories => [:music], :tags => ['classic', 'rock'], :max_results => 2)
|
47
47
|
assert_equal "http://gdata.youtube.com/feeds/api/videos/-/Music/classic/rock/?max-results=2", request.url
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def test_should_build_author_query_url
|
51
51
|
request = YouTubeIt::Request::VideoSearch.new(:author => "davidguetta")
|
52
52
|
assert_equal "http://gdata.youtube.com/feeds/api/videos?author=davidguetta", request.url
|
53
53
|
end
|
54
|
+
|
55
|
+
def test_should_build_language_query_url
|
56
|
+
request = YouTubeIt::Request::VideoSearch.new(:query => 'christina ricci', :lang => 'pt')
|
57
|
+
assert_equal "http://gdata.youtube.com/feeds/api/videos?lr=pt&vq=christina+ricci", request.url
|
58
|
+
end
|
59
|
+
|
54
60
|
# -- Standard Feeds --------------------------------------------------------------------------------
|
55
|
-
|
61
|
+
|
56
62
|
def test_should_build_url_for_most_viewed
|
57
63
|
request = YouTubeIt::Request::StandardSearch.new(:most_viewed)
|
58
|
-
assert_equal "http://gdata.youtube.com/feeds/api/standardfeeds/most_viewed", request.url
|
64
|
+
assert_equal "http://gdata.youtube.com/feeds/api/standardfeeds/most_viewed", request.url
|
59
65
|
end
|
60
|
-
|
66
|
+
|
61
67
|
def test_should_build_url_for_top_rated_for_today
|
62
68
|
request = YouTubeIt::Request::StandardSearch.new(:top_rated, :time => :today)
|
63
|
-
assert_equal "http://gdata.youtube.com/feeds/api/standardfeeds/top_rated?time=today", request.url
|
64
|
-
end
|
65
|
-
|
69
|
+
assert_equal "http://gdata.youtube.com/feeds/api/standardfeeds/top_rated?time=today", request.url
|
70
|
+
end
|
71
|
+
|
66
72
|
def test_should_build_url_for_most_viewed_offset_and_max_results_without_time
|
67
73
|
request = YouTubeIt::Request::StandardSearch.new(:top_rated, :offset => 5, :max_results => 10)
|
68
|
-
assert_equal "http://gdata.youtube.com/feeds/api/standardfeeds/top_rated?max-results=10&start-index=5", request.url
|
74
|
+
assert_equal "http://gdata.youtube.com/feeds/api/standardfeeds/top_rated?max-results=10&start-index=5", request.url
|
69
75
|
end
|
70
|
-
|
76
|
+
|
71
77
|
def test_should_build_url_for_most_viewed_offset_and_max_results_with_time
|
72
78
|
request = YouTubeIt::Request::StandardSearch.new(:top_rated, :offset => 5, :max_results => 10, :time => :today)
|
73
|
-
assert_equal "http://gdata.youtube.com/feeds/api/standardfeeds/top_rated?max-results=10&start-index=5&time=today", request.url
|
79
|
+
assert_equal "http://gdata.youtube.com/feeds/api/standardfeeds/top_rated?max-results=10&start-index=5&time=today", request.url
|
74
80
|
end
|
75
81
|
|
76
82
|
def test_should_raise_exception_for_invalid_type
|
@@ -78,9 +84,9 @@ class TestVideoSearch < Test::Unit::TestCase
|
|
78
84
|
request = YouTubeIt::Request::StandardSearch.new(:most_viewed_yo)
|
79
85
|
end
|
80
86
|
end
|
81
|
-
|
87
|
+
|
82
88
|
# -- Complex Video Queries -------------------------------------------------------------------------
|
83
|
-
|
89
|
+
|
84
90
|
def test_should_build_url_for_boolean_or_case_for_categories
|
85
91
|
request = YouTubeIt::Request::VideoSearch.new(:categories => { :either => [:news, :sports] })
|
86
92
|
assert_equal "http://gdata.youtube.com/feeds/api/videos/-/News%7CSports/", request.url
|
@@ -102,21 +108,21 @@ class TestVideoSearch < Test::Unit::TestCase
|
|
102
108
|
:tags => { :either => ['soccer', 'football', 'donkey'] })
|
103
109
|
assert_equal "http://gdata.youtube.com/feeds/api/videos/-/News%7CSports/-Comedy/soccer%7Cfootball%7Cdonkey/", request.url
|
104
110
|
end
|
105
|
-
|
111
|
+
|
106
112
|
def test_should_build_url_for_query_search_with_categories_excluded
|
107
|
-
request = YouTubeIt::Request::VideoSearch.new(:query => 'bench press',
|
113
|
+
request = YouTubeIt::Request::VideoSearch.new(:query => 'bench press',
|
108
114
|
:categories => { :exclude => [:comedy, :entertainment] },
|
109
115
|
:max_results => 10)
|
110
116
|
assert_equal "http://gdata.youtube.com/feeds/api/videos/-/-Comedy/-Entertainment/?max-results=10&vq=bench+press", request.url
|
111
117
|
end
|
112
|
-
|
118
|
+
|
113
119
|
# -- User Queries ---------------------------------------------------------------------------------
|
114
|
-
|
120
|
+
|
115
121
|
def test_should_build_url_for_videos_by_user
|
116
122
|
request = YouTubeIt::Request::UserSearch.new(:user => 'liz')
|
117
123
|
assert_equal "http://gdata.youtube.com/feeds/api/users/liz/uploads", request.url
|
118
124
|
end
|
119
|
-
|
125
|
+
|
120
126
|
def test_should_build_url_for_videos_by_user_paginate_and_order
|
121
127
|
request = YouTubeIt::Request::UserSearch.new(:user => 'liz', :offset => 20, :max_results => 10, :order_by => 'published')
|
122
128
|
assert_equal "http://gdata.youtube.com/feeds/api/users/liz/uploads?max-results=10&orderby=published&start-index=20", request.url
|
@@ -132,3 +138,4 @@ class TestVideoSearch < Test::Unit::TestCase
|
|
132
138
|
assert_equal "http://gdata.youtube.com/feeds/api/users/liz/favorites?max-results=10&start-index=20", request.url
|
133
139
|
end
|
134
140
|
end
|
141
|
+
|
data/youtube_it.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{youtube_it}
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "1.0.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["chebyte", "kylejginavan"]
|
12
|
-
s.date = %q{2010-11-
|
12
|
+
s.date = %q{2010-11-24}
|
13
13
|
s.description = %q{Upload, delete, update, comment on youtube videos all from one gem.}
|
14
14
|
s.email = %q{kylejginavan@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -44,6 +44,7 @@ Gem::Specification.new do |s|
|
|
44
44
|
"lib/youtube_it/request/video_upload.rb",
|
45
45
|
"lib/youtube_it/response/video_search.rb",
|
46
46
|
"lib/youtube_it/version.rb",
|
47
|
+
"pkg/youtube_it-0.0.8.gem",
|
47
48
|
"test/helper.rb",
|
48
49
|
"test/test.mov",
|
49
50
|
"test/test_chain_io.rb",
|
@@ -70,9 +71,12 @@ Gem::Specification.new do |s|
|
|
70
71
|
s.specification_version = 3
|
71
72
|
|
72
73
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
74
|
+
s.add_runtime_dependency(%q<oauth>, [">= 0.4.4"])
|
73
75
|
else
|
76
|
+
s.add_dependency(%q<oauth>, [">= 0.4.4"])
|
74
77
|
end
|
75
78
|
else
|
79
|
+
s.add_dependency(%q<oauth>, [">= 0.4.4"])
|
76
80
|
end
|
77
81
|
end
|
78
82
|
|
metadata
CHANGED
@@ -3,10 +3,10 @@ name: youtube_it
|
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
|
+
- 1
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 0.0.8
|
9
|
+
version: 1.0.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- chebyte
|
@@ -15,10 +15,23 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-24 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: oauth
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 4
|
31
|
+
- 4
|
32
|
+
version: 0.4.4
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
22
35
|
description: Upload, delete, update, comment on youtube videos all from one gem.
|
23
36
|
email: kylejginavan@gmail.com
|
24
37
|
executables: []
|
@@ -56,6 +69,7 @@ files:
|
|
56
69
|
- lib/youtube_it/request/video_upload.rb
|
57
70
|
- lib/youtube_it/response/video_search.rb
|
58
71
|
- lib/youtube_it/version.rb
|
72
|
+
- pkg/youtube_it-0.0.8.gem
|
59
73
|
- test/helper.rb
|
60
74
|
- test/test.mov
|
61
75
|
- test/test_chain_io.rb
|