msp-youtube-g 0.4.8.3 → 0.4.8.4
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/lib/youtube_g.rb +1 -1
- data/lib/youtube_g/request/video_upload.rb +18 -4
- data/test/test_upload.rb +30 -5
- metadata +1 -1
data/lib/youtube_g.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
class YouTubeG
|
2
2
|
|
3
3
|
module Upload
|
4
|
+
|
5
|
+
CLIENT_LOGIN_HEADER = "GoogleLogin auth="
|
6
|
+
AUTH_SUB_HEADER = "AuthSub token="
|
7
|
+
|
4
8
|
class UploadError < Exception; end
|
5
9
|
class AuthenticationError < Exception; end
|
6
10
|
|
@@ -16,8 +20,9 @@ class YouTubeG
|
|
16
20
|
|
17
21
|
attr_accessor :auth_token
|
18
22
|
|
19
|
-
def initialize user, pass, dev_key, client_id = 'youtube_g',
|
20
|
-
@user, @pass, @dev_key, @client_id, @
|
23
|
+
def initialize user, pass, dev_key, client_id = 'youtube_g', auth_sub_token = nil
|
24
|
+
@user, @pass, @dev_key, @client_id, @auth_sub_token = user, pass, dev_key, client_id, auth_sub_token
|
25
|
+
@auth_token = @auth_sub_token != nil ? @auth_sub_token : nil
|
21
26
|
end
|
22
27
|
|
23
28
|
# TODO merge this in with logger.rb or replace logger.rb
|
@@ -63,7 +68,7 @@ class YouTubeG
|
|
63
68
|
upload_body = generate_upload_body(boundary, video_xml, data)
|
64
69
|
|
65
70
|
upload_header = {
|
66
|
-
"Authorization" =>
|
71
|
+
"Authorization" => get_auth_header,
|
67
72
|
"X-GData-Client" => "#{@client_id}",
|
68
73
|
"X-GData-Key" => "key=#{@dev_key}",
|
69
74
|
"Slug" => "#{@opts[:filename]}",
|
@@ -74,6 +79,7 @@ class YouTubeG
|
|
74
79
|
|
75
80
|
direct_upload_url = "/feeds/api/users/#{@user}/uploads"
|
76
81
|
logger.debug("direct_upload_url [#{direct_upload_url}]")
|
82
|
+
logger.debug("upload_header [#{upload_header}]")
|
77
83
|
|
78
84
|
Net::HTTP.start(base_url) do |upload|
|
79
85
|
response = upload.post(direct_upload_url, upload_body, upload_header)
|
@@ -92,7 +98,15 @@ class YouTubeG
|
|
92
98
|
end
|
93
99
|
|
94
100
|
end
|
95
|
-
|
101
|
+
|
102
|
+
def get_auth_header
|
103
|
+
logger.debug("@auth_sub_token [#{@auth_sub_token}]")
|
104
|
+
if @auth_sub_token
|
105
|
+
return YouTubeG::Upload::AUTH_SUB_HEADER+derive_auth_token
|
106
|
+
else
|
107
|
+
return YouTubeG::Upload::CLIENT_LOGIN_HEADER+derive_auth_token
|
108
|
+
end
|
109
|
+
end
|
96
110
|
|
97
111
|
private
|
98
112
|
|
data/test/test_upload.rb
CHANGED
@@ -4,9 +4,13 @@ require File.dirname(__FILE__) + '/../lib/youtube_g'
|
|
4
4
|
class TestClient < Test::Unit::TestCase
|
5
5
|
|
6
6
|
def setup
|
7
|
-
@uploader = YouTubeG::Upload::VideoUpload.new(
|
7
|
+
@uploader = YouTubeG::Upload::VideoUpload.new(@user,@pswd,@dev_key)
|
8
8
|
@uploader.auth_token = "auth_token_for_testing"
|
9
|
-
@response = nil
|
9
|
+
@response = nil
|
10
|
+
@user = "user"
|
11
|
+
@pswd = "pswd"
|
12
|
+
@dev_key = "dev_key"
|
13
|
+
@client_id = "client_id"
|
10
14
|
end
|
11
15
|
|
12
16
|
def test_logger_still_active_without_rails_default
|
@@ -18,10 +22,10 @@ class TestClient < Test::Unit::TestCase
|
|
18
22
|
end
|
19
23
|
|
20
24
|
def test_passing_auth_token_in_constructor
|
21
|
-
upload = YouTubeG::Upload::VideoUpload.new(
|
25
|
+
upload = YouTubeG::Upload::VideoUpload.new(@user,@pswd,@dev_key)
|
22
26
|
assert_nil upload.auth_token
|
23
27
|
|
24
|
-
upload = YouTubeG::Upload::VideoUpload.new(
|
28
|
+
upload = YouTubeG::Upload::VideoUpload.new(@user,@pswd,@dev_key,@client_id, :test_token)
|
25
29
|
assert_equal :test_token, upload.auth_token
|
26
30
|
end
|
27
31
|
|
@@ -47,7 +51,28 @@ class TestClient < Test::Unit::TestCase
|
|
47
51
|
assert_raise YouTubeG::Upload::UploadError do
|
48
52
|
response = @uploader.upload("a_file")
|
49
53
|
end
|
50
|
-
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_get_auth_header_for_auth_sub
|
57
|
+
token = "1234554321"
|
58
|
+
upload = YouTubeG::Upload::VideoUpload.new(@user,@pswd,@dev_key,@client_id, token)
|
59
|
+
assert_equal YouTubeG::Upload::AUTH_SUB_HEADER+token, upload.get_auth_header
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_get_auth_header_for_client_login
|
63
|
+
token = "1234554321"
|
64
|
+
# YouTubeG::Upload.module_eval do
|
65
|
+
# def derive_auth_token()
|
66
|
+
# token
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
|
70
|
+
# mock the result of derive_auth_token
|
71
|
+
upload = YouTubeG::Upload::VideoUpload.new(@user,@pswd,@dev_key,@client_id)
|
72
|
+
upload.auth_token = token
|
73
|
+
assert_equal YouTubeG::Upload::CLIENT_LOGIN_HEADER+token, upload.get_auth_header
|
74
|
+
end
|
75
|
+
|
51
76
|
|
52
77
|
# stubs
|
53
78
|
class Net::HTTPForbidden < Net::HTTPClientError # 403
|