google_drive 1.0.0.pre1 → 1.0.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +9 -2
  3. data/lib/google_drive/api_client_fetcher.rb +3 -0
  4. data/lib/google_drive/authentication_error.rb +2 -2
  5. data/lib/google_drive/error.rb +1 -1
  6. data/lib/google_drive/response_code_error.rb +24 -0
  7. data/lib/google_drive/session.rb +4 -5
  8. data/lib/google_drive/worksheet.rb +39 -45
  9. data/lib/{google_drive_v1.rb → google_drive_v0.rb} +9 -9
  10. data/lib/{google_drive_v1 → google_drive_v0}/acl.rb +7 -7
  11. data/lib/{google_drive_v1 → google_drive_v0}/acl_entry.rb +3 -3
  12. data/lib/{google_drive_v1 → google_drive_v0}/api_client_fetcher.rb +1 -1
  13. data/lib/google_drive_v0/authentication_error.rb +14 -0
  14. data/lib/{google_drive_v1 → google_drive_v0}/basic_fetcher.rb +1 -1
  15. data/lib/{google_drive_v1 → google_drive_v0}/client_login_fetcher.rb +2 -2
  16. data/lib/{google_drive_v1 → google_drive_v0}/collection.rb +12 -12
  17. data/lib/{google_drive_v1 → google_drive_v0}/error.rb +1 -1
  18. data/lib/{google_drive_v1 → google_drive_v0}/file.rb +9 -9
  19. data/lib/{google_drive_v1 → google_drive_v0}/list.rb +15 -15
  20. data/lib/{google_drive_v1 → google_drive_v0}/list_row.rb +4 -4
  21. data/lib/{google_drive_v1 → google_drive_v0}/oauth1_fetcher.rb +1 -1
  22. data/lib/{google_drive_v1 → google_drive_v0}/oauth2_fetcher.rb +2 -2
  23. data/lib/{google_drive_v1 → google_drive_v0}/record.rb +4 -4
  24. data/lib/{google_drive_v1 → google_drive_v0}/session.rb +45 -45
  25. data/lib/{google_drive_v1 → google_drive_v0}/spreadsheet.rb +17 -17
  26. data/lib/{google_drive_v1 → google_drive_v0}/table.rb +6 -6
  27. data/lib/{google_drive_v1 → google_drive_v0}/util.rb +1 -1
  28. data/lib/{google_drive_v1 → google_drive_v0}/worksheet.rb +13 -13
  29. metadata +23 -22
  30. 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: 76b903fb2d84303774103ab6da528579367ce8a5
4
- data.tar.gz: 04f591af34df950ba24d46a0ba0f6e099447f291
3
+ metadata.gz: 1d9ee76291f5aafbc59e093fe4e10d39e145f754
4
+ data.tar.gz: a0b8c073cc8aa484bdb7c0e7485272ac94c60991
5
5
  SHA512:
6
- metadata.gz: e5253faaa7c32a502d296354cc1aa1728c79136d009f45fb05801c21b490b4f6ec81c6995d3486c5742b9ecf96f7408ced12d08b3b46d2c9a729ba1d3379a148
7
- data.tar.gz: f52470706946884dd09e400b8fff2bd22af076947083910f58b92177566a80c96c8a9c833307c6f4ce9bc181ed7f6fa69723eff4a4e23faa31c0c91dd91a9c60
6
+ metadata.gz: 1d09a5b9cb38197481392383a56a37ca957e44676dc3d910d8832254cf1d4db8d03d287578be74a1adb6152596168aa4abe718adc5097dbb7e7989a4be559756
7
+ data.tar.gz: 5a24e7d09facd452ddd125ba6667c1307d848e3a813d71c7aa940025a1a936c0126e200cf87bee64efafa4dda2adfcefd88b63e176169d6d89a9d8a8e1daecb0
data/README.rdoc CHANGED
@@ -1,8 +1,15 @@
1
- This is a Ruby 1.8/1.9/2.0 library to read/write files/spreadsheets in Google Drive/Docs.
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.login(access_token)
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/error"
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::Error
10
+ class AuthenticationError < GoogleDrive::ResponseCodeError
11
11
 
12
12
  end
13
13
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  module GoogleDrive
6
6
 
7
- # Raised when spreadsheets.google.com has returned error.
7
+ # Raised on errors in this library.
8
8
  class Error < RuntimeError
9
9
 
10
10
  end
@@ -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
@@ -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 =~ /^[23]/)
423
- raise(
424
- response.code == "401" ? AuthenticationError : GoogleDrive::Error,
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
- # Updates cell values using batch operation.
301
- # If the data is large, we split it into multiple operations, otherwise batch may fail.
302
- @modified.each_slice(25) do |chunk|
303
-
304
- xml = <<-EOS
305
- <feed xmlns="http://www.w3.org/2005/Atom"
306
- xmlns:batch="http://schemas.google.com/gdata/batch"
307
- xmlns:gs="http://schemas.google.com/spreadsheets/2006">
308
- <id>#{h(self.cells_feed_url)}</id>
309
- EOS
310
- for row, col in chunk
311
- value = @cells[[row, col]]
312
- entry = cell_entries[[row, col]]
313
- id = entry.css("id").text
314
- edit_url = entry.css("link[rel='edit']")[0]["href"]
315
- xml << <<-EOS
316
- <entry>
317
- <batch:id>#{h(row)},#{h(col)}</batch:id>
318
- <batch:operation type="update"/>
319
- <id>#{h(id)}</id>
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
- batch_url = concat_url(self.cells_feed_url, "/batch")
331
- result = @session.request(
332
- :post,
333
- batch_url,
334
- :data => xml,
335
- :header => {"Content-Type" => "application/atom+xml;charset=utf-8", "If-Match" => "*"})
336
- for entry in result.css("entry")
337
- interrupted = entry.css("batch|interrupted")[0]
338
- if interrupted
339
- raise(GoogleDrive::Error, "Update has failed: %s" %
340
- interrupted["reason"])
341
- end
342
- if !(entry.css("batch|status").first["code"] =~ /^2/)
343
- raise(GoogleDrive::Error, "Updating cell %s has failed: %s" %
344
- [entry.css("id").text, entry.css("batch|status")[0]["reason"]])
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 "google_drive_v1/session"
8
+ require "google_drive_v0/session"
9
9
 
10
10
 
11
- module GoogleDriveV1
11
+ module GoogleDriveV0
12
12
 
13
- # Authenticates with given +mail+ and +password+, and returns GoogleDriveV1::Session
14
- # if succeeds. Raises GoogleDriveV1::AuthenticationError if fails.
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 = GoogleDriveV1.login_with_oauth(auth_token.token)
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 = GoogleDriveV1.login_with_oauth(auth_token.token)
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 GoogleDriveV1.login for description of parameter +proxy+.
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 GoogleDriveV1::Session from +path+ and returns it.
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 GoogleDriveV1.login_with_oauth(auth.access_token)
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 "google_drive_v1/acl_entry"
6
+ require "google_drive_v0/acl_entry"
7
7
 
8
- module GoogleDriveV1
8
+ module GoogleDriveV0
9
9
 
10
10
  # ACL (access control list) of a spreadsheet.
11
11
  #
12
- # Use GoogleDriveV1::Spreadsheet#acl to get GoogleDriveV1::Acl object.
13
- # See GoogleDriveV1::Spreadsheet#acl for usage example.
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 GoogleDriveV1::AclEntry or a Hash with keys
32
- # :scope_type, :scope and :role. See GoogleDriveV1::AclEntry#scope_type and
33
- # GoogleDriveV1::AclEntry#role for the document of the fields.
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 GoogleDriveV1
7
+ module GoogleDriveV0
8
8
 
9
9
  # An entry of an ACL (access control list) of a spreadsheet.
10
10
  #
11
- # Use GoogleDriveV1::Acl#[] to get GoogleDriveV1::AclEntry object.
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: GoogleDriveV1::AclEntry\#edit_url is deprecated and will be removed in the next version.")
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
 
@@ -6,7 +6,7 @@ require "uri"
6
6
  Net::HTTP.version_1_2
7
7
 
8
8
 
9
- module GoogleDriveV1
9
+ module GoogleDriveV0
10
10
 
11
11
  class ApiClientFetcher
12
12
 
@@ -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
@@ -6,7 +6,7 @@ require "uri"
6
6
  Net::HTTP.version_1_2
7
7
 
8
8
 
9
- module GoogleDriveV1
9
+ module GoogleDriveV0
10
10
 
11
11
  class BasicFetcher #:nodoc:
12
12
 
@@ -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 "google_drive_v1/basic_fetcher"
4
+ require "google_drive_v0/basic_fetcher"
5
5
 
6
6
 
7
- module GoogleDriveV1
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 "google_drive_v1/util"
5
- require "google_drive_v1/error"
6
- require "google_drive_v1/spreadsheet"
4
+ require "google_drive_v0/util"
5
+ require "google_drive_v0/error"
6
+ require "google_drive_v0/spreadsheet"
7
7
 
8
8
 
9
- module GoogleDriveV1
9
+ module GoogleDriveV0
10
10
 
11
- # Use GoogleDriveV1::Session#root_collection, GoogleDriveV1::Collection#subcollections,
12
- # or GoogleDriveV1::Session#collection_by_url to get GoogleDriveV1::Collection object.
13
- class Collection < GoogleDriveV1::File
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 GoogleDriveV1::File to the collection.
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 GoogleDriveV1::Collection object.
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 GoogleDriveV1::File from the collection.
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 GoogleDriveV1::File.
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 GoogleDriveV1::Collection.
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
  #