gdata 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/gdata/client/base.rb +9 -8
- data/lib/gdata/client/calendar.rb +30 -0
- data/lib/gdata/client/youtube.rb +1 -0
- data/lib/gdata/http/request.rb +1 -0
- data/test/tc_gdata_auth_clientlogin.rb +8 -0
- data/test/tc_gdata_client_calendar.rb +40 -0
- data/test/ts_gdata_client.rb +2 -0
- metadata +3 -2
data/Rakefile
CHANGED
@@ -50,7 +50,7 @@ spec = Gem::Specification.new do |s|
|
|
50
50
|
s.summary = "Google Data APIs Ruby Utility Library"
|
51
51
|
s.rubyforge_project = 'gdata'
|
52
52
|
s.name = 'gdata'
|
53
|
-
s.version = '1.0.
|
53
|
+
s.version = '1.0.1'
|
54
54
|
s.requirements << 'none'
|
55
55
|
s.require_path = 'lib'
|
56
56
|
s.test_files = FileList['test/ts_gdata.rb']
|
data/lib/gdata/client/base.rb
CHANGED
@@ -12,8 +12,6 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require "rexml/document"
|
16
|
-
|
17
15
|
module GData
|
18
16
|
module Client
|
19
17
|
|
@@ -83,7 +81,7 @@ module GData
|
|
83
81
|
response = service.make_request(request)
|
84
82
|
|
85
83
|
case response.status_code
|
86
|
-
when 200, 201
|
84
|
+
when 200, 201, 302
|
87
85
|
#Do nothing, it's a success.
|
88
86
|
when 401, 403
|
89
87
|
raise AuthorizationError, response.body
|
@@ -142,12 +140,15 @@ module GData
|
|
142
140
|
return headers
|
143
141
|
end
|
144
142
|
|
145
|
-
# Performs ClientLogin for the service.
|
146
|
-
|
143
|
+
# Performs ClientLogin for the service. See GData::Auth::ClientLogin
|
144
|
+
# for details.
|
145
|
+
def clientlogin(username, password, captcha_token = nil,
|
146
|
+
captcha_answer = nil, service = nil, account_type = nil)
|
147
147
|
if service.nil?
|
148
148
|
service = @clientlogin_service
|
149
149
|
end
|
150
|
-
|
150
|
+
options = { :account_type => account_type }
|
151
|
+
self.auth_handler = GData::Auth::ClientLogin.new(service, options)
|
151
152
|
if @clientlogin_url
|
152
153
|
@auth_handler.auth_url = @clientlogin_url
|
153
154
|
end
|
@@ -165,7 +166,7 @@ module GData
|
|
165
166
|
|
166
167
|
# Sets an AuthSub token for the service.
|
167
168
|
def authsub_token=(token)
|
168
|
-
|
169
|
+
self.auth_handler = GData::Auth::AuthSub.new(token)
|
169
170
|
end
|
170
171
|
|
171
172
|
# Sets a private key to use with AuthSub requests.
|
@@ -178,4 +179,4 @@ module GData
|
|
178
179
|
end
|
179
180
|
end
|
180
181
|
end
|
181
|
-
end
|
182
|
+
end
|
@@ -18,11 +18,41 @@ module GData
|
|
18
18
|
# Client class to wrap working with the Calendar Data API.
|
19
19
|
class Calendar < Base
|
20
20
|
|
21
|
+
# Holds on to a session cookie
|
22
|
+
attr_accessor :session_cookie
|
23
|
+
|
21
24
|
def initialize(options = {})
|
22
25
|
options[:clientlogin_service] ||= 'cl'
|
23
26
|
options[:authsub_scope] ||= 'http://www.google.com/calendar/feeds/'
|
24
27
|
super(options)
|
25
28
|
end
|
29
|
+
|
30
|
+
# Overrides auth_handler= so if the authentication changes,
|
31
|
+
# the session cookie is cleared.
|
32
|
+
def auth_handler=(handler)
|
33
|
+
@session_cookie = nil
|
34
|
+
return super(handler)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Overrides make_request to handle 302 redirects with a session cookie.
|
38
|
+
def make_request(method, url, body = '', retries = 4)
|
39
|
+
response = super(method, url, body)
|
40
|
+
if response.status_code == 302 and retries > 0
|
41
|
+
@session_cookie = response.headers['set-cookie']
|
42
|
+
return self.make_request(method, url, body,
|
43
|
+
retries - 1)
|
44
|
+
else
|
45
|
+
return response
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Custom prepare_headers to include the session cookie if it exists
|
50
|
+
def prepare_headers
|
51
|
+
if @session_cookie
|
52
|
+
@headers['cookie'] = @session_cookie
|
53
|
+
end
|
54
|
+
super
|
55
|
+
end
|
26
56
|
end
|
27
57
|
end
|
28
58
|
end
|
data/lib/gdata/client/youtube.rb
CHANGED
data/lib/gdata/http/request.rb
CHANGED
@@ -47,5 +47,13 @@ class TC_GData_Auth_ClientLogin < Test::Unit::TestCase
|
|
47
47
|
end
|
48
48
|
end
|
49
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
|
+
|
50
58
|
|
51
59
|
end
|
@@ -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
|
data/test/ts_gdata_client.rb
CHANGED
@@ -13,6 +13,7 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
require 'tc_gdata_client_base'
|
16
|
+
require 'tc_gdata_client_calendar'
|
16
17
|
require 'tc_gdata_client_photos'
|
17
18
|
require 'tc_gdata_client_youtube'
|
18
19
|
|
@@ -20,6 +21,7 @@ class TS_GData_Client
|
|
20
21
|
def self.suite
|
21
22
|
suite = Test::Unit::TestSuite.new
|
22
23
|
suite << TC_GData_Client_Base.suite
|
24
|
+
suite << TC_GData_Client_Calendar.suite
|
23
25
|
suite << TC_GData_Client_Photos.suite
|
24
26
|
suite << TC_GData_Client_YouTube.suite
|
25
27
|
return suite
|
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: 1.0.
|
4
|
+
version: 1.0.1
|
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: 2009-
|
12
|
+
date: 2009-04-06 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- test/tc_gdata_auth_authsub.rb
|
56
56
|
- test/tc_gdata_auth_clientlogin.rb
|
57
57
|
- test/tc_gdata_client_base.rb
|
58
|
+
- test/tc_gdata_client_calendar.rb
|
58
59
|
- test/tc_gdata_client_photos.rb
|
59
60
|
- test/tc_gdata_client_youtube.rb
|
60
61
|
- test/tc_gdata_http_mime_body.rb
|