gdata 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,28 @@
|
|
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
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# Client class to wrap working with the Contacts API.
|
19
|
+
class Contacts < Base
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
options[:clientlogin_service] ||= 'cp'
|
23
|
+
options[:authsub_scope] ||= 'http://www.google.com/m8/feeds/'
|
24
|
+
super(options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# Client class to wrap working with the Documents List Data API.
|
19
|
+
class DocList < Base
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
options[:clientlogin_service] ||= 'writely'
|
23
|
+
options[:authsub_scope] ||= 'http://docs.google.com/feeds/'
|
24
|
+
super(options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# Client class to wrap working with the Finance API.
|
19
|
+
class Finance < Base
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
options[:clientlogin_service] ||= 'finance'
|
23
|
+
options[:authsub_scope] ||= 'http://finance.google.com/finance/feeds/'
|
24
|
+
super(options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# Client class to wrap working with the Google Base API.
|
19
|
+
class GBase < Base
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
options[:clientlogin_service] ||= 'gbase'
|
23
|
+
options[:authsub_scope] ||= 'http://www.google.com/base/feeds/'
|
24
|
+
super(options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# Client class to wrap working with the GMail Atom Feed.
|
19
|
+
class GMail < Base
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
options[:clientlogin_service] ||= 'mail'
|
23
|
+
options[:authsub_scope] ||= 'https://mail.google.com/mail/feed/atom/'
|
24
|
+
super(options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# Client class to wrap working with the Health API.
|
19
|
+
class Health < Base
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
options[:clientlogin_service] ||= 'health'
|
23
|
+
options[:authsub_scope] ||= 'https://www.google.com/health/feeds/'
|
24
|
+
super(options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# Client class to wrap working with the Notebook Data API.
|
19
|
+
class Notebook < Base
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
options[:clientlogin_service] ||= 'notebook'
|
23
|
+
options[:authsub_scope] ||= 'http://www.google.com/notebook/feeds/'
|
24
|
+
super(options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
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
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# Client class to wrap working with the Picasa Web Albums API.
|
19
|
+
class Photos < Base
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
options[:clientlogin_service] ||= 'lh2'
|
23
|
+
options[:authsub_scope] ||= 'http://picasaweb.google.com/data/'
|
24
|
+
options[:version] ||= '1'
|
25
|
+
super(options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# Client class to wrap working with the Spreadsheets API.
|
19
|
+
class Spreadsheets < Base
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
options[:clientlogin_service] ||= 'wise'
|
23
|
+
options[:authsub_scope] ||= 'http://spreadsheets.google.com/feeds/'
|
24
|
+
super(options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# Client class to wrap working with the Webmaster Tools API.
|
19
|
+
class WebmasterTools < Base
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
options[:clientlogin_service] ||= 'sitemaps'
|
23
|
+
options[:authsub_scope] ||= 'http://www.google.com/webmasters/tools/feeds/'
|
24
|
+
super(options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/gdata/client/youtube.rb
CHANGED
@@ -19,19 +19,16 @@ module GData
|
|
19
19
|
# YouTube-specific options.
|
20
20
|
class YouTube < Base
|
21
21
|
|
22
|
-
DEFAULT_OPTIONS = {
|
23
|
-
:version => '2',
|
24
|
-
:clientlogin_url => 'https://www.google.com/youtube/accounts/ClientLogin',
|
25
|
-
:clientlogin_service => 'youtube',
|
26
|
-
:authsub_scope => 'http://gdata.youtube.com' }
|
27
|
-
|
28
22
|
# The YouTube developer key being used.
|
29
23
|
attr_accessor :developer_key
|
30
24
|
# The YouTube ClientID being used.
|
31
25
|
attr_accessor :client_id
|
32
26
|
|
33
27
|
def initialize(options = {})
|
34
|
-
options
|
28
|
+
options[:clientlogin_service] ||= 'youtube'
|
29
|
+
options[:clientlogin_url] ||= 'https://www.google.com/youtube/accounts/ClientLogin'
|
30
|
+
options[:authsub_scope] ||= 'http://gdata.youtube.com'
|
31
|
+
options[:version] ||= '2'
|
35
32
|
super(options)
|
36
33
|
end
|
37
34
|
|
data/lib/gdata/http.rb
CHANGED
@@ -37,25 +37,43 @@ module GData
|
|
37
37
|
req = Net::HTTP::Get.new(url.request_uri)
|
38
38
|
when :put
|
39
39
|
req = Net::HTTP::Put.new(url.request_uri)
|
40
|
-
request.calculate_length!
|
41
40
|
when :post
|
42
41
|
req = Net::HTTP::Post.new(url.request_uri)
|
43
|
-
request.calculate_length!
|
44
42
|
when :delete
|
45
43
|
req = Net::HTTP::Delete.new(url.request_uri)
|
46
44
|
else
|
47
45
|
raise ArgumentError, "Unsupported HTTP method specified."
|
48
46
|
end
|
49
47
|
|
50
|
-
|
48
|
+
case request.body
|
49
|
+
when String
|
50
|
+
req.body = request.body
|
51
|
+
when Hash
|
52
|
+
req.set_form_data(request.body)
|
53
|
+
when File
|
54
|
+
req.body_stream = request.body
|
55
|
+
request.chunked = true
|
56
|
+
when GData::HTTP::MimeBody
|
57
|
+
req.body_stream = request.body
|
58
|
+
request.chunked = true
|
59
|
+
else
|
60
|
+
req.body = request.body.to_s
|
61
|
+
end
|
62
|
+
|
51
63
|
request.headers.each do |key, value|
|
52
64
|
req[key] = value
|
53
65
|
end
|
66
|
+
|
67
|
+
request.calculate_length!
|
68
|
+
|
54
69
|
res = http.request(req)
|
55
70
|
|
56
71
|
response = Response.new
|
57
72
|
response.body = res.body
|
58
|
-
response.headers =
|
73
|
+
response.headers = Hash.new
|
74
|
+
res.each do |key, value|
|
75
|
+
response.headers[key] = value
|
76
|
+
end
|
59
77
|
response.status_code = res.code.to_i
|
60
78
|
return response
|
61
79
|
end
|
@@ -0,0 +1,95 @@
|
|
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
|
+
|
16
|
+
module GData
|
17
|
+
module HTTP
|
18
|
+
|
19
|
+
# Class acts as a virtual file handle to a MIME multipart message body
|
20
|
+
class MimeBody
|
21
|
+
|
22
|
+
# The MIME boundary being used.
|
23
|
+
attr_reader :boundary
|
24
|
+
|
25
|
+
# All fields are required, the entry should be a string and is assumed
|
26
|
+
# to be XML.
|
27
|
+
def initialize(entry, file, file_mime_type)
|
28
|
+
@boundary = "END_OF_PART_#{rand(64000)}"
|
29
|
+
entry = wrap_entry(entry, file_mime_type)
|
30
|
+
closing_boundary = MimeBodyString.new("\r\n--#{@boundary}--")
|
31
|
+
@parts = [entry, file, closing_boundary]
|
32
|
+
@current_part = 0
|
33
|
+
end
|
34
|
+
|
35
|
+
# Implement read so that this class can be treated as a stream.
|
36
|
+
def read(bytes_requested)
|
37
|
+
if @current_part >= @parts.length
|
38
|
+
return false
|
39
|
+
end
|
40
|
+
|
41
|
+
buffer = @parts[@current_part].read(bytes_requested)
|
42
|
+
|
43
|
+
until buffer.length == bytes_requested
|
44
|
+
@current_part += 1
|
45
|
+
next_buffer = self.read(bytes_requested - buffer.length)
|
46
|
+
break if not next_buffer
|
47
|
+
buffer += next_buffer
|
48
|
+
end
|
49
|
+
|
50
|
+
return buffer
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns the content type of the message including boundary.
|
54
|
+
def content_type
|
55
|
+
return "multipart/related; boundary=\"#{@boundary}\""
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# Sandwiches the entry body into a MIME message
|
61
|
+
def wrap_entry(entry, file_mime_type)
|
62
|
+
wrapped_entry = "--#{@boundary}\r\n"
|
63
|
+
wrapped_entry += "Content-Type: application/atom+xml\r\n\r\n"
|
64
|
+
wrapped_entry += entry
|
65
|
+
wrapped_entry += "--#{@boundary}\r\n"
|
66
|
+
wrapped_entry += "Content-Type: #{file_mime_type}\r\n\r\n"
|
67
|
+
return MimeBodyString.new(wrapped_entry)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
# Class makes a string into a stream-like object
|
73
|
+
class MimeBodyString
|
74
|
+
|
75
|
+
def initialize(source_string)
|
76
|
+
@string = source_string
|
77
|
+
@bytes_read = 0
|
78
|
+
end
|
79
|
+
|
80
|
+
# Implement read so that this class can be treated as a stream.
|
81
|
+
def read(bytes_requested)
|
82
|
+
if @bytes_read == @string.length
|
83
|
+
return false
|
84
|
+
elsif bytes_requested > @string.length - @bytes_read
|
85
|
+
bytes_requested = @string.length - @bytes_read
|
86
|
+
end
|
87
|
+
|
88
|
+
buffer = @string[@bytes_read, bytes_requested]
|
89
|
+
@bytes_read += bytes_requested
|
90
|
+
|
91
|
+
return buffer
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|