gdata 0.0.1 → 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/README +31 -5
- data/Rakefile +8 -8
- data/lib/gdata.rb +4 -1
- data/lib/gdata/auth/authsub.rb +1 -5
- data/lib/gdata/auth/clientlogin.rb +11 -11
- data/lib/gdata/client.rb +15 -1
- data/lib/gdata/client/apps.rb +27 -0
- data/lib/gdata/client/{gdata.rb → base.rb} +42 -26
- data/lib/gdata/client/blogger.rb +28 -0
- data/lib/gdata/client/booksearch.rb +28 -0
- data/lib/gdata/client/calendar.rb +28 -0
- data/lib/gdata/client/contacts.rb +28 -0
- data/lib/gdata/client/doclist.rb +28 -0
- data/lib/gdata/client/finance.rb +28 -0
- data/lib/gdata/client/gbase.rb +28 -0
- data/lib/gdata/client/gmail.rb +28 -0
- data/lib/gdata/client/health.rb +28 -0
- data/lib/gdata/client/notebook.rb +28 -0
- data/lib/gdata/client/photos.rb +29 -0
- data/lib/gdata/client/spreadsheets.rb +28 -0
- data/lib/gdata/client/webmaster_tools.rb +28 -0
- data/lib/gdata/client/youtube.rb +4 -7
- data/lib/gdata/http.rb +1 -0
- data/lib/gdata/http/default_service.rb +22 -4
- data/lib/gdata/http/mime_body.rb +95 -0
- data/lib/gdata/http/request.rb +5 -7
- data/lib/gdata/http/response.rb +13 -0
- data/test/tc_gdata_auth_clientlogin.rb +13 -0
- data/test/tc_gdata_client_base.rb +9 -1
- data/test/tc_gdata_client_photos.rb +65 -0
- data/test/tc_gdata_client_youtube.rb +5 -4
- data/test/tc_gdata_http_mime_body.rb +46 -0
- data/test/test_helper.rb +1 -1
- data/test/testimage.jpg +0 -0
- data/test/ts_gdata.rb +11 -0
- data/test/ts_gdata_client.rb +2 -0
- data/test/ts_gdata_http.rb +2 -0
- metadata +21 -3
data/lib/gdata/http/request.rb
CHANGED
@@ -18,11 +18,6 @@ module GData
|
|
18
18
|
|
19
19
|
# Very simple class to hold everything about an HTTP request.
|
20
20
|
class Request
|
21
|
-
|
22
|
-
DEFAULT_OPTIONS = {
|
23
|
-
:body => '',
|
24
|
-
:method => :get,
|
25
|
-
:headers => {} }
|
26
21
|
|
27
22
|
# The URL of the request.
|
28
23
|
attr_accessor :url
|
@@ -36,10 +31,12 @@ module GData
|
|
36
31
|
# Only the URL itself is required, everything else is optional.
|
37
32
|
def initialize(url, options = {})
|
38
33
|
@url = url
|
39
|
-
options = DEFAULT_OPTIONS.merge(options)
|
40
34
|
options.each do |key, value|
|
41
35
|
self.send("#{key}=", value)
|
42
36
|
end
|
37
|
+
|
38
|
+
@method ||= :get
|
39
|
+
@headers ||= {}
|
43
40
|
end
|
44
41
|
|
45
42
|
# Returns whether or not a request is chunked.
|
@@ -62,7 +59,8 @@ module GData
|
|
62
59
|
|
63
60
|
# Calculates and sets the length of the body.
|
64
61
|
def calculate_length!
|
65
|
-
if not @headers['Content-Length'] and not chunked?
|
62
|
+
if not @headers['Content-Length'] and not chunked? \
|
63
|
+
and method != :get and method != :delete
|
66
64
|
if @body
|
67
65
|
@headers['Content-Length'] = @body.length
|
68
66
|
else
|
data/lib/gdata/http/response.rb
CHANGED
@@ -24,6 +24,19 @@ module GData
|
|
24
24
|
attr_accessor :body
|
25
25
|
# The headers of the HTTP response.
|
26
26
|
attr_accessor :headers
|
27
|
+
|
28
|
+
# Converts the response body into a REXML::Document
|
29
|
+
def to_xml
|
30
|
+
if @body
|
31
|
+
begin
|
32
|
+
return REXML::Document.new(@body).root
|
33
|
+
rescue
|
34
|
+
raise RuntimeError, "Response body not XML."
|
35
|
+
end
|
36
|
+
else
|
37
|
+
return nil
|
38
|
+
end
|
39
|
+
end
|
27
40
|
end
|
28
41
|
end
|
29
42
|
end
|
@@ -34,5 +34,18 @@ class TC_GData_Auth_ClientLogin < Test::Unit::TestCase
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
def test_all_clients
|
38
|
+
source = 'GDataUnitTest'
|
39
|
+
GData::Client.constants.each do |const_name|
|
40
|
+
const = GData::Client.const_get(const_name)
|
41
|
+
if const.superclass == GData::Client::Base
|
42
|
+
instance = const.new
|
43
|
+
assert_nothing_raised do
|
44
|
+
instance.clientlogin(self.get_username(), self.get_password(), source)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
37
50
|
|
38
51
|
end
|
@@ -21,7 +21,15 @@ class TC_GData_Client_Base < Test::Unit::TestCase
|
|
21
21
|
|
22
22
|
def test_simple_gdata_get
|
23
23
|
service = GData::Client::Base.new
|
24
|
-
feed = service.get('http://gdata.youtube.com/feeds/base/videos?max-results=1')
|
24
|
+
feed = service.get('http://gdata.youtube.com/feeds/base/videos?max-results=1').to_xml
|
25
|
+
assert_not_nil(feed, 'feed can not be nil')
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_clientlogin_with_service
|
29
|
+
service = GData::Client::Base.new
|
30
|
+
service.clientlogin(self.get_username(), self.get_password(), nil, nil,
|
31
|
+
'youtube')
|
32
|
+
feed = service.get('http://gdata.youtube.com/feeds/api/users/default/uploads?max-results=1').to_xml
|
25
33
|
assert_not_nil(feed, 'feed can not be nil')
|
26
34
|
end
|
27
35
|
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Copyright (C) 2008 Google Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
$:.unshift(File.dirname(__FILE__))
|
16
|
+
require 'test_helper'
|
17
|
+
|
18
|
+
class TC_GData_Client_Photos < Test::Unit::TestCase
|
19
|
+
|
20
|
+
include TestHelper
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@gp = GData::Client::Photos.new
|
24
|
+
@gp.source = 'Ruby Client Unit Tests'
|
25
|
+
@gp.clientlogin(self.get_username(), self.get_password())
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_authenticated_dropbox_feed
|
29
|
+
feed = @gp.get('http://picasaweb.google.com/data/feed/api/user/default/albumid/default?max-results=1').to_xml
|
30
|
+
self.assert_not_nil(feed, 'feed can not be nil')
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_photo_upload
|
34
|
+
test_image = File.join(File.dirname(__FILE__), 'testimage.jpg')
|
35
|
+
mime_type = 'image/jpeg'
|
36
|
+
|
37
|
+
response = @gp.post_file('http://picasaweb.google.com/data/feed/api/user/default/albumid/default',
|
38
|
+
test_image, mime_type).to_xml
|
39
|
+
|
40
|
+
edit_uri = response.elements["link[@rel='edit']"].attributes['href']
|
41
|
+
|
42
|
+
@gp.delete(edit_uri)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_photo_upload_with_metadata
|
46
|
+
test_image = File.join(File.dirname(__FILE__), 'testimage.jpg')
|
47
|
+
mime_type = 'image/jpeg'
|
48
|
+
|
49
|
+
entry = <<-EOF
|
50
|
+
<entry xmlns='http://www.w3.org/2005/Atom'>
|
51
|
+
<title>ruby-client-testing.jpg</title>
|
52
|
+
<summary>Test case for Ruby Client Library.</summary>
|
53
|
+
<category scheme="http://schemas.google.com/g/2005#kind"
|
54
|
+
term="http://schemas.google.com/photos/2007#photo"/>
|
55
|
+
</entry>
|
56
|
+
EOF
|
57
|
+
|
58
|
+
response = @gp.post_file('http://picasaweb.google.com/data/feed/api/user/default/albumid/default',
|
59
|
+
test_image, mime_type, entry).to_xml
|
60
|
+
|
61
|
+
edit_uri = response.elements["link[@rel='edit']"].attributes['href']
|
62
|
+
|
63
|
+
@gp.delete(edit_uri)
|
64
|
+
end
|
65
|
+
end
|
@@ -21,6 +21,7 @@ class TC_GData_Client_YouTube < Test::Unit::TestCase
|
|
21
21
|
|
22
22
|
def setup
|
23
23
|
@yt = GData::Client::YouTube.new
|
24
|
+
self.assert(@yt.headers.empty?, 'headers should be empty.')
|
24
25
|
@yt.clientlogin(self.get_username(), self.get_password())
|
25
26
|
@yt.client_id = 'ytapi-Google-GDataUnitTests-lcqr3u89-1'
|
26
27
|
@yt.developer_key = 'AI39si4vwXwDLR5MrtsdR1ULUD8__EnEccla-0bnqV40KpeFDIyCwEv0VJqZKHUsO3MvVM_bXHp3cAr55HmMYMhqfxzLMUgDXA'
|
@@ -29,7 +30,7 @@ class TC_GData_Client_YouTube < Test::Unit::TestCase
|
|
29
30
|
def test_authenticated_uploads_feed
|
30
31
|
|
31
32
|
|
32
|
-
feed = @yt.get('http://gdata.youtube.com/feeds/api/users/default/uploads?max-results=1')
|
33
|
+
feed = @yt.get('http://gdata.youtube.com/feeds/api/users/default/uploads?max-results=1').to_xml
|
33
34
|
self.assert_not_nil(feed, 'feed can not be nil')
|
34
35
|
end
|
35
36
|
|
@@ -43,7 +44,7 @@ class TC_GData_Client_YouTube < Test::Unit::TestCase
|
|
43
44
|
</entry>
|
44
45
|
EOF
|
45
46
|
|
46
|
-
response = @yt.post('http://gdata.youtube.com/feeds/api/users/default/favorites', entry)
|
47
|
+
response = @yt.post('http://gdata.youtube.com/feeds/api/users/default/favorites', entry).to_xml
|
47
48
|
|
48
49
|
edit_uri = response.elements["link[@rel='edit']"].attributes['href']
|
49
50
|
|
@@ -60,13 +61,13 @@ class TC_GData_Client_YouTube < Test::Unit::TestCase
|
|
60
61
|
</entry>
|
61
62
|
EOF
|
62
63
|
|
63
|
-
response = @yt.post('http://gdata.youtube.com/feeds/api/users/default/playlists', entry)
|
64
|
+
response = @yt.post('http://gdata.youtube.com/feeds/api/users/default/playlists', entry).to_xml
|
64
65
|
|
65
66
|
edit_uri = response.elements["link[@rel='edit']"].attributes['href']
|
66
67
|
|
67
68
|
response.elements["summary"].text = "Updated description"
|
68
69
|
|
69
|
-
response = @yt.put(edit_uri, response.to_s)
|
70
|
+
response = @yt.put(edit_uri, response.to_s).to_xml
|
70
71
|
|
71
72
|
self.assert_equal("Updated description", response.elements["summary"].text)
|
72
73
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Copyright (C) 2008 Google Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
$:.unshift(File.dirname(__FILE__))
|
16
|
+
require 'test_helper'
|
17
|
+
|
18
|
+
class TC_GData_HTTP_MimeBody < Test::Unit::TestCase
|
19
|
+
|
20
|
+
include TestHelper
|
21
|
+
|
22
|
+
def test_mime_body_string
|
23
|
+
stream = GData::HTTP::MimeBodyString.new('testing 1 2 3')
|
24
|
+
|
25
|
+
self.assert_equal('t', stream.read(1))
|
26
|
+
self.assert_equal('esting', stream.read(6))
|
27
|
+
self.assert_equal(' 1 2 ', stream.read(5))
|
28
|
+
self.assert_equal('3', stream.read(50))
|
29
|
+
self.assert_equal(false, stream.read(10))
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_mime_body_string_large_read
|
33
|
+
stream = GData::HTTP::MimeBodyString.new('test string')
|
34
|
+
|
35
|
+
self.assert_equal('test string', stream.read(1024))
|
36
|
+
self.assert_equal(false, stream.read(1024))
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_mime_body_string_unicode
|
40
|
+
stream = GData::HTTP::MimeBodyString.new('λ')
|
41
|
+
self.assert(stream.read(1), 'Greek character should be two bytes')
|
42
|
+
self.assert(stream.read(1), 'Greek character should be two full bytes')
|
43
|
+
self.assert_equal(false, stream.read(1))
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/test/test_helper.rb
CHANGED
data/test/testimage.jpg
ADDED
Binary file
|
data/test/ts_gdata.rb
CHANGED
@@ -21,6 +21,7 @@ require 'ts_gdata_auth'
|
|
21
21
|
class TS_GData
|
22
22
|
def self.suite
|
23
23
|
suite = Test::Unit::TestSuite.new("GData Test Suite")
|
24
|
+
suite << UnicodeStringTest.suite
|
24
25
|
suite << TS_GData_HTTP.suite
|
25
26
|
suite << TS_GData_Client.suite
|
26
27
|
suite << TS_GData_Auth.suite
|
@@ -28,4 +29,14 @@ class TS_GData
|
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
32
|
+
class UnicodeStringTest < Test::Unit::TestCase
|
33
|
+
def test_jlength
|
34
|
+
s = "Καλημέρα κόσμε!"
|
35
|
+
assert_equal(15, s.jlength) # Note the 'j'
|
36
|
+
assert_not_equal(15, s.length) # Normal, non unicode length
|
37
|
+
assert_equal(28, s.length) # Greek letters happen to take two-bytes
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
31
42
|
Test::Unit::UI::Console::TestRunner.run(TS_GData)
|
data/test/ts_gdata_client.rb
CHANGED
@@ -13,12 +13,14 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
require 'tc_gdata_client_base'
|
16
|
+
require 'tc_gdata_client_photos'
|
16
17
|
require 'tc_gdata_client_youtube'
|
17
18
|
|
18
19
|
class TS_GData_Client
|
19
20
|
def self.suite
|
20
21
|
suite = Test::Unit::TestSuite.new
|
21
22
|
suite << TC_GData_Client_Base.suite
|
23
|
+
suite << TC_GData_Client_Photos.suite
|
22
24
|
suite << TC_GData_Client_YouTube.suite
|
23
25
|
return suite
|
24
26
|
end
|
data/test/ts_gdata_http.rb
CHANGED
@@ -13,11 +13,13 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
require 'tc_gdata_http_request'
|
16
|
+
require 'tc_gdata_http_mime_body'
|
16
17
|
|
17
18
|
class TS_GData_HTTP
|
18
19
|
def self.suite
|
19
20
|
suite = Test::Unit::TestSuite.new
|
20
21
|
suite << TC_GData_HTTP_Request.suite
|
22
|
+
suite << TC_GData_HTTP_MimeBody.suite
|
21
23
|
return suite
|
22
24
|
end
|
23
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gdata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Fisher
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-02-20 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -29,10 +29,25 @@ files:
|
|
29
29
|
- lib/gdata/auth/authsub.rb
|
30
30
|
- lib/gdata/auth/clientlogin.rb
|
31
31
|
- lib/gdata/auth.rb
|
32
|
-
- lib/gdata/client/
|
32
|
+
- lib/gdata/client/apps.rb
|
33
|
+
- lib/gdata/client/base.rb
|
34
|
+
- lib/gdata/client/blogger.rb
|
35
|
+
- lib/gdata/client/booksearch.rb
|
36
|
+
- lib/gdata/client/calendar.rb
|
37
|
+
- lib/gdata/client/contacts.rb
|
38
|
+
- lib/gdata/client/doclist.rb
|
39
|
+
- lib/gdata/client/finance.rb
|
40
|
+
- lib/gdata/client/gbase.rb
|
41
|
+
- lib/gdata/client/gmail.rb
|
42
|
+
- lib/gdata/client/health.rb
|
43
|
+
- lib/gdata/client/notebook.rb
|
44
|
+
- lib/gdata/client/photos.rb
|
45
|
+
- lib/gdata/client/spreadsheets.rb
|
46
|
+
- lib/gdata/client/webmaster_tools.rb
|
33
47
|
- lib/gdata/client/youtube.rb
|
34
48
|
- lib/gdata/client.rb
|
35
49
|
- lib/gdata/http/default_service.rb
|
50
|
+
- lib/gdata/http/mime_body.rb
|
36
51
|
- lib/gdata/http/request.rb
|
37
52
|
- lib/gdata/http/response.rb
|
38
53
|
- lib/gdata/http.rb
|
@@ -40,10 +55,13 @@ files:
|
|
40
55
|
- test/tc_gdata_auth_authsub.rb
|
41
56
|
- test/tc_gdata_auth_clientlogin.rb
|
42
57
|
- test/tc_gdata_client_base.rb
|
58
|
+
- test/tc_gdata_client_photos.rb
|
43
59
|
- test/tc_gdata_client_youtube.rb
|
60
|
+
- test/tc_gdata_http_mime_body.rb
|
44
61
|
- test/tc_gdata_http_request.rb
|
45
62
|
- test/test_config.yml.example
|
46
63
|
- test/test_helper.rb
|
64
|
+
- test/testimage.jpg
|
47
65
|
- test/ts_gdata.rb
|
48
66
|
- test/ts_gdata_auth.rb
|
49
67
|
- test/ts_gdata_client.rb
|