google_drive 1.0.0.pre1 → 1.0.0.pre2
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.
- checksums.yaml +4 -4
- data/README.rdoc +9 -2
- data/lib/google_drive/api_client_fetcher.rb +3 -0
- data/lib/google_drive/authentication_error.rb +2 -2
- data/lib/google_drive/error.rb +1 -1
- data/lib/google_drive/response_code_error.rb +24 -0
- data/lib/google_drive/session.rb +4 -5
- data/lib/google_drive/worksheet.rb +39 -45
- data/lib/{google_drive_v1.rb → google_drive_v0.rb} +9 -9
- data/lib/{google_drive_v1 → google_drive_v0}/acl.rb +7 -7
- data/lib/{google_drive_v1 → google_drive_v0}/acl_entry.rb +3 -3
- data/lib/{google_drive_v1 → google_drive_v0}/api_client_fetcher.rb +1 -1
- data/lib/google_drive_v0/authentication_error.rb +14 -0
- data/lib/{google_drive_v1 → google_drive_v0}/basic_fetcher.rb +1 -1
- data/lib/{google_drive_v1 → google_drive_v0}/client_login_fetcher.rb +2 -2
- data/lib/{google_drive_v1 → google_drive_v0}/collection.rb +12 -12
- data/lib/{google_drive_v1 → google_drive_v0}/error.rb +1 -1
- data/lib/{google_drive_v1 → google_drive_v0}/file.rb +9 -9
- data/lib/{google_drive_v1 → google_drive_v0}/list.rb +15 -15
- data/lib/{google_drive_v1 → google_drive_v0}/list_row.rb +4 -4
- data/lib/{google_drive_v1 → google_drive_v0}/oauth1_fetcher.rb +1 -1
- data/lib/{google_drive_v1 → google_drive_v0}/oauth2_fetcher.rb +2 -2
- data/lib/{google_drive_v1 → google_drive_v0}/record.rb +4 -4
- data/lib/{google_drive_v1 → google_drive_v0}/session.rb +45 -45
- data/lib/{google_drive_v1 → google_drive_v0}/spreadsheet.rb +17 -17
- data/lib/{google_drive_v1 → google_drive_v0}/table.rb +6 -6
- data/lib/{google_drive_v1 → google_drive_v0}/util.rb +1 -1
- data/lib/{google_drive_v1 → google_drive_v0}/worksheet.rb +13 -13
- metadata +23 -22
- data/lib/google_drive_v1/authentication_error.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d9ee76291f5aafbc59e093fe4e10d39e145f754
|
4
|
+
data.tar.gz: a0b8c073cc8aa484bdb7c0e7485272ac94c60991
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d09a5b9cb38197481392383a56a37ca957e44676dc3d910d8832254cf1d4db8d03d287578be74a1adb6152596168aa4abe718adc5097dbb7e7989a4be559756
|
7
|
+
data.tar.gz: 5a24e7d09facd452ddd125ba6667c1307d848e3a813d71c7aa940025a1a936c0126e200cf87bee64efafa4dda2adfcefd88b63e176169d6d89a9d8a8e1daecb0
|
data/README.rdoc
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
-
This is a Ruby 1.
|
1
|
+
This is a Ruby 1.9/2.0 library to read/write files/spreadsheets in Google Drive/Docs.
|
2
2
|
|
3
3
|
NOTE: This is NOT a library to create Google Drive App.
|
4
4
|
|
5
5
|
|
6
|
+
= Incompatibility introduced in ver. 1.0.0
|
7
|
+
|
8
|
+
Ver. 1.0.0 is not 100% backward compatible with 0.3.x. Some methods have been removed. Especially, GoogleDrive.login has been removed, and you must use GoogleDrive.login_with_oauth instead, as in the example code below.
|
9
|
+
|
10
|
+
I recommend to switch to the new API. But if you somehow want to continue using the old API, you can keep using it by requiring "google_drive_v0" instead of "google_drive" and use GoogleDriveV0 class instead of GoogleDrive class. It should continue working at least until April 20, 2015 when Google stops support of Documents List API.
|
11
|
+
|
12
|
+
|
6
13
|
= How to install
|
7
14
|
|
8
15
|
$ sudo gem install google_drive
|
@@ -60,7 +67,7 @@ Example to read/write spreadsheets:
|
|
60
67
|
# Same as the code above to get access_token...
|
61
68
|
|
62
69
|
# Creates a session.
|
63
|
-
session = GoogleDrive.
|
70
|
+
session = GoogleDrive.login_with_oauth(access_token)
|
64
71
|
|
65
72
|
# First worksheet of
|
66
73
|
# https://docs.google.com/spreadsheet/ccc?key=pz7XtlQC-PYx-jrVMJErTcg
|
@@ -30,6 +30,9 @@ module GoogleDrive
|
|
30
30
|
|
31
31
|
def initialize(client)
|
32
32
|
@client = client
|
33
|
+
# Sets virtually infinite default timeout because some operations (e.g., uploading
|
34
|
+
# a large files/spreadsheets) can take very long.
|
35
|
+
@client.connection.options[:timeout] ||= 100000000
|
33
36
|
@drive = @client.discovered_api("drive", "v2")
|
34
37
|
end
|
35
38
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# Author: Hiroshi Ichikawa <http://gimite.net/>
|
2
2
|
# The license of this source is "New BSD Licence"
|
3
3
|
|
4
|
-
require "google_drive/
|
4
|
+
require "google_drive/response_code_error"
|
5
5
|
|
6
6
|
|
7
7
|
module GoogleDrive
|
8
8
|
|
9
9
|
# Raised when GoogleDrive.login has failed.
|
10
|
-
class AuthenticationError < GoogleDrive::
|
10
|
+
class AuthenticationError < GoogleDrive::ResponseCodeError
|
11
11
|
|
12
12
|
end
|
13
13
|
|
data/lib/google_drive/error.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Author: Hiroshi Ichikawa <http://gimite.net/>
|
2
|
+
# The license of this source is "New BSD Licence"
|
3
|
+
|
4
|
+
require "cgi"
|
5
|
+
|
6
|
+
require "google_drive/error"
|
7
|
+
|
8
|
+
|
9
|
+
module GoogleDrive
|
10
|
+
|
11
|
+
# Raised when an HTTP request has returned an unexpected response code.
|
12
|
+
class ResponseCodeError < GoogleDrive::Error
|
13
|
+
|
14
|
+
def initialize(code, body, method, url) #:nodoc:#
|
15
|
+
@code = code
|
16
|
+
@body = body
|
17
|
+
super("Response code %s for %s %s: %s" % [code, method, url, CGI.unescapeHTML(body)])
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader(:code, :body)
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/google_drive/session.rb
CHANGED
@@ -14,6 +14,7 @@ require "google_drive/util"
|
|
14
14
|
require "google_drive/api_client_fetcher"
|
15
15
|
require "google_drive/error"
|
16
16
|
require "google_drive/authentication_error"
|
17
|
+
require "google_drive/response_code_error"
|
17
18
|
require "google_drive/spreadsheet"
|
18
19
|
require "google_drive/worksheet"
|
19
20
|
require "google_drive/collection"
|
@@ -419,11 +420,9 @@ module GoogleDrive
|
|
419
420
|
if response.code == "401" && @on_auth_fail && @on_auth_fail.call()
|
420
421
|
next
|
421
422
|
end
|
422
|
-
if !(response.code =~ /^
|
423
|
-
raise(
|
424
|
-
|
425
|
-
"Response code #{response.code} for #{method} #{url}: " +
|
426
|
-
CGI.unescapeHTML(response.body))
|
423
|
+
if !(response.code =~ /^2/)
|
424
|
+
raise((response.code == "401" ? AuthenticationError : ResponseCodeError).
|
425
|
+
new(response.code, response.body, method, url))
|
427
426
|
end
|
428
427
|
return convert_response(response, response_type)
|
429
428
|
end
|
@@ -297,54 +297,48 @@ module GoogleDrive
|
|
297
297
|
cell_entries[[row, col]] = entry
|
298
298
|
end
|
299
299
|
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
entry
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
<
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
<link rel="edit" type="application/atom+xml"
|
321
|
-
href="#{h(edit_url)}"/>
|
322
|
-
<gs:cell row="#{h(row)}" col="#{h(col)}" inputValue="#{h(value)}"/>
|
323
|
-
</entry>
|
324
|
-
EOS
|
325
|
-
end
|
326
|
-
xml << <<-"EOS"
|
327
|
-
</feed>
|
300
|
+
xml = <<-EOS
|
301
|
+
<feed xmlns="http://www.w3.org/2005/Atom"
|
302
|
+
xmlns:batch="http://schemas.google.com/gdata/batch"
|
303
|
+
xmlns:gs="http://schemas.google.com/spreadsheets/2006">
|
304
|
+
<id>#{h(self.cells_feed_url)}</id>
|
305
|
+
EOS
|
306
|
+
for row, col in @modified
|
307
|
+
value = @cells[[row, col]]
|
308
|
+
entry = cell_entries[[row, col]]
|
309
|
+
id = entry.css("id").text
|
310
|
+
edit_url = entry.css("link[rel='edit']")[0]["href"]
|
311
|
+
xml << <<-EOS
|
312
|
+
<entry>
|
313
|
+
<batch:id>#{h(row)},#{h(col)}</batch:id>
|
314
|
+
<batch:operation type="update"/>
|
315
|
+
<id>#{h(id)}</id>
|
316
|
+
<link rel="edit" type="application/atom+xml"
|
317
|
+
href="#{h(edit_url)}"/>
|
318
|
+
<gs:cell row="#{h(row)}" col="#{h(col)}" inputValue="#{h(value)}"/>
|
319
|
+
</entry>
|
328
320
|
EOS
|
321
|
+
end
|
322
|
+
xml << <<-"EOS"
|
323
|
+
</feed>
|
324
|
+
EOS
|
329
325
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
end
|
326
|
+
batch_url = concat_url(self.cells_feed_url, "/batch")
|
327
|
+
result = @session.request(
|
328
|
+
:post,
|
329
|
+
batch_url,
|
330
|
+
:data => xml,
|
331
|
+
:header => {"Content-Type" => "application/atom+xml;charset=utf-8", "If-Match" => "*"})
|
332
|
+
for entry in result.css("entry")
|
333
|
+
interrupted = entry.css("batch|interrupted")[0]
|
334
|
+
if interrupted
|
335
|
+
raise(GoogleDrive::Error, "Update has failed: %s" %
|
336
|
+
interrupted["reason"])
|
337
|
+
end
|
338
|
+
if !(entry.css("batch|status").first["code"] =~ /^2/)
|
339
|
+
raise(GoogleDrive::Error, "Updating cell %s has failed: %s" %
|
340
|
+
[entry.css("id").text, entry.css("batch|status")[0]["reason"]])
|
346
341
|
end
|
347
|
-
|
348
342
|
end
|
349
343
|
|
350
344
|
@modified.clear()
|
@@ -5,13 +5,13 @@ require "rubygems"
|
|
5
5
|
require "google/api_client"
|
6
6
|
require "json"
|
7
7
|
|
8
|
-
require "
|
8
|
+
require "google_drive_v0/session"
|
9
9
|
|
10
10
|
|
11
|
-
module
|
11
|
+
module GoogleDriveV0
|
12
12
|
|
13
|
-
# Authenticates with given +mail+ and +password+, and returns
|
14
|
-
# if succeeds. Raises
|
13
|
+
# Authenticates with given +mail+ and +password+, and returns GoogleDriveV0::Session
|
14
|
+
# if succeeds. Raises GoogleDriveV0::AuthenticationError if fails.
|
15
15
|
# Google Apps account is supported.
|
16
16
|
#
|
17
17
|
# +proxy+ is deprecated, and will be removed in the next version.
|
@@ -42,14 +42,14 @@ module GoogleDriveV1
|
|
42
42
|
# # Redirect the user to auth_url and get authorization code from redirect URL.
|
43
43
|
# auth_token = client.auth_code.get_token(
|
44
44
|
# authorization_code, :redirect_uri => "http://example.com/")
|
45
|
-
# session =
|
45
|
+
# session = GoogleDriveV0.login_with_oauth(auth_token.token)
|
46
46
|
#
|
47
47
|
# Or, from existing refresh token:
|
48
48
|
#
|
49
49
|
# auth_token = OAuth2::AccessToken.from_hash(client,
|
50
50
|
# {:refresh_token => refresh_token, :expires_at => expires_at})
|
51
51
|
# auth_token = auth_token.refresh!
|
52
|
-
# session =
|
52
|
+
# session = GoogleDriveV0.login_with_oauth(auth_token.token)
|
53
53
|
#
|
54
54
|
# If your app is not a Web app, use "urn:ietf:wg:oauth:2.0:oob" as redirect_url. Then
|
55
55
|
# authorization code is shown after authorization.
|
@@ -66,12 +66,12 @@ module GoogleDriveV1
|
|
66
66
|
|
67
67
|
# Restores session using return value of auth_tokens method of previous session.
|
68
68
|
#
|
69
|
-
# See
|
69
|
+
# See GoogleDriveV0.login for description of parameter +proxy+.
|
70
70
|
def self.restore_session(auth_tokens, proxy = nil)
|
71
71
|
return Session.restore_session(auth_tokens, proxy)
|
72
72
|
end
|
73
73
|
|
74
|
-
# Restores
|
74
|
+
# Restores GoogleDriveV0::Session from +path+ and returns it.
|
75
75
|
# If +path+ doesn't exist or authentication has failed, prompts the user to authorize the access,
|
76
76
|
# stores the session to +path+ and returns it.
|
77
77
|
#
|
@@ -141,7 +141,7 @@ module GoogleDriveV1
|
|
141
141
|
|
142
142
|
end
|
143
143
|
|
144
|
-
return
|
144
|
+
return GoogleDriveV0.login_with_oauth(auth.access_token)
|
145
145
|
|
146
146
|
end
|
147
147
|
|
@@ -3,14 +3,14 @@
|
|
3
3
|
# Author: Hiroshi Ichikawa <http://gimite.net/>
|
4
4
|
# The license of this source is "New BSD Licence"
|
5
5
|
|
6
|
-
require "
|
6
|
+
require "google_drive_v0/acl_entry"
|
7
7
|
|
8
|
-
module
|
8
|
+
module GoogleDriveV0
|
9
9
|
|
10
10
|
# ACL (access control list) of a spreadsheet.
|
11
11
|
#
|
12
|
-
# Use
|
13
|
-
# See
|
12
|
+
# Use GoogleDriveV0::Spreadsheet#acl to get GoogleDriveV0::Acl object.
|
13
|
+
# See GoogleDriveV0::Spreadsheet#acl for usage example.
|
14
14
|
#
|
15
15
|
# This code is based on https://github.com/guyboertje/gdata-spreadsheet-ruby .
|
16
16
|
class Acl
|
@@ -28,9 +28,9 @@ module GoogleDriveV1
|
|
28
28
|
|
29
29
|
def_delegators(:@acls, :size, :[], :each)
|
30
30
|
|
31
|
-
# Adds a new entry. +entry+ is either a
|
32
|
-
# :scope_type, :scope and :role. See
|
33
|
-
#
|
31
|
+
# Adds a new entry. +entry+ is either a GoogleDriveV0::AclEntry or a Hash with keys
|
32
|
+
# :scope_type, :scope and :role. See GoogleDriveV0::AclEntry#scope_type and
|
33
|
+
# GoogleDriveV0::AclEntry#role for the document of the fields.
|
34
34
|
#
|
35
35
|
# NOTE: This sends email to the new people.
|
36
36
|
#
|
@@ -4,11 +4,11 @@
|
|
4
4
|
# Author: Phuogn Nguyen <https://github.com/phuongnd08>
|
5
5
|
# The license of this source is "New BSD Licence"
|
6
6
|
|
7
|
-
module
|
7
|
+
module GoogleDriveV0
|
8
8
|
|
9
9
|
# An entry of an ACL (access control list) of a spreadsheet.
|
10
10
|
#
|
11
|
-
# Use
|
11
|
+
# Use GoogleDriveV0::Acl#[] to get GoogleDriveV0::AclEntry object.
|
12
12
|
#
|
13
13
|
# This code is based on https://github.com/guyboertje/gdata-spreadsheet-ruby .
|
14
14
|
class AclEntry
|
@@ -41,7 +41,7 @@ module GoogleDriveV1
|
|
41
41
|
|
42
42
|
def edit_url
|
43
43
|
warn(
|
44
|
-
"WARNING:
|
44
|
+
"WARNING: GoogleDriveV0::AclEntry\#edit_url is deprecated and will be removed in the next version.")
|
45
45
|
return self.edit_url_internal
|
46
46
|
end
|
47
47
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Author: Hiroshi Ichikawa <http://gimite.net/>
|
2
|
+
# The license of this source is "New BSD Licence"
|
3
|
+
|
4
|
+
require "google_drive_v0/error"
|
5
|
+
|
6
|
+
|
7
|
+
module GoogleDriveV0
|
8
|
+
|
9
|
+
# Raised when GoogleDriveV0.login has failed.
|
10
|
+
class AuthenticationError < GoogleDriveV0::Error
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# Author: Hiroshi Ichikawa <http://gimite.net/>
|
2
2
|
# The license of this source is "New BSD Licence"
|
3
3
|
|
4
|
-
require "
|
4
|
+
require "google_drive_v0/basic_fetcher"
|
5
5
|
|
6
6
|
|
7
|
-
module
|
7
|
+
module GoogleDriveV0
|
8
8
|
|
9
9
|
class ClientLoginFetcher < BasicFetcher #:nodoc:
|
10
10
|
|
@@ -1,16 +1,16 @@
|
|
1
1
|
# Author: Hiroshi Ichikawa <http://gimite.net/>
|
2
2
|
# The license of this source is "New BSD Licence"
|
3
3
|
|
4
|
-
require "
|
5
|
-
require "
|
6
|
-
require "
|
4
|
+
require "google_drive_v0/util"
|
5
|
+
require "google_drive_v0/error"
|
6
|
+
require "google_drive_v0/spreadsheet"
|
7
7
|
|
8
8
|
|
9
|
-
module
|
9
|
+
module GoogleDriveV0
|
10
10
|
|
11
|
-
# Use
|
12
|
-
# or
|
13
|
-
class Collection <
|
11
|
+
# Use GoogleDriveV0::Session#root_collection, GoogleDriveV0::Collection#subcollections,
|
12
|
+
# or GoogleDriveV0::Session#collection_by_url to get GoogleDriveV0::Collection object.
|
13
|
+
class Collection < GoogleDriveV0::File
|
14
14
|
|
15
15
|
include(Util)
|
16
16
|
|
@@ -44,7 +44,7 @@ module GoogleDriveV1
|
|
44
44
|
return self.root? ? nil : super
|
45
45
|
end
|
46
46
|
|
47
|
-
# Adds the given
|
47
|
+
# Adds the given GoogleDriveV0::File to the collection.
|
48
48
|
def add(file)
|
49
49
|
header = {"GData-Version" => "3.0", "Content-Type" => "application/atom+xml;charset=utf-8"}
|
50
50
|
xml = <<-"EOS"
|
@@ -57,7 +57,7 @@ module GoogleDriveV1
|
|
57
57
|
return nil
|
58
58
|
end
|
59
59
|
|
60
|
-
# Creates a sub-collection with given title. Returns
|
60
|
+
# Creates a sub-collection with given title. Returns GoogleDriveV0::Collection object.
|
61
61
|
def create_subcollection(title)
|
62
62
|
header = {"GData-Version" => "3.0", "Content-Type" => "application/atom+xml;charset=utf-8"}
|
63
63
|
xml = <<-EOS
|
@@ -72,7 +72,7 @@ module GoogleDriveV1
|
|
72
72
|
return @session.entry_element_to_file(doc)
|
73
73
|
end
|
74
74
|
|
75
|
-
# Removes the given
|
75
|
+
# Removes the given GoogleDriveV0::File from the collection.
|
76
76
|
def remove(file)
|
77
77
|
url = to_v3_url("#{contents_url}/#{file.resource_id}")
|
78
78
|
@session.request(:delete, url, :auth => :writely, :header => {"If-Match" => "*"})
|
@@ -117,7 +117,7 @@ module GoogleDriveV1
|
|
117
117
|
end
|
118
118
|
|
119
119
|
# Returns a file (can be a spreadsheet, document, subcollection or other files) in the
|
120
|
-
# collection which exactly matches +title+ as
|
120
|
+
# collection which exactly matches +title+ as GoogleDriveV0::File.
|
121
121
|
# Returns nil if not found. If multiple collections with the +title+ are found, returns
|
122
122
|
# one of them.
|
123
123
|
#
|
@@ -126,7 +126,7 @@ module GoogleDriveV1
|
|
126
126
|
return file_by_title_with_type(title, nil)
|
127
127
|
end
|
128
128
|
|
129
|
-
# Returns its subcollection whose title exactly matches +title+ as
|
129
|
+
# Returns its subcollection whose title exactly matches +title+ as GoogleDriveV0::Collection.
|
130
130
|
# Returns nil if not found. If multiple collections with the +title+ are found, returns
|
131
131
|
# one of them.
|
132
132
|
#
|