youtube_it 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/youtube_it/client.rb +77 -8
- data/lib/youtube_it/request/video_upload.rb +35 -9
- data/pkg/youtube_it-1.1.0.gem +0 -0
- data/youtube_it.gemspec +3 -2
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/lib/youtube_it/client.rb
CHANGED
@@ -166,7 +166,7 @@ class YouTubeIt
|
|
166
166
|
private
|
167
167
|
|
168
168
|
def client
|
169
|
-
@client ||= YouTubeIt::Upload::VideoUpload.new(@user, @pass, @dev_key)
|
169
|
+
@client ||= YouTubeIt::Upload::VideoUpload.new(:username => @user, :password => @pass, :dev_key => @dev_key)
|
170
170
|
end
|
171
171
|
|
172
172
|
def calculate_offset(page, per_page)
|
@@ -179,6 +179,74 @@ class YouTubeIt
|
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
|
+
class AuthSubClient < Client
|
183
|
+
def initialize *params
|
184
|
+
if params.first.is_a?(Hash)
|
185
|
+
hash_options = params.first
|
186
|
+
@authsub_token = hash_options[:token]
|
187
|
+
@dev_key = hash_options[:dev_key]
|
188
|
+
@client_id = hash_options[:client_id] || "youtube_it"
|
189
|
+
@legacy_debug_flag = hash_options[:debug]
|
190
|
+
else
|
191
|
+
puts "* warning: the method YouTubeIt::AuthSubClient.new(token, dev_key) is depricated, use YouTubeIt::AuthSubClient.new(:token => 'token', :dev_key => 'dev_key')"
|
192
|
+
@authsub_token = params.shift
|
193
|
+
@dev_key = params.shift
|
194
|
+
@client_id = params.shift || "youtube_it"
|
195
|
+
@legacy_debug_flag = params.shift
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def create_session_token
|
200
|
+
response = nil
|
201
|
+
session_token_url = "/accounts/AuthSubSessionToken"
|
202
|
+
|
203
|
+
http_connection do |session|
|
204
|
+
response = session.get2('https://%s' % session_token_url,session_token_header).body
|
205
|
+
end
|
206
|
+
@authsub_token = response.sub('Token=','')
|
207
|
+
end
|
208
|
+
|
209
|
+
def revoke_session_token
|
210
|
+
response = nil
|
211
|
+
session_token_url = "/accounts/AuthSubRevokeToken"
|
212
|
+
|
213
|
+
http_connection do |session|
|
214
|
+
response = session.get2('https://%s' % session_token_url,session_token_header).code
|
215
|
+
end
|
216
|
+
response.to_s == '200' ? true : false
|
217
|
+
end
|
218
|
+
|
219
|
+
def session_token_info
|
220
|
+
response = nil
|
221
|
+
session_token_url = "/accounts/AuthSubTokenInfo"
|
222
|
+
|
223
|
+
http_connection do |session|
|
224
|
+
response = session.get2('https://%s' % session_token_url,session_token_header)
|
225
|
+
end
|
226
|
+
{:code => response.code, :body => response.body }
|
227
|
+
end
|
228
|
+
|
229
|
+
private
|
230
|
+
def client
|
231
|
+
@client ||= YouTubeIt::Upload::VideoUpload.new(:dev_key => @dev_key, :authsub_token => @authsub_token)
|
232
|
+
end
|
233
|
+
|
234
|
+
def session_token_header
|
235
|
+
{
|
236
|
+
"Content-Type" => "application/x-www-form-urlencoded",
|
237
|
+
"Authorization" => "AuthSub token=#{@authsub_token}"
|
238
|
+
}
|
239
|
+
end
|
240
|
+
|
241
|
+
def http_connection
|
242
|
+
http = Net::HTTP.new("www.google.com")
|
243
|
+
http.set_debug_output(logger) if @http_debugging
|
244
|
+
http.start do |session|
|
245
|
+
yield(session)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
182
250
|
class OAuthClient < Client
|
183
251
|
def initialize *params
|
184
252
|
if params.first.is_a?(Hash)
|
@@ -191,12 +259,12 @@ class YouTubeIt
|
|
191
259
|
@legacy_debug_flag = hash_options[:debug]
|
192
260
|
else
|
193
261
|
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
|
195
|
-
@consumer_secret
|
196
|
-
@dev_key
|
197
|
-
@user
|
198
|
-
@client_id
|
199
|
-
@legacy_debug_flag
|
262
|
+
@consumer_key = params.shift
|
263
|
+
@consumer_secret = params.shift
|
264
|
+
@dev_key = params.shift
|
265
|
+
@user = params.shift
|
266
|
+
@client_id = params.shift || "youtube_it"
|
267
|
+
@legacy_debug_flag = params.shift
|
200
268
|
end
|
201
269
|
end
|
202
270
|
|
@@ -231,11 +299,12 @@ class YouTubeIt
|
|
231
299
|
REXML::Document.new(body).elements["entry"].elements['author'].elements['name'].text
|
232
300
|
end
|
233
301
|
|
302
|
+
|
234
303
|
private
|
235
304
|
|
236
305
|
def client
|
237
306
|
# IMPORTANT: make sure authorize_from_access is called before client is fetched
|
238
|
-
@client ||= YouTubeIt::Upload::VideoUpload.new(
|
307
|
+
@client ||= YouTubeIt::Upload::VideoUpload.new(:username => current_user, :dev_key => @dev_key, :acces_token => access_token)
|
239
308
|
end
|
240
309
|
|
241
310
|
end
|
@@ -16,11 +16,32 @@ class YouTubeIt
|
|
16
16
|
#
|
17
17
|
class VideoUpload
|
18
18
|
include YouTubeIt::Logging
|
19
|
-
def initialize user, pass, dev_key,
|
20
|
-
@user, @
|
19
|
+
def initialize user, pass, dev_key, access_token = nil, authsub_token = nil, client_id = 'youtube_it'
|
20
|
+
@user, @password, @dev_key, @access_token, @authsub_token, @client_id = user, pass, dev_key, access_token, authsub_token, client_id
|
21
21
|
@http_debugging = false
|
22
22
|
end
|
23
23
|
|
24
|
+
def initialize *params
|
25
|
+
if params.first.is_a?(Hash)
|
26
|
+
hash_options = params.first
|
27
|
+
@user = hash_options[:username]
|
28
|
+
@password = hash_options[:password]
|
29
|
+
@dev_key = hash_options[:dev_key]
|
30
|
+
@access_token = hash_options[:access_token]
|
31
|
+
@authsub_token = hash_options[:authsub_token]
|
32
|
+
@client_id = hash_options[:client_id] || "youtube_it"
|
33
|
+
else
|
34
|
+
puts "* warning: the method YouTubeIt::Upload::VideoUpload.new(username, password, dev_key) is depricated, use YouTubeIt::Upload::VideoUpload.new(:username => 'user', :password => 'passwd', :dev_key => 'dev_key')"
|
35
|
+
@user = params.shift
|
36
|
+
@password = params.shift
|
37
|
+
@dev_key = params.shift
|
38
|
+
@access_token = params.shift
|
39
|
+
@authsub_token = params.shift
|
40
|
+
@client_id = params.shift || "youtube_it"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
24
45
|
def enable_http_debugging
|
25
46
|
@http_debugging = true
|
26
47
|
end
|
@@ -396,12 +417,17 @@ class YouTubeIt
|
|
396
417
|
end
|
397
418
|
|
398
419
|
def authorization_headers
|
399
|
-
{
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
420
|
+
header = {
|
421
|
+
"X-GData-Client" => "#{@client_id}",
|
422
|
+
"X-GData-Key" => "key=#{@dev_key}",
|
423
|
+
"GData-Version" => "2",
|
424
|
+
}
|
425
|
+
if @authsub_token
|
426
|
+
header.merge!("Authorization" => "AuthSub token=#{@authsub_token}")
|
427
|
+
else
|
428
|
+
header.merge!("Authorization" => "GoogleLogin auth=#{auth_token}")
|
429
|
+
end
|
430
|
+
header
|
405
431
|
end
|
406
432
|
|
407
433
|
def parse_upload_error_from(string)
|
@@ -457,7 +483,7 @@ class YouTubeIt
|
|
457
483
|
@auth_token ||= begin
|
458
484
|
http = Net::HTTP.new("www.google.com", 443)
|
459
485
|
http.use_ssl = true
|
460
|
-
body = "Email=#{YouTubeIt.esc @user}&Passwd=#{YouTubeIt.esc @
|
486
|
+
body = "Email=#{YouTubeIt.esc @user}&Passwd=#{YouTubeIt.esc @password}&service=youtube&source=#{YouTubeIt.esc @client_id}"
|
461
487
|
response = http.post("/youtube/accounts/ClientLogin", body, "Content-Type" => "application/x-www-form-urlencoded")
|
462
488
|
raise UploadError, response.body[/Error=(.+)/,1] if response.code.to_i != 200
|
463
489
|
@auth_token = response.body[/Auth=(.+)/, 1]
|
Binary file
|
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 = "1.
|
8
|
+
s.version = "1.2.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-28}
|
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 = [
|
@@ -46,6 +46,7 @@ Gem::Specification.new do |s|
|
|
46
46
|
"lib/youtube_it/version.rb",
|
47
47
|
"pkg/youtube_it-0.0.8.gem",
|
48
48
|
"pkg/youtube_it-1.0.0.gem",
|
49
|
+
"pkg/youtube_it-1.1.0.gem",
|
49
50
|
"test/helper.rb",
|
50
51
|
"test/test.mov",
|
51
52
|
"test/test_chain_io.rb",
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 1.
|
9
|
+
version: 1.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- chebyte
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-28 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/youtube_it/version.rb
|
72
72
|
- pkg/youtube_it-0.0.8.gem
|
73
73
|
- pkg/youtube_it-1.0.0.gem
|
74
|
+
- pkg/youtube_it-1.1.0.gem
|
74
75
|
- test/helper.rb
|
75
76
|
- test/test.mov
|
76
77
|
- test/test_chain_io.rb
|