gdata_19 1.1.2
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/.hgtags +5 -0
- data/LICENSE +202 -0
- data/README +97 -0
- data/Rakefile +82 -0
- data/VERSION +1 -0
- data/bin/test_captcha.rb +52 -0
- data/doc/classes/GData/Auth/AuthSub.html +349 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000020.html +29 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000021.html +29 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000022.html +31 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000023.html +29 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000024.html +32 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000025.html +26 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000026.html +29 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000038.html +28 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000039.html +29 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000040.html +31 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000041.html +29 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000042.html +32 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000043.html +28 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000044.html +29 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000045.html +31 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000046.html +28 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000047.html +28 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000048.html +29 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000049.html +31 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000050.html +28 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000051.html +31 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000052.html +25 -0
- data/doc/classes/GData/Auth/AuthSub.src/M000053.html +29 -0
- data/doc/classes/GData/Auth/ClientLogin.html +232 -0
- data/doc/classes/GData/Auth/ClientLogin.src/M000027.html +27 -0
- data/doc/classes/GData/Auth/ClientLogin.src/M000028.html +47 -0
- data/doc/classes/GData/Auth/ClientLogin.src/M000029.html +22 -0
- data/doc/classes/GData/Auth/ClientLogin.src/M000045.html +29 -0
- data/doc/classes/GData/Auth/ClientLogin.src/M000046.html +49 -0
- data/doc/classes/GData/Auth/ClientLogin.src/M000047.html +22 -0
- data/doc/classes/GData/Auth/ClientLogin.src/M000050.html +29 -0
- data/doc/classes/GData/Auth/ClientLogin.src/M000051.html +49 -0
- data/doc/classes/GData/Auth/ClientLogin.src/M000052.html +22 -0
- data/doc/classes/GData/Auth/ClientLogin.src/M000053.html +29 -0
- data/doc/classes/GData/Auth/ClientLogin.src/M000054.html +29 -0
- data/doc/classes/GData/Auth/ClientLogin.src/M000055.html +49 -0
- data/doc/classes/GData/Auth/ClientLogin.src/M000056.html +22 -0
- data/doc/classes/GData/Auth.html +133 -0
- data/doc/classes/GData/Client/Apps.html +146 -0
- data/doc/classes/GData/Client/Apps.src/M000027.html +19 -0
- data/doc/classes/GData/Client/Apps.src/M000028.html +19 -0
- data/doc/classes/GData/Client/AuthorizationError.html +113 -0
- data/doc/classes/GData/Client/BadRequestError.html +113 -0
- data/doc/classes/GData/Client/Base.html +453 -0
- data/doc/classes/GData/Client/Base.src/M000002.html +21 -0
- data/doc/classes/GData/Client/Base.src/M000003.html +55 -0
- data/doc/classes/GData/Client/Base.src/M000004.html +18 -0
- data/doc/classes/GData/Client/Base.src/M000005.html +18 -0
- data/doc/classes/GData/Client/Base.src/M000006.html +18 -0
- data/doc/classes/GData/Client/Base.src/M000007.html +18 -0
- data/doc/classes/GData/Client/Base.src/M000008.html +22 -0
- data/doc/classes/GData/Client/Base.src/M000009.html +26 -0
- data/doc/classes/GData/Client/Base.src/M000010.html +22 -0
- data/doc/classes/GData/Client/Base.src/M000011.html +25 -0
- data/doc/classes/GData/Client/Base.src/M000012.html +25 -0
- data/doc/classes/GData/Client/Base.src/M000013.html +33 -0
- data/doc/classes/GData/Client/Base.src/M000014.html +44 -0
- data/doc/classes/GData/Client/Base.src/M000015.html +18 -0
- data/doc/classes/GData/Client/Base.src/M000016.html +18 -0
- data/doc/classes/GData/Client/Base.src/M000017.html +18 -0
- data/doc/classes/GData/Client/Base.src/M000018.html +18 -0
- data/doc/classes/GData/Client/Base.src/M000019.html +18 -0
- data/doc/classes/GData/Client/Base.src/M000020.html +18 -0
- data/doc/classes/GData/Client/Base.src/M000021.html +25 -0
- data/doc/classes/GData/Client/Base.src/M000022.html +28 -0
- data/doc/classes/GData/Client/Base.src/M000023.html +22 -0
- data/doc/classes/GData/Client/Base.src/M000024.html +18 -0
- data/doc/classes/GData/Client/Base.src/M000025.html +22 -0
- data/doc/classes/GData/Client/Blogger.html +146 -0
- data/doc/classes/GData/Client/Blogger.src/M000002.html +20 -0
- data/doc/classes/GData/Client/BookSearch.html +146 -0
- data/doc/classes/GData/Client/BookSearch.src/M000010.html +20 -0
- data/doc/classes/GData/Client/BookSearch.src/M000011.html +20 -0
- data/doc/classes/GData/Client/Calendar.html +221 -0
- data/doc/classes/GData/Client/Calendar.src/M000030.html +20 -0
- data/doc/classes/GData/Client/Calendar.src/M000031.html +20 -0
- data/doc/classes/GData/Client/Calendar.src/M000032.html +19 -0
- data/doc/classes/GData/Client/Calendar.src/M000033.html +25 -0
- data/doc/classes/GData/Client/Calendar.src/M000034.html +21 -0
- data/doc/classes/GData/Client/CaptchaError.html +167 -0
- data/doc/classes/GData/Client/CaptchaError.src/M000001.html +19 -0
- data/doc/classes/GData/Client/CaptchaError.src/M000005.html +19 -0
- data/doc/classes/GData/Client/Contacts.html +146 -0
- data/doc/classes/GData/Client/Contacts.src/M000003.html +20 -0
- data/doc/classes/GData/Client/DocList.html +146 -0
- data/doc/classes/GData/Client/DocList.src/M000006.html +20 -0
- data/doc/classes/GData/Client/DocList.src/M000007.html +20 -0
- data/doc/classes/GData/Client/Error.html +118 -0
- data/doc/classes/GData/Client/Finance.html +146 -0
- data/doc/classes/GData/Client/Finance.src/M000029.html +20 -0
- data/doc/classes/GData/Client/Finance.src/M000030.html +20 -0
- data/doc/classes/GData/Client/GBase.html +146 -0
- data/doc/classes/GData/Client/GBase.src/M000004.html +20 -0
- data/doc/classes/GData/Client/GMail.html +146 -0
- data/doc/classes/GData/Client/GMail.src/M000028.html +20 -0
- data/doc/classes/GData/Client/GMail.src/M000029.html +20 -0
- data/doc/classes/GData/Client/Health.html +146 -0
- data/doc/classes/GData/Client/Health.src/M000031.html +20 -0
- data/doc/classes/GData/Client/Health.src/M000034.html +20 -0
- data/doc/classes/GData/Client/Health.src/M000035.html +20 -0
- data/doc/classes/GData/Client/Notebook.html +146 -0
- data/doc/classes/GData/Client/Notebook.src/M000009.html +20 -0
- data/doc/classes/GData/Client/Notebook.src/M000010.html +20 -0
- data/doc/classes/GData/Client/Photos.html +146 -0
- data/doc/classes/GData/Client/Photos.src/M000008.html +21 -0
- data/doc/classes/GData/Client/Photos.src/M000009.html +21 -0
- data/doc/classes/GData/Client/RequestError.html +167 -0
- data/doc/classes/GData/Client/RequestError.src/M000006.html +20 -0
- data/doc/classes/GData/Client/ServerError.html +113 -0
- data/doc/classes/GData/Client/Spreadsheets.html +146 -0
- data/doc/classes/GData/Client/Spreadsheets.src/M000001.html +20 -0
- data/doc/classes/GData/Client/UnknownError.html +113 -0
- data/doc/classes/GData/Client/VersionConflictError.html +113 -0
- data/doc/classes/GData/Client/WebmasterTools.html +146 -0
- data/doc/classes/GData/Client/WebmasterTools.src/M000007.html +20 -0
- data/doc/classes/GData/Client/WebmasterTools.src/M000008.html +20 -0
- data/doc/classes/GData/Client/YouTube.html +192 -0
- data/doc/classes/GData/Client/YouTube.src/M000013.html +19 -0
- data/doc/classes/GData/Client/YouTube.src/M000014.html +24 -0
- data/doc/classes/GData/Client/YouTube.src/M000025.html +22 -0
- data/doc/classes/GData/Client/YouTube.src/M000026.html +22 -0
- data/doc/classes/GData/Client/YouTube.src/M000027.html +24 -0
- data/doc/classes/GData/Client.html +198 -0
- data/doc/classes/GData/HTTP/DefaultService.html +150 -0
- data/doc/classes/GData/HTTP/DefaultService.src/M000019.html +48 -0
- data/doc/classes/GData/HTTP/DefaultService.src/M000037.html +63 -0
- data/doc/classes/GData/HTTP/DefaultService.src/M000042.html +66 -0
- data/doc/classes/GData/HTTP/DefaultService.src/M000045.html +66 -0
- data/doc/classes/GData/HTTP/DefaultService.src/M000046.html +66 -0
- data/doc/classes/GData/HTTP/MimeBody.html +202 -0
- data/doc/classes/GData/HTTP/MimeBody.src/M000032.html +22 -0
- data/doc/classes/GData/HTTP/MimeBody.src/M000033.html +31 -0
- data/doc/classes/GData/HTTP/MimeBody.src/M000034.html +18 -0
- data/doc/classes/GData/HTTP/MimeBody.src/M000035.html +22 -0
- data/doc/classes/GData/HTTP/MimeBody.src/M000036.html +22 -0
- data/doc/classes/GData/HTTP/MimeBody.src/M000037.html +31 -0
- data/doc/classes/GData/HTTP/MimeBody.src/M000038.html +18 -0
- data/doc/classes/GData/HTTP/MimeBodyString.html +164 -0
- data/doc/classes/GData/HTTP/MimeBodyString.src/M000036.html +19 -0
- data/doc/classes/GData/HTTP/MimeBodyString.src/M000037.html +27 -0
- data/doc/classes/GData/HTTP/MimeBodyString.src/M000039.html +19 -0
- data/doc/classes/GData/HTTP/MimeBodyString.src/M000040.html +19 -0
- data/doc/classes/GData/HTTP/MimeBodyString.src/M000041.html +27 -0
- data/doc/classes/GData/HTTP/Request.html +243 -0
- data/doc/classes/GData/HTTP/Request.src/M000015.html +22 -0
- data/doc/classes/GData/HTTP/Request.src/M000016.html +22 -0
- data/doc/classes/GData/HTTP/Request.src/M000017.html +22 -0
- data/doc/classes/GData/HTTP/Request.src/M000018.html +24 -0
- data/doc/classes/GData/HTTP/Request.src/M000033.html +24 -0
- data/doc/classes/GData/HTTP/Request.src/M000034.html +22 -0
- data/doc/classes/GData/HTTP/Request.src/M000035.html +22 -0
- data/doc/classes/GData/HTTP/Request.src/M000036.html +25 -0
- data/doc/classes/GData/HTTP/Request.src/M000038.html +24 -0
- data/doc/classes/GData/HTTP/Request.src/M000039.html +22 -0
- data/doc/classes/GData/HTTP/Request.src/M000040.html +22 -0
- data/doc/classes/GData/HTTP/Request.src/M000041.html +24 -0
- data/doc/classes/GData/HTTP/Request.src/M000042.html +24 -0
- data/doc/classes/GData/HTTP/Request.src/M000043.html +22 -0
- data/doc/classes/GData/HTTP/Request.src/M000044.html +22 -0
- data/doc/classes/GData/HTTP/Request.src/M000045.html +25 -0
- data/doc/classes/GData/HTTP/Response.html +179 -0
- data/doc/classes/GData/HTTP/Response.src/M000032.html +26 -0
- data/doc/classes/GData/HTTP/Response.src/M000035.html +26 -0
- data/doc/classes/GData/HTTP/Response.src/M000038.html +26 -0
- data/doc/classes/GData/HTTP/Response.src/M000039.html +26 -0
- data/doc/classes/GData/HTTP.html +127 -0
- data/doc/classes/GData.html +226 -0
- data/doc/created.rid +1 -0
- data/doc/files/README.html +214 -0
- data/doc/files/lib/gdata/auth/authsub_rb.html +131 -0
- data/doc/files/lib/gdata/auth/clientlogin_rb.html +129 -0
- data/doc/files/lib/gdata/auth_rb.html +130 -0
- data/doc/files/lib/gdata/client/apps_rb.html +122 -0
- data/doc/files/lib/gdata/client/base_rb.html +122 -0
- data/doc/files/lib/gdata/client/blogger_rb.html +122 -0
- data/doc/files/lib/gdata/client/booksearch_rb.html +122 -0
- data/doc/files/lib/gdata/client/calendar_rb.html +122 -0
- data/doc/files/lib/gdata/client/contacts_rb.html +122 -0
- data/doc/files/lib/gdata/client/doclist_rb.html +122 -0
- data/doc/files/lib/gdata/client/finance_rb.html +122 -0
- data/doc/files/lib/gdata/client/gbase_rb.html +122 -0
- data/doc/files/lib/gdata/client/gdata_rb.html +129 -0
- data/doc/files/lib/gdata/client/gmail_rb.html +122 -0
- data/doc/files/lib/gdata/client/health_rb.html +122 -0
- data/doc/files/lib/gdata/client/notebook_rb.html +122 -0
- data/doc/files/lib/gdata/client/photos_rb.html +122 -0
- data/doc/files/lib/gdata/client/spreadsheets_rb.html +122 -0
- data/doc/files/lib/gdata/client/webmaster_tools_rb.html +122 -0
- data/doc/files/lib/gdata/client/youtube_rb.html +122 -0
- data/doc/files/lib/gdata/client_rb.html +144 -0
- data/doc/files/lib/gdata/http/default_service_rb.html +131 -0
- data/doc/files/lib/gdata/http/mime_body_rb.html +122 -0
- data/doc/files/lib/gdata/http/request_rb.html +129 -0
- data/doc/files/lib/gdata/http/response_rb.html +129 -0
- data/doc/files/lib/gdata/http_rb.html +132 -0
- data/doc/files/lib/gdata_rb.html +132 -0
- data/doc/fr_class_index.html +61 -0
- data/doc/fr_file_index.html +53 -0
- data/doc/fr_method_index.html +82 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/gdata19.gemspec +294 -0
- data/lib/gdata/auth/authsub.rb +162 -0
- data/lib/gdata/auth/clientlogin.rb +103 -0
- data/lib/gdata/auth.rb +23 -0
- data/lib/gdata/client/apps.rb +28 -0
- data/lib/gdata/client/base.rb +183 -0
- data/lib/gdata/client/blogger.rb +29 -0
- data/lib/gdata/client/booksearch.rb +29 -0
- data/lib/gdata/client/calendar.rb +59 -0
- data/lib/gdata/client/contacts.rb +29 -0
- data/lib/gdata/client/doclist.rb +29 -0
- data/lib/gdata/client/finance.rb +29 -0
- data/lib/gdata/client/gbase.rb +29 -0
- data/lib/gdata/client/gmail.rb +29 -0
- data/lib/gdata/client/health.rb +29 -0
- data/lib/gdata/client/notebook.rb +29 -0
- data/lib/gdata/client/photos.rb +30 -0
- data/lib/gdata/client/spreadsheets.rb +29 -0
- data/lib/gdata/client/webmaster_tools.rb +29 -0
- data/lib/gdata/client/youtube.rb +48 -0
- data/lib/gdata/client.rb +85 -0
- data/lib/gdata/http/default_service.rb +83 -0
- data/lib/gdata/http/mime_body.rb +101 -0
- data/lib/gdata/http/request.rb +75 -0
- data/lib/gdata/http/response.rb +45 -0
- data/lib/gdata/http.rb +19 -0
- data/lib/gdata.rb +24 -0
- data/pkg/gdata19-1.1.2.gem +0 -0
- data/test/tc_gdata_auth_authsub.rb +53 -0
- data/test/tc_gdata_auth_clientlogin.rb +59 -0
- data/test/tc_gdata_client_base.rb +37 -0
- data/test/tc_gdata_client_calendar.rb +40 -0
- data/test/tc_gdata_client_photos.rb +65 -0
- data/test/tc_gdata_client_youtube.rb +77 -0
- data/test/tc_gdata_http_mime_body.rb +47 -0
- data/test/tc_gdata_http_request.rb +36 -0
- data/test/test_config.yml.example +7 -0
- data/test/test_helper.rb +47 -0
- data/test/testimage.jpg +0 -0
- data/test/ts_gdata.rb +48 -0
- data/test/ts_gdata_auth.rb +25 -0
- data/test/ts_gdata_client.rb +29 -0
- data/test/ts_gdata_http.rb +25 -0
- metadata +320 -0
data/lib/gdata/client.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# Copyright (C) 2008 Google Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require 'gdata/client/base'
|
17
|
+
require 'gdata/client/apps'
|
18
|
+
require 'gdata/client/blogger'
|
19
|
+
require 'gdata/client/booksearch'
|
20
|
+
require 'gdata/client/calendar'
|
21
|
+
require 'gdata/client/contacts'
|
22
|
+
require 'gdata/client/doclist'
|
23
|
+
require 'gdata/client/finance'
|
24
|
+
require 'gdata/client/gbase'
|
25
|
+
require 'gdata/client/gmail'
|
26
|
+
require 'gdata/client/health'
|
27
|
+
require 'gdata/client/notebook'
|
28
|
+
require 'gdata/client/photos'
|
29
|
+
require 'gdata/client/spreadsheets'
|
30
|
+
require 'gdata/client/webmaster_tools'
|
31
|
+
require 'gdata/client/youtube'
|
32
|
+
|
33
|
+
module GData
|
34
|
+
module Client
|
35
|
+
|
36
|
+
# Base class for GData::Client errors
|
37
|
+
class Error < RuntimeError
|
38
|
+
end
|
39
|
+
|
40
|
+
# Base class for errors raised due to requests
|
41
|
+
class RequestError < Error
|
42
|
+
|
43
|
+
# The Net::HTTPResponse that caused this error.
|
44
|
+
attr_accessor :response
|
45
|
+
|
46
|
+
# Creates a new RequestError from Net::HTTPResponse +response+ with a
|
47
|
+
# message containing the error code and response body.
|
48
|
+
def initialize(response)
|
49
|
+
@response = response
|
50
|
+
|
51
|
+
super "request error #{response.status_code}: #{response.body}"
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
class AuthorizationError < RequestError
|
57
|
+
end
|
58
|
+
|
59
|
+
class BadRequestError < RequestError
|
60
|
+
end
|
61
|
+
|
62
|
+
# An error caused by ClientLogin issuing a CAPTCHA error.
|
63
|
+
class CaptchaError < RuntimeError
|
64
|
+
# The token identifying the CAPTCHA
|
65
|
+
attr_reader :token
|
66
|
+
# The URL to the CAPTCHA image
|
67
|
+
attr_reader :url
|
68
|
+
|
69
|
+
def initialize(token, url)
|
70
|
+
@token = token
|
71
|
+
@url = url
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class ServerError < RequestError
|
76
|
+
end
|
77
|
+
|
78
|
+
class UnknownError < RequestError
|
79
|
+
end
|
80
|
+
|
81
|
+
class VersionConflictError < RequestError
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# Copyright (C) 2008 Google Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require 'net/http'
|
17
|
+
require 'net/https'
|
18
|
+
require 'uri'
|
19
|
+
|
20
|
+
module GData
|
21
|
+
module HTTP
|
22
|
+
|
23
|
+
# This is the default implementation of the HTTP layer that uses
|
24
|
+
# Net::HTTP. You could roll your own if you have different requirements
|
25
|
+
# or cannot use Net::HTTP for some reason.
|
26
|
+
class DefaultService
|
27
|
+
|
28
|
+
# Take a GData::HTTP::Request, execute the request, and return a
|
29
|
+
# GData::HTTP::Response object.
|
30
|
+
def make_request(request)
|
31
|
+
url = URI.parse(request.url)
|
32
|
+
http = Net::HTTP.new(url.host, url.port)
|
33
|
+
http.use_ssl = (url.scheme == 'https')
|
34
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
35
|
+
|
36
|
+
case request.method
|
37
|
+
when :get
|
38
|
+
req = Net::HTTP::Get.new(url.request_uri)
|
39
|
+
when :put
|
40
|
+
req = Net::HTTP::Put.new(url.request_uri)
|
41
|
+
when :post
|
42
|
+
req = Net::HTTP::Post.new(url.request_uri)
|
43
|
+
when :delete
|
44
|
+
req = Net::HTTP::Delete.new(url.request_uri)
|
45
|
+
else
|
46
|
+
raise ArgumentError, "Unsupported HTTP method specified."
|
47
|
+
end
|
48
|
+
|
49
|
+
case request.body
|
50
|
+
when String
|
51
|
+
req.body = request.body
|
52
|
+
when Hash
|
53
|
+
req.set_form_data(request.body)
|
54
|
+
when File
|
55
|
+
req.body_stream = request.body
|
56
|
+
request.chunked = true
|
57
|
+
when GData::HTTP::MimeBody
|
58
|
+
req.body_stream = request.body
|
59
|
+
request.chunked = true
|
60
|
+
else
|
61
|
+
req.body = request.body.to_s
|
62
|
+
end
|
63
|
+
|
64
|
+
request.headers.each do |key, value|
|
65
|
+
req[key] = value
|
66
|
+
end
|
67
|
+
|
68
|
+
request.calculate_length!
|
69
|
+
|
70
|
+
res = http.request(req)
|
71
|
+
|
72
|
+
response = Response.new
|
73
|
+
response.body = res.body
|
74
|
+
response.headers = Hash.new
|
75
|
+
res.each do |key, value|
|
76
|
+
response.headers[key] = value
|
77
|
+
end
|
78
|
+
response.status_code = res.code.to_i
|
79
|
+
return response
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# Copyright (C) 2008 Google Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
|
17
|
+
module GData
|
18
|
+
module HTTP
|
19
|
+
|
20
|
+
# Class acts as a virtual file handle to a MIME multipart message body
|
21
|
+
class MimeBody
|
22
|
+
|
23
|
+
# The MIME boundary being used.
|
24
|
+
attr_reader :boundary
|
25
|
+
|
26
|
+
# All fields are required, the entry should be a string and is assumed
|
27
|
+
# to be XML.
|
28
|
+
def initialize(entry, file, file_mime_type)
|
29
|
+
@boundary = "END_OF_PART_#{rand(64000)}"
|
30
|
+
entry = wrap_entry(entry, file_mime_type)
|
31
|
+
closing_boundary = MimeBodyString.new("\r\n--#{@boundary}--")
|
32
|
+
@parts = [entry, file, closing_boundary]
|
33
|
+
@current_part = 0
|
34
|
+
end
|
35
|
+
|
36
|
+
# Implement read so that this class can be treated as a stream.
|
37
|
+
def read(bytes_requested)
|
38
|
+
if @current_part >= @parts.length
|
39
|
+
return false
|
40
|
+
end
|
41
|
+
|
42
|
+
buffer = @parts[@current_part].read(bytes_requested)
|
43
|
+
|
44
|
+
until buffer.length == bytes_requested
|
45
|
+
@current_part += 1
|
46
|
+
next_buffer = self.read(bytes_requested - buffer.length)
|
47
|
+
break if not next_buffer
|
48
|
+
buffer += next_buffer
|
49
|
+
end
|
50
|
+
|
51
|
+
return buffer
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns the content type of the message including boundary.
|
55
|
+
def content_type
|
56
|
+
return "multipart/related; boundary=\"#{@boundary}\""
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
# Sandwiches the entry body into a MIME message
|
62
|
+
def wrap_entry(entry, file_mime_type)
|
63
|
+
wrapped_entry = "--#{@boundary}\r\n"
|
64
|
+
wrapped_entry += "Content-Type: application/atom+xml\r\n\r\n"
|
65
|
+
wrapped_entry += entry
|
66
|
+
wrapped_entry += "\r\n--#{@boundary}\r\n"
|
67
|
+
wrapped_entry += "Content-Type: #{file_mime_type}\r\n\r\n"
|
68
|
+
return MimeBodyString.new(wrapped_entry)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
# Class makes a string into a stream-like object
|
74
|
+
class MimeBodyString
|
75
|
+
|
76
|
+
def initialize(source_string)
|
77
|
+
@string = source_string
|
78
|
+
@bytes_read = 0
|
79
|
+
end
|
80
|
+
|
81
|
+
# Implement read so that this class can be treated as a stream.
|
82
|
+
def read(bytes_requested)
|
83
|
+
if RUBY_VERSION < '1.9'
|
84
|
+
max_bytes = @string.length
|
85
|
+
else
|
86
|
+
max_bytes = @string.bytesize
|
87
|
+
end
|
88
|
+
if @bytes_read == max_bytes
|
89
|
+
return false
|
90
|
+
elsif bytes_requested > max_bytes - @bytes_read
|
91
|
+
bytes_requested = max_bytes - @bytes_read
|
92
|
+
end
|
93
|
+
|
94
|
+
buffer = @string[@bytes_read, bytes_requested]
|
95
|
+
@bytes_read += bytes_requested
|
96
|
+
|
97
|
+
return buffer
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# Copyright (C) 2008 Google Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require "rexml/document"
|
17
|
+
|
18
|
+
module GData
|
19
|
+
module HTTP
|
20
|
+
|
21
|
+
# Very simple class to hold everything about an HTTP request.
|
22
|
+
class Request
|
23
|
+
|
24
|
+
# The URL of the request.
|
25
|
+
attr_accessor :url
|
26
|
+
# The body of the request.
|
27
|
+
attr_accessor :body
|
28
|
+
# The HTTP method being used in the request.
|
29
|
+
attr_accessor :method
|
30
|
+
# The HTTP headers of the request.
|
31
|
+
attr_accessor :headers
|
32
|
+
|
33
|
+
# Only the URL itself is required, everything else is optional.
|
34
|
+
def initialize(url, options = {})
|
35
|
+
@url = url
|
36
|
+
options.each do |key, value|
|
37
|
+
self.send("#{key}=", value)
|
38
|
+
end
|
39
|
+
|
40
|
+
@method ||= :get
|
41
|
+
@headers ||= {}
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns whether or not a request is chunked.
|
45
|
+
def chunked?
|
46
|
+
if @headers['Transfer-Encoding'] == 'chunked'
|
47
|
+
return true
|
48
|
+
else
|
49
|
+
return false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Sets if the request is using chunked transfer-encoding.
|
54
|
+
def chunked=(enabled)
|
55
|
+
if enabled
|
56
|
+
@headers['Transfer-Encoding'] = 'chunked'
|
57
|
+
else
|
58
|
+
@headers.delete('Transfer-Encoding')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Calculates and sets the length of the body.
|
63
|
+
def calculate_length!
|
64
|
+
if not @headers['Content-Length'] and not chunked? \
|
65
|
+
and method != :get and method != :delete
|
66
|
+
if @body
|
67
|
+
@headers['Content-Length'] = @body.length
|
68
|
+
else
|
69
|
+
@headers['Content-Length'] = 0
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# Copyright (C) 2008 Google Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require 'gdata/client'
|
17
|
+
|
18
|
+
module GData
|
19
|
+
module HTTP
|
20
|
+
|
21
|
+
# An extremely simple class to hold the values of an HTTP response.
|
22
|
+
class Response
|
23
|
+
|
24
|
+
# The HTTP response code.
|
25
|
+
attr_accessor :status_code
|
26
|
+
# The body of the HTTP response.
|
27
|
+
attr_accessor :body
|
28
|
+
# The headers of the HTTP response.
|
29
|
+
attr_accessor :headers
|
30
|
+
|
31
|
+
# Converts the response body into a REXML::Document
|
32
|
+
def to_xml
|
33
|
+
if @body
|
34
|
+
begin
|
35
|
+
return REXML::Document.new(@body).root
|
36
|
+
rescue
|
37
|
+
raise GData::Client::Error, "Response body not XML."
|
38
|
+
end
|
39
|
+
else
|
40
|
+
return nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/gdata/http.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# Copyright (C) 2008 Google Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require 'gdata/http/default_service'
|
17
|
+
require 'gdata/http/mime_body'
|
18
|
+
require 'gdata/http/request'
|
19
|
+
require 'gdata/http/response'
|
data/lib/gdata.rb
ADDED
@@ -0,0 +1,24 @@
|
|
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
|
+
|
17
|
+
require 'gdata/http'
|
18
|
+
require 'gdata/client'
|
19
|
+
require 'gdata/auth'
|
20
|
+
if RUBY_VERSION < '1.9'
|
21
|
+
# This is for Unicode "support" in Ruby 1.8
|
22
|
+
$KCODE = 'UTF8'
|
23
|
+
require 'jcode'
|
24
|
+
end
|
Binary file
|
@@ -0,0 +1,53 @@
|
|
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_Auth_AuthSub < Test::Unit::TestCase
|
19
|
+
|
20
|
+
include TestHelper
|
21
|
+
|
22
|
+
def test_make_authenticated_request
|
23
|
+
token = self.get_authsub_token()
|
24
|
+
key = self.get_authsub_private_key()
|
25
|
+
service = GData::Client::YouTube.new
|
26
|
+
if token
|
27
|
+
|
28
|
+
service.authsub_token = token
|
29
|
+
if key
|
30
|
+
service.authsub_private_key = key
|
31
|
+
end
|
32
|
+
|
33
|
+
feed = service.get('http://gdata.youtube.com/feeds/api/users/default/uploads?max-results=1')
|
34
|
+
self.assert_not_nil(feed, 'Feed should not be nil')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_generate_url
|
39
|
+
scope = 'http://gdata.youtube.com'
|
40
|
+
next_url = 'http://example.com'
|
41
|
+
secure = true
|
42
|
+
session = false
|
43
|
+
url = GData::Auth::AuthSub.get_url(next_url, scope, secure, session)
|
44
|
+
self.assert_equal('https://www.google.com/accounts/AuthSubRequest?next=http%3A%2F%2Fexample.com&scope=http%3A%2F%2Fgdata.youtube.com&session=0&secure=1', url)
|
45
|
+
|
46
|
+
# test generating with a pre-populated scope
|
47
|
+
yt = GData::Client::YouTube.new
|
48
|
+
client_url = yt.authsub_url(next_url, secure, session)
|
49
|
+
self.assert_equal(url, client_url)
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,59 @@
|
|
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_Auth_ClientLogin < Test::Unit::TestCase
|
19
|
+
|
20
|
+
include TestHelper
|
21
|
+
|
22
|
+
def test_has_config
|
23
|
+
self.assert_not_nil(self.get_username(),
|
24
|
+
'Must have a username in test_config.yml')
|
25
|
+
self.assert_not_nil(self.get_password(),
|
26
|
+
'Must have a password in test_config.yml')
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_get_token
|
30
|
+
client_login = GData::Auth::ClientLogin.new('cl')
|
31
|
+
source = 'GDataUnitTest'
|
32
|
+
assert_nothing_raised do
|
33
|
+
token = client_login.get_token(self.get_username(), self.get_password(), source)
|
34
|
+
end
|
35
|
+
end
|
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
|
+
|
50
|
+
def test_specify_account_type
|
51
|
+
gp = GData::Client::Photos.new
|
52
|
+
gp.source = 'GDataUnitTest'
|
53
|
+
assert_nothing_raised do
|
54
|
+
token = gp.clientlogin(self.get_username(), self.get_password(), nil, nil, nil, 'GOOGLE')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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_Base < Test::Unit::TestCase
|
19
|
+
|
20
|
+
include TestHelper
|
21
|
+
|
22
|
+
def test_simple_gdata_get
|
23
|
+
service = GData::Client::Base.new
|
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
|
33
|
+
assert_not_nil(feed, 'feed can not be nil')
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,40 @@
|
|
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_Calendar < Test::Unit::TestCase
|
19
|
+
|
20
|
+
include TestHelper
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@cl = GData::Client::Calendar.new
|
24
|
+
@cl.clientlogin(self.get_username, self.get_password)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_get_all_calendars
|
28
|
+
response = @cl.get('http://www.google.com/calendar/feeds/default/allcalendars/full')
|
29
|
+
self.assert_equal(200, response.status_code, 'Must not be a redirect.')
|
30
|
+
self.assert_not_nil(@cl.session_cookie, 'Must have a session cookie.')
|
31
|
+
feed = response.to_xml
|
32
|
+
self.assert_not_nil(feed, 'feed can not be nil')
|
33
|
+
|
34
|
+
#login again to make sure the session cookie gets cleared
|
35
|
+
@cl.clientlogin(self.get_username, self.get_password)
|
36
|
+
self.assert_nil(@cl.session_cookie, 'Should clear session cookie.')
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
end
|