google_drive 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2752fea3fdb95778f8fc63299c853b2c59733db7
4
- data.tar.gz: dabdc2d01823ea09bbb7a5c711b606ee99b9b55a
3
+ metadata.gz: 9f3de00c7d9e7589646ba3b4a85c5f94ffec2d2f
4
+ data.tar.gz: 09aea7b2c3900145d6415c6614f254ab347562c2
5
5
  SHA512:
6
- metadata.gz: 6c14714081c816a87140ba645aad48076519cf7817f4d9ce606c5c09c0de682dc26db70a6b46e234b0789295a880e82bbb6af8d063b45cd34557897855a5d49b
7
- data.tar.gz: 6a46e4256b8fe4f36e6bbaf1561c567ab2138ebf701121b73441c238f471dccddcfb708b125a4edd6e9ba6db510e75805ba0a1e49bfb8963830901c46e9e7f84
6
+ metadata.gz: d8357b2b90f33bc5a655904983a2ee77e46c768142ddc0e3ead86c313938a100992d89c2ee02f6d9a1e58ff696829f541859a1a9d7bf5741e0a51d7d6c05864b
7
+ data.tar.gz: f4aed23d0b698072149e54ac154667a4ea78eceaa19364962a89431035aa6131fdae58b1f83a5494431499c8d08a218dc4efce5f50f874692ea13d55fb423a5c
@@ -0,0 +1,139 @@
1
+ This is a Ruby library to read/write files/spreadsheets in Google Drive/Docs.
2
+
3
+ NOTE: This is NOT a library to create Google Drive App.
4
+
5
+
6
+ ## Migration from ver. 0.x.x / 1.x.x to to ver. 2.x.x
7
+
8
+ There are some incompatible API changes. See
9
+ [MIGRATING.md](https://github.com/gimite/google-drive-ruby/blob/master/MIGRATING.md).
10
+
11
+
12
+ ## How to install
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'google_drive'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ ```
23
+ $ bundle
24
+ ```
25
+
26
+ Or install it yourself as:
27
+
28
+ ```
29
+ $ gem install google_drive
30
+ ```
31
+
32
+ If you need system wide installation, execute below:
33
+
34
+ ```
35
+ $ sudo gem install google_drive
36
+ ```
37
+
38
+ ## How to use
39
+
40
+ First, follow Step 1 and 2 of "Authorizing requests with OAuth 2.0" in [this
41
+ page](https://developers.google.com/drive/v3/web/about-auth) to get a client
42
+ ID and client secret for OAuth. Set "Application type" to "Other" in the form
43
+ to create a client ID if you use GoogleDrive.saved_session method as in the
44
+ example below.
45
+
46
+ Next, create a file config.json which contains the client ID and crient secret
47
+ you got above, which looks like:
48
+
49
+ ```json
50
+ {
51
+ "client_id": "xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
52
+ "client_secret": "xxxxxxxxxxxxxxxxxxxxxxxx"
53
+ }
54
+ ```
55
+
56
+ Note that when using the OAuth flow, the client will be able to access all files
57
+ belonging to the the user who generated the token. To set permissions more
58
+ specifically, you may want to consider using a service account. [See full docs
59
+ in the login_with_oauth method.](https://github.com/gimite/google-drive-ruby/blob/lib/google_drive.rb)
60
+
61
+ ### Example to read/write files in Google Drive:
62
+
63
+ ```ruby
64
+ require "google_drive"
65
+
66
+ # Creates a session. This will prompt the credential via command line for the
67
+ # first time and save it to config.json file for later usages.
68
+ session = GoogleDrive.saved_session("config.json")
69
+
70
+ # Gets list of remote files.
71
+ session.files.each do |file|
72
+ p file.title
73
+ end
74
+
75
+ # Uploads a local file.
76
+ session.upload_from_file("/path/to/hello.txt", "hello.txt", convert: false)
77
+
78
+ # Downloads to a local file.
79
+ file = session.file_by_title("hello.txt")
80
+ file.download_to_file("/path/to/hello.txt")
81
+
82
+ # Updates content of the remote file.
83
+ file.update_from_file("/path/to/hello.txt")
84
+ ```
85
+
86
+ ### Example to read/write spreadsheets:
87
+
88
+ ```ruby
89
+ require "google_drive"
90
+
91
+ # Creates a session. This will prompt the credential via command line for the
92
+ # first time and save it to config.json file for later usages.
93
+ session = GoogleDrive.saved_session("config.json")
94
+
95
+ # First worksheet of
96
+ # https://docs.google.com/spreadsheet/ccc?key=pz7XtlQC-PYx-jrVMJErTcg
97
+ # Or https://docs.google.com/a/someone.com/spreadsheets/d/pz7XtlQC-PYx-jrVMJErTcg/edit?usp=drive_web
98
+ ws = session.spreadsheet_by_key("pz7XtlQC-PYx-jrVMJErTcg").worksheets[0]
99
+
100
+ # Gets content of A2 cell.
101
+ p ws[2, 1] #==> "hoge"
102
+
103
+ # Changes content of cells.
104
+ # Changes are not sent to the server until you call ws.save().
105
+ ws[2, 1] = "foo"
106
+ ws[2, 2] = "bar"
107
+ ws.save
108
+
109
+ # Dumps all cells.
110
+ (1..ws.num_rows).each do |row|
111
+ (1..ws.num_cols).each do |col|
112
+ p ws[row, col]
113
+ end
114
+ end
115
+
116
+ # Yet another way to do so.
117
+ p ws.rows #==> [["fuga", ""], ["foo", "bar]]
118
+
119
+ # Reloads the worksheet to get changes by other clients.
120
+ ws.reload
121
+ ```
122
+
123
+ ## Full API documentation
124
+
125
+ [API documentation in RubyDoc.info](http://www.rubydoc.info/gems/google_drive)
126
+
127
+ ## Source code
128
+
129
+ [Github](http://github.com/gimite/google-drive-ruby)
130
+
131
+ The license of this source is "New BSD Licence"
132
+
133
+ ## Supported environments
134
+
135
+ Ruby 2.0.0 or later. Checked with Ruby 2.3.0.
136
+
137
+ ## Author
138
+
139
+ [Hiroshi Ichikawa](http://gimite.net/en/index.php?Contact)
@@ -48,6 +48,22 @@ module GoogleDrive
48
48
  # session = GoogleDrive.login_with_oauth(credentials.access_token)
49
49
  #
50
50
  # For command-line apps, it would be easier to use saved_session method instead.
51
+ #
52
+ # To use service account authentication:
53
+ #
54
+ # 1. Go to the Credentials tab for your project in the Google API console: https://console.developers.google.com/apis/credentials
55
+ # 2. Create a service account key, and download the keys as JSON. (This address ends in iam.gserviceaccount.com.)
56
+ # 3. Share the Drive folders or files with the client_email address in the JSON you downloaded.
57
+ # 3. Set a GOOGLE_CLIENT_EMAIL environmental variable based on the client_email.
58
+ # 4. Set a GOOGLE_PRIVATE_KEY environmental variable based on the private_key in the JSON. Be careful to preserve newlines.
59
+ # 5. Create a GoogleDrive session from these environmental variables:
60
+ #
61
+ # session = GoogleDrive.login_with_oauth(Google::Auth::ServiceAccountCredentials.from_env(
62
+ # 'https://www.googleapis.com/auth/drive'
63
+ # ))
64
+ # The scope can be adjusted to be as broad or specific as necessary.
65
+ # The full list of scopes is available here: https://developers.google.com/drive/v2/web/scopes.
66
+ #
51
67
  def self.login_with_oauth(client_or_access_token, proxy = nil)
52
68
  Session.new(client_or_access_token, proxy)
53
69
  end
@@ -91,14 +107,15 @@ module GoogleDrive
91
107
  # save
92
108
  def self.saved_session(
93
109
  path_or_config = nil, proxy = nil, client_id = nil, client_secret = nil)
94
- config = case path_or_config
95
- when String
96
- Config.new(path_or_config)
97
- when nil
98
- Config.new(ENV['HOME'] + '/.ruby_google_drive.token')
99
- else
100
- path_or_config
101
- end
110
+ config =
111
+ case path_or_config
112
+ when String
113
+ Config.new(path_or_config)
114
+ when nil
115
+ Config.new(ENV['HOME'] + '/.ruby_google_drive.token')
116
+ else
117
+ path_or_config
118
+ end
102
119
 
103
120
  config.scope ||= [
104
121
  'https://www.googleapis.com/auth/drive',
@@ -122,8 +139,6 @@ module GoogleDrive
122
139
  'Specifying a proxy object is no longer supported. Set ENV["http_proxy"] instead.')
123
140
  end
124
141
 
125
- refresh_token = config.refresh_token
126
-
127
142
  credentials = Google::Auth::UserRefreshCredentials.new(
128
143
  client_id: config.client_id,
129
144
  client_secret: config.client_secret,
@@ -63,7 +63,7 @@ module GoogleDrive
63
63
  # https://developers.google.com/drive/v3/reference/permissions/create
64
64
  def push(params_or_entry, options = {})
65
65
  entry = params_or_entry.is_a?(AclEntry) ? params_or_entry : AclEntry.new(params_or_entry)
66
- api_permission = @session.drive.create_permission(@file.id, entry.params, fields: '*')
66
+ api_permission = @session.drive.create_permission(@file.id, entry.params, {fields: '*'}.merge(options))
67
67
  new_entry = AclEntry.new(api_permission, self)
68
68
  @entries.push(new_entry)
69
69
  new_entry
@@ -60,6 +60,24 @@ module GoogleDrive
60
60
  files_with_type(nil, params, &block)
61
61
  end
62
62
 
63
+ # Same as Session#upload_from_file. It uploads file to current collection
64
+ def upload_from_file(path, title = nil, params = {})
65
+ params = {parents: [self.id]}.merge(params)
66
+ @session.upload_from_file(path, title, params)
67
+ end
68
+
69
+ # Same as Session#upload_from_io. It uploads file to current collection
70
+ def upload_from_io(io, title = 'Untitled', params = {})
71
+ params = {parents: [self.id]}.merge(params)
72
+ @session.upload_from_io(io, title, params)
73
+ end
74
+
75
+ # Same as Session#upload_from_string. It uploads file to current collection
76
+ def upload_from_string(content, title = 'Untitled', params = {})
77
+ params = {parents: [self.id]}.merge(params)
78
+ @session.upload_from_string(content, title, params)
79
+ end
80
+
63
81
  alias_method :contents, :files
64
82
 
65
83
  # Returns all the spreadsheets in the collection.
@@ -78,7 +78,7 @@ module GoogleDrive
78
78
  # This returns zero or one file type. You may be able to download the file in other formats using
79
79
  # export_as_file, export_as_string, or export_to_io.
80
80
  def available_content_types
81
- api_file.download_url ? [api_file.mime_type] : []
81
+ api_file.web_content_link ? [api_file.mime_type] : []
82
82
  end
83
83
 
84
84
  # Downloads the file to a local file. e.g.
@@ -86,7 +86,7 @@ module GoogleDrive
86
86
  #
87
87
  # To export the file in other formats, use export_as_file.
88
88
  def download_to_file(path, params = {})
89
- @session.drive.get_file(id, download_dest: path)
89
+ @session.drive.get_file(id, {download_dest: path}.merge(params))
90
90
  end
91
91
 
92
92
  # Downloads the file and returns as a String.
@@ -101,8 +101,8 @@ module GoogleDrive
101
101
  # Downloads the file and writes it to +io+.
102
102
  #
103
103
  # To export the file in other formats, use export_to_io.
104
- def download_to_io(io, _params = {})
105
- @session.drive.get_file(id, download_dest: io)
104
+ def download_to_io(io, params = {})
105
+ @session.drive.get_file(id, {download_dest: io}.merge(params))
106
106
  end
107
107
 
108
108
  # Export the file to +path+ in content type +format+.
@@ -6,8 +6,6 @@ require 'stringio'
6
6
 
7
7
  require 'rubygems'
8
8
  require 'nokogiri'
9
- require 'oauth'
10
- require 'oauth2'
11
9
  require 'googleauth'
12
10
 
13
11
  require 'google_drive/util'
@@ -42,21 +40,18 @@ module GoogleDrive
42
40
  if proxy
43
41
  fail(
44
42
  ArgumentError,
45
- "Specifying a proxy object is no longer supported. Set ENV[\"http_proxy\"] instead.")
43
+ 'Specifying a proxy object is no longer supported. Set ENV["http_proxy"] instead.')
46
44
  end
47
45
 
48
46
  if credentials_or_access_token
49
- case credentials_or_access_token
50
- when String
47
+ if credentials_or_access_token.is_a?(String)
51
48
  credentials = Google::Auth::UserRefreshCredentials.new(
52
49
  access_token: credentials_or_access_token)
53
- when OAuth2::AccessToken
50
+ # Equivalent of credentials_or_access_token.is_a?(OAuth2::AccessToken),
51
+ # without adding dependency to "oauth2" library.
52
+ elsif credentials_or_access_token.class.ancestors.any?{ |m| m.name == 'OAuth2::AccessToken' }
54
53
  credentials = Google::Auth::UserRefreshCredentials.new(
55
54
  access_token: credentials_or_access_token.token)
56
- when OAuth::AccessToken
57
- fail(
58
- ArgumentError,
59
- 'OAuth1 is no longer supported. Use OAuth2 instead.')
60
55
  else
61
56
  credentials = credentials_or_access_token
62
57
  end
@@ -190,19 +185,28 @@ module GoogleDrive
190
185
  end
191
186
 
192
187
  # Returns GoogleDrive::Worksheet with given +url+.
193
- # You must specify URL of cell-based feed of the worksheet.
188
+ # You must specify URL of either worksheet feed or cell-based feed of the worksheet.
194
189
  #
195
- # e.g.
190
+ # e.g.:
191
+ # # Worksheet feed URL
192
+ # session.worksheet_by_url(
193
+ # "https://spreadsheets.google.com/feeds/worksheets/" +
194
+ # "1smypkyAz4STrKO4Zkos5Z4UPUJKvvgIza32LnlQ7OGw/private/full/od7")
195
+ # # Cell-based feed URL
196
196
  # session.worksheet_by_url(
197
- # "http://spreadsheets.google.com/feeds/" +
198
- # "cells/pz7XtlQC-PYxNmbBVgyiNWg/od6/private/full")
197
+ # "https://spreadsheets.google.com/feeds/cells/" +
198
+ # "1smypkyAz4STrKO4Zkos5Z4UPUJKvvgIza32LnlQ7OGw/od7/private/full")
199
199
  def worksheet_by_url(url)
200
- unless url =~
201
- %r{^https?://spreadsheets.google.com/feeds/cells/(.*)/(.*)/private/full((\?.*)?)$}
202
- fail(GoogleDrive::Error, "URL is not a cell-based feed URL: #{url}")
200
+ case url
201
+ when %r{^https?://spreadsheets.google.com/feeds/worksheets/.*/.*/full/.*$}
202
+ worksheet_feed_url = url
203
+ when %r{^https?://spreadsheets.google.com/feeds/cells/(.*)/(.*)/private/full((\?.*)?)$}
204
+ worksheet_feed_url = "https://spreadsheets.google.com/feeds/worksheets/" +
205
+ "#{Regexp.last_match(1)}/private/full/#{Regexp.last_match(2)}#{Regexp.last_match(3)}"
206
+ else
207
+ fail(GoogleDrive::Error, "URL is neither a worksheet feed URL nor a cell-based feed URL: #{url}")
203
208
  end
204
- worksheet_feed_url = "https://spreadsheets.google.com/feeds/worksheets/" +
205
- "#{Regexp.last_match(1)}/private/full/#{Regexp.last_match(2)}#{Regexp.last_match(3)}"
209
+
206
210
  worksheet_feed_entry = request(:get, worksheet_feed_url)
207
211
  Worksheet.new(self, nil, worksheet_feed_entry)
208
212
  end
@@ -310,7 +314,7 @@ module GoogleDrive
310
314
  end
311
315
 
312
316
  # Uploads a file. Reads content from +io+.
313
- # Returns a GoogleSpreadsheet::File object.
317
+ # Returns a GoogleDrive::File object.
314
318
  def upload_from_io(io, title = 'Untitled', params = {})
315
319
  upload_from_source(io, title, params)
316
320
  end
@@ -328,16 +332,15 @@ module GoogleDrive
328
332
 
329
333
  def execute_paged!(opts, &block) #:nodoc:
330
334
  if block
331
-
332
335
  page_token = nil
333
- begin
336
+ loop do
334
337
  parameters = (opts[:parameters] || {}).merge({page_token: page_token})
335
338
  (items, page_token) = execute_paged!(opts.merge(parameters: parameters))
336
339
  items.each(&block)
337
- end while page_token
340
+ break unless page_token
341
+ end
338
342
 
339
343
  elsif opts[:parameters] && opts[:parameters].key?(:page_token)
340
-
341
344
  response = opts[:method].call(opts[:parameters])
342
345
  items = response.__send__(opts[:items_method_name]).map do |item|
343
346
  opts[:converter] ? opts[:converter].call(item) : item
@@ -345,8 +348,8 @@ module GoogleDrive
345
348
  return [items, response.next_page_token]
346
349
 
347
350
  else
348
- parameters = (opts[:parameters] || {}).merge({page_token: nil})
349
- (items, next_page_token) = execute_paged!(opts.merge(parameters: parameters))
351
+ parameters = (opts[:parameters] || {}).merge({page_token: nil})
352
+ (items, _) = execute_paged!(opts.merge(parameters: parameters))
350
353
  items
351
354
  end
352
355
  end
@@ -391,7 +394,7 @@ module GoogleDrive
391
394
  fields: '*',
392
395
  }
393
396
  for k, v in params
394
- if ![:convert, :convert_mime_type].include?(k)
397
+ if ![:convert, :convert_mime_type, :parents].include?(k)
395
398
  api_params[k] = v
396
399
  end
397
400
  end
@@ -403,6 +406,9 @@ module GoogleDrive
403
406
  elsif params.fetch(:convert, true) && IMPORTABLE_CONTENT_TYPE_MAP.key?(content_type)
404
407
  file_metadata[:mime_type] = IMPORTABLE_CONTENT_TYPE_MAP[content_type]
405
408
  end
409
+ if params[:parents]
410
+ file_metadata[:parents] = params[:parents]
411
+ end
406
412
 
407
413
  file = self.drive.create_file(file_metadata, api_params)
408
414
  wrap_api_file(file)
@@ -255,18 +255,16 @@ module GoogleDrive
255
255
 
256
256
  # Shifts all cells below the row.
257
257
  self.max_rows += rows.size
258
- r = num_rows
259
- while r >= row_num
260
- for c in 1..num_cols
258
+ num_rows.downto(row_num) do |r|
259
+ (1..num_cols).each do |c|
261
260
  self[r + rows.size, c] = self[r, c]
262
261
  end
263
- r -= 1
264
262
  end
265
263
 
266
264
  # Fills in the inserted rows.
267
265
  num_cols = self.num_cols
268
266
  rows.each_with_index do |row, r|
269
- for c in 0...[row.size, num_cols].max
267
+ (0...[row.size, num_cols].max).each do |c|
270
268
  self[row_num + r, 1 + c] = row[c] || ''
271
269
  end
272
270
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_drive
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Ichikawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-28 00:00:00.000000000 Z
11
+ date: 2016-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -30,46 +30,6 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 2.0.0
33
- - !ruby/object:Gem::Dependency
34
- name: oauth
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: 0.3.6
40
- - - "<"
41
- - !ruby/object:Gem::Version
42
- version: 1.0.0
43
- type: :runtime
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: 0.3.6
50
- - - "<"
51
- - !ruby/object:Gem::Version
52
- version: 1.0.0
53
- - !ruby/object:Gem::Dependency
54
- name: oauth2
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- version: 0.5.0
60
- - - "<"
61
- - !ruby/object:Gem::Version
62
- version: 2.0.0
63
- type: :runtime
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: 0.5.0
70
- - - "<"
71
- - !ruby/object:Gem::Version
72
- version: 2.0.0
73
33
  - !ruby/object:Gem::Dependency
74
34
  name: google-api-client
75
35
  requirement: !ruby/object:Gem::Requirement
@@ -169,12 +129,9 @@ email:
169
129
  - gimite+github@gmail.com
170
130
  executables: []
171
131
  extensions: []
172
- extra_rdoc_files:
173
- - README.rdoc
174
- - doc_src/google_drive/acl.rb
132
+ extra_rdoc_files: []
175
133
  files:
176
- - README.rdoc
177
- - doc_src/google_drive/acl.rb
134
+ - README.md
178
135
  - lib/google_drive.rb
179
136
  - lib/google_drive/acl.rb
180
137
  - lib/google_drive/acl_entry.rb
@@ -196,9 +153,7 @@ licenses:
196
153
  - BSD-3-Clause
197
154
  metadata: {}
198
155
  post_install_message:
199
- rdoc_options:
200
- - "--main"
201
- - README.rdoc
156
+ rdoc_options: []
202
157
  require_paths:
203
158
  - lib
204
159
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -1,101 +0,0 @@
1
- This is a Ruby library to read/write files/spreadsheets in Google Drive/Docs.
2
-
3
- NOTE: This is NOT a library to create Google Drive App.
4
-
5
-
6
- = Migration from ver. 0.x.x / 1.x.x to to ver. 2.x.x
7
-
8
- There are some incompatible API changes. See {MIGRATING.md}[https://github.com/gimite/google-drive-ruby/blob/master/MIGRATING.md].
9
-
10
-
11
- = How to install
12
-
13
- $ sudo gem install google_drive
14
-
15
-
16
- = How to use
17
-
18
- First, follow Step 1 and 2 of "Authorizing requests with OAuth 2.0" in {this page}[https://developers.google.com/drive/v3/web/about-auth] to get a client ID and client secret for OAuth. Set "Application type" to "Other" in the form to create a client ID if you use GoogleDrive.saved_session method as in the example below.
19
-
20
- Next, create a file config.json which contains the client ID and crient secret you got above, which looks like:
21
-
22
- {
23
- "client_id": "xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
24
- "client_secret": "xxxxxxxxxxxxxxxxxxxxxxxx"
25
- }
26
-
27
- Example to read/write files in Google Drive:
28
-
29
- require "google_drive"
30
-
31
- # Creates a session. This will prompt the credential via command line for the
32
- # first time and save it to config.json file for later usages.
33
- session = GoogleDrive.saved_session("config.json")
34
-
35
- # Gets list of remote files.
36
- session.files.each do |file|
37
- p file.title
38
- end
39
-
40
- # Uploads a local file.
41
- session.upload_from_file("/path/to/hello.txt", "hello.txt", convert: false)
42
-
43
- # Downloads to a local file.
44
- file = session.file_by_title("hello.txt")
45
- file.download_to_file("/path/to/hello.txt")
46
-
47
- # Updates content of the remote file.
48
- file.update_from_file("/path/to/hello.txt")
49
-
50
- Example to read/write spreadsheets:
51
-
52
- require "google_drive"
53
-
54
- # Creates a session. This will prompt the credential via command line for the
55
- # first time and save it to config.json file for later usages.
56
- session = GoogleDrive.saved_session("config.json")
57
-
58
- # First worksheet of
59
- # https://docs.google.com/spreadsheet/ccc?key=pz7XtlQC-PYx-jrVMJErTcg
60
- # Or https://docs.google.com/a/someone.com/spreadsheets/d/pz7XtlQC-PYx-jrVMJErTcg/edit?usp=drive_web
61
- ws = session.spreadsheet_by_key("pz7XtlQC-PYx-jrVMJErTcg").worksheets[0]
62
-
63
- # Gets content of A2 cell.
64
- p ws[2, 1] #==> "hoge"
65
-
66
- # Changes content of cells.
67
- # Changes are not sent to the server until you call ws.save().
68
- ws[2, 1] = "foo"
69
- ws[2, 2] = "bar"
70
- ws.save
71
-
72
- # Dumps all cells.
73
- (1..ws.num_rows).each do |row|
74
- (1..ws.num_cols).each do |col|
75
- p ws[row, col]
76
- end
77
- end
78
-
79
- # Yet another way to do so.
80
- p ws.rows #==> [["fuga", ""], ["foo", "bar]]
81
-
82
- # Reloads the worksheet to get changes by other clients.
83
- ws.reload
84
-
85
- API document: http://www.rubydoc.info/gems/google_drive
86
-
87
- = Source code
88
-
89
- http://github.com/gimite/google-drive-ruby
90
-
91
- The license of this source is "New BSD Licence"
92
-
93
-
94
- = Supported environments
95
-
96
- Ruby 2.0.0 or later. Checked with Ruby 2.3.0.
97
-
98
-
99
- = Author
100
-
101
- Hiroshi Ichikawa - http://gimite.net/en/index.php?Contact
@@ -1,16 +0,0 @@
1
- module GoogleDrive
2
- class Acl
3
- # Returns the number of entries.
4
- def size
5
- end
6
-
7
- # Returns GoogleDrive::AclEntry object at +index+.
8
- def [](index)
9
- end
10
-
11
- # Iterates over GoogleDrive::AclEntry objects.
12
- def each(&_block)
13
- yield(entry)
14
- end
15
- end
16
- end