google_drive 2.1.1 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/lib/google_drive/access_token_credentials.rb +19 -0
- data/lib/google_drive/acl.rb +11 -8
- data/lib/google_drive/acl_entry.rb +6 -2
- data/lib/google_drive/collection.rb +6 -5
- data/lib/google_drive/config.rb +2 -1
- data/lib/google_drive/file.rb +2 -1
- data/lib/google_drive/list.rb +10 -5
- data/lib/google_drive/list_row.rb +2 -1
- data/lib/google_drive/response_code_error.rb +2 -1
- data/lib/google_drive/session.rb +27 -14
- data/lib/google_drive/util.rb +2 -1
- data/lib/google_drive/worksheet.rb +13 -15
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 584b24ba7f2e0849c5209e2343f33f553dc920f6
|
4
|
+
data.tar.gz: b6a5d71757609057cb510ea4177a14e9cb8355a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34f581e48edad100d18590d9556f25fbdcf348332c5e05afda8a0de7ac93a41244f773614e9d67fcc1ac3941e07c1726e74bd3797ea95571eff3a01c88ebc71e
|
7
|
+
data.tar.gz: f8787070a461e3d712f9dd9ab42c342b48016fac29f433c854ab6722b4abc8963f0e643b1282d9e7f3a38f1f0a7be4bb638c9fc6373c32399a8530862f8347af
|
data/README.md
CHANGED
@@ -103,15 +103,15 @@ p ws.rows #==> [["fuga", ""], ["foo", "bar]]
|
|
103
103
|
ws.reload
|
104
104
|
```
|
105
105
|
|
106
|
-
##
|
106
|
+
## Learn more
|
107
107
|
|
108
|
-
[API documentation
|
108
|
+
* [API documentation](http://www.rubydoc.info/gems/google_drive/2.1.1)
|
109
|
+
* [Authorization](https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md)
|
110
|
+
* [Github](http://github.com/gimite/google-drive-ruby)
|
109
111
|
|
110
|
-
##
|
112
|
+
## License
|
111
113
|
|
112
|
-
|
113
|
-
|
114
|
-
The license of this source is "New BSD Licence"
|
114
|
+
New BSD Licence.
|
115
115
|
|
116
116
|
## Supported environments
|
117
117
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module GoogleDrive
|
2
|
+
# A simple credentials class using an existing OAuth2 access_token.
|
3
|
+
#
|
4
|
+
# Based on:
|
5
|
+
# https://github.com/google/google-api-ruby-client/issues/296
|
6
|
+
#
|
7
|
+
# @api private
|
8
|
+
class AccessTokenCredentials
|
9
|
+
attr_reader :access_token
|
10
|
+
|
11
|
+
def initialize(access_token)
|
12
|
+
@access_token = access_token
|
13
|
+
end
|
14
|
+
|
15
|
+
def apply!(headers)
|
16
|
+
headers['Authorization'] = "Bearer #{@access_token}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/google_drive/acl.rb
CHANGED
@@ -16,7 +16,8 @@ module GoogleDrive
|
|
16
16
|
include(Util)
|
17
17
|
extend(Forwardable)
|
18
18
|
|
19
|
-
|
19
|
+
# @api private
|
20
|
+
def initialize(session, file)
|
20
21
|
@session = session
|
21
22
|
@file = file
|
22
23
|
api_permissions = @session.drive.list_permissions(@file.id, fields: '*')
|
@@ -33,11 +34,12 @@ module GoogleDrive
|
|
33
34
|
# Also you can pass the second hash argument +options+, which specifies
|
34
35
|
# optional query parameters for the API.
|
35
36
|
# Possible keys of +options+ are,
|
36
|
-
# * :
|
37
|
-
# * :
|
38
|
-
# when sharing to users or groups.
|
39
|
-
#
|
40
|
-
#
|
37
|
+
# * :email_message -- A custom message to include in notification emails
|
38
|
+
# * :send_notification_email -- Whether to send notification emails
|
39
|
+
# when sharing to users or groups. (Default: true)
|
40
|
+
# * :transfer_ownership -- Whether to transfer ownership to the specified user
|
41
|
+
# and downgrade the current owner to a writer. This parameter is required as an
|
42
|
+
# acknowledgement of the side effect. (Default: false)
|
41
43
|
#
|
42
44
|
# e.g.
|
43
45
|
# # A specific user can read or write.
|
@@ -57,7 +59,7 @@ module GoogleDrive
|
|
57
59
|
# # Set ACL without sending notification emails
|
58
60
|
# spreadsheet.acl.push(
|
59
61
|
# {type: "user", email_address: "example2@gmail.com", role: "reader"},
|
60
|
-
# {
|
62
|
+
# {send_notification_email: false})
|
61
63
|
#
|
62
64
|
# See here for parameter detais:
|
63
65
|
# https://developers.google.com/drive/v3/reference/permissions/create
|
@@ -78,7 +80,8 @@ module GoogleDrive
|
|
78
80
|
@entries.delete(entry)
|
79
81
|
end
|
80
82
|
|
81
|
-
|
83
|
+
# @api private
|
84
|
+
def update_role(entry)
|
82
85
|
api_permission = @session.drive.update_permission(
|
83
86
|
@file.id, entry.id, {role: entry.role}, fields: '*')
|
84
87
|
entry.api_permission = api_permission
|
@@ -29,8 +29,12 @@ module GoogleDrive
|
|
29
29
|
end
|
30
30
|
|
31
31
|
attr_reader(:acl)
|
32
|
-
|
33
|
-
|
32
|
+
|
33
|
+
# @api private
|
34
|
+
attr_reader(:params)
|
35
|
+
|
36
|
+
# @api private
|
37
|
+
attr_accessor(:api_permission)
|
34
38
|
|
35
39
|
# The role given to the scope. One of:
|
36
40
|
# - "owner": The owner.
|
@@ -41,18 +41,19 @@ module GoogleDrive
|
|
41
41
|
end
|
42
42
|
|
43
43
|
# Returns all the files (including spreadsheets, documents, subcollections) in the collection.
|
44
|
-
#
|
45
44
|
# You can specify parameters documented at
|
46
|
-
# https://developers.google.com/drive/
|
45
|
+
# https://developers.google.com/drive/v3/web/search-parameters
|
47
46
|
#
|
48
47
|
# e.g.
|
49
48
|
#
|
50
|
-
# # Gets all the files in collection, including subcollections.
|
49
|
+
# # Gets all the files in the collection, including subcollections.
|
51
50
|
# collection.files
|
51
|
+
#
|
52
52
|
# # Gets only files with title "hoge".
|
53
|
-
# collection.files(
|
53
|
+
# collection.files(q: "name = 'hoge'")
|
54
|
+
#
|
54
55
|
# # Same as above with a placeholder.
|
55
|
-
# collection.files(
|
56
|
+
# collection.files(q: ["name = ?", "hoge"])
|
56
57
|
#
|
57
58
|
# By default, it returns the first 100 files. See document of GoogleDrive::Session#files method
|
58
59
|
# for how to get all files.
|
data/lib/google_drive/config.rb
CHANGED
data/lib/google_drive/file.rb
CHANGED
data/lib/google_drive/list.rb
CHANGED
@@ -15,7 +15,8 @@ module GoogleDrive
|
|
15
15
|
class List
|
16
16
|
include(Enumerable)
|
17
17
|
|
18
|
-
|
18
|
+
# @api private
|
19
|
+
def initialize(worksheet)
|
19
20
|
@worksheet = worksheet
|
20
21
|
end
|
21
22
|
|
@@ -90,19 +91,23 @@ module GoogleDrive
|
|
90
91
|
map(&:to_hash)
|
91
92
|
end
|
92
93
|
|
93
|
-
|
94
|
+
# @api private
|
95
|
+
def get(index, key)
|
94
96
|
@worksheet[index + 2, key_to_col(key)]
|
95
97
|
end
|
96
98
|
|
97
|
-
|
99
|
+
# @api private
|
100
|
+
def numeric_value(index, key)
|
98
101
|
@worksheet.numeric_value(index + 2, key_to_col(key))
|
99
102
|
end
|
100
103
|
|
101
|
-
|
104
|
+
# @api private
|
105
|
+
def input_value(index, key)
|
102
106
|
@worksheet.input_value(index + 2, key_to_col(key))
|
103
107
|
end
|
104
108
|
|
105
|
-
|
109
|
+
# @api private
|
110
|
+
def set(index, key, value)
|
106
111
|
@worksheet[index + 2, key_to_col(key)] = value
|
107
112
|
end
|
108
113
|
|
@@ -17,7 +17,8 @@ module GoogleDrive
|
|
17
17
|
:assoc, :fetch, :flatten, :key, :invert, :size, :length, :rassoc,
|
18
18
|
:merge, :reject, :select, :sort, :to_a, :values_at)
|
19
19
|
|
20
|
-
|
20
|
+
# @api private
|
21
|
+
def initialize(list, index)
|
21
22
|
@list = list
|
22
23
|
@index = index
|
23
24
|
end
|
@@ -8,7 +8,8 @@ require 'google_drive/error'
|
|
8
8
|
module GoogleDrive
|
9
9
|
# Raised when an HTTP request has returned an unexpected response code.
|
10
10
|
class ResponseCodeError < GoogleDrive::Error
|
11
|
-
|
11
|
+
# @api private
|
12
|
+
def initialize(code, body, method, url)
|
12
13
|
@code = code
|
13
14
|
@body = body
|
14
15
|
super('Response code %s for %s %s: %s' % [code, method, url, CGI.unescapeHTML(body)])
|
data/lib/google_drive/session.rb
CHANGED
@@ -18,10 +18,13 @@ require 'google_drive/worksheet'
|
|
18
18
|
require 'google_drive/collection'
|
19
19
|
require 'google_drive/file'
|
20
20
|
require 'google_drive/config'
|
21
|
+
require 'google_drive/access_token_credentials'
|
21
22
|
|
22
23
|
module GoogleDrive
|
23
|
-
#
|
24
|
-
#
|
24
|
+
# A session for Google Drive operations.
|
25
|
+
#
|
26
|
+
# Use from_credentials, from_access_token, from_service_account_key or from_config
|
27
|
+
# class method to construct a GoogleDrive::Session object.
|
25
28
|
class Session
|
26
29
|
include(Util)
|
27
30
|
extend(Util)
|
@@ -137,13 +140,11 @@ module GoogleDrive
|
|
137
140
|
|
138
141
|
if credentials_or_access_token
|
139
142
|
if credentials_or_access_token.is_a?(String)
|
140
|
-
credentials =
|
141
|
-
access_token: credentials_or_access_token)
|
143
|
+
credentials = AccessTokenCredentials.new(credentials_or_access_token)
|
142
144
|
# Equivalent of credentials_or_access_token.is_a?(OAuth2::AccessToken),
|
143
145
|
# without adding dependency to "oauth2" library.
|
144
146
|
elsif credentials_or_access_token.class.ancestors.any?{ |m| m.name == 'OAuth2::AccessToken' }
|
145
|
-
credentials =
|
146
|
-
access_token: credentials_or_access_token.token)
|
147
|
+
credentials = AccessTokenCredentials.new(credentials_or_access_token.token)
|
147
148
|
else
|
148
149
|
credentials = credentials_or_access_token
|
149
150
|
end
|
@@ -191,9 +192,11 @@ module GoogleDrive
|
|
191
192
|
&block)
|
192
193
|
end
|
193
194
|
|
194
|
-
# Returns
|
195
|
-
#
|
196
|
-
#
|
195
|
+
# Returns a file (including a spreadsheet and a folder) whose title exactly matches +title+.
|
196
|
+
#
|
197
|
+
# Returns an instance of GoogleDrive::File or its subclass (GoogleDrive::Spreadsheet,
|
198
|
+
# GoogleDrive::Collection). Returns nil if not found. If multiple files with the +title+ are
|
199
|
+
# found, returns one of them.
|
197
200
|
#
|
198
201
|
# If given an Array, traverses collections by title. e.g.
|
199
202
|
# session.file_by_title(["myfolder", "mysubfolder/even/w/slash", "myfile"])
|
@@ -205,15 +208,22 @@ module GoogleDrive
|
|
205
208
|
end
|
206
209
|
end
|
207
210
|
|
208
|
-
# Returns
|
211
|
+
# Returns a file (including a spreadsheet and a folder) with a given +id+.
|
212
|
+
#
|
213
|
+
# Returns an instance of GoogleDrive::File or its subclass (GoogleDrive::Spreadsheet,
|
214
|
+
# GoogleDrive::Collection).
|
209
215
|
def file_by_id(id)
|
210
216
|
api_file = self.drive.get_file(id, fields: '*')
|
211
217
|
wrap_api_file(api_file)
|
212
218
|
end
|
213
219
|
|
214
|
-
# Returns
|
220
|
+
# Returns a file (including a spreadsheet and a folder) with a given +url+.
|
221
|
+
# +url+ must be eitehr of:
|
215
222
|
# - URL of the page you open to access a document/spreadsheet in your browser
|
216
223
|
# - URL of worksheet-based feed of a spreadseet
|
224
|
+
#
|
225
|
+
# Returns an instance of GoogleDrive::File or its subclass (GoogleDrive::Spreadsheet,
|
226
|
+
# GoogleDrive::Collection).
|
217
227
|
def file_by_url(url)
|
218
228
|
file_by_id(url_to_id(url))
|
219
229
|
end
|
@@ -411,7 +421,8 @@ module GoogleDrive
|
|
411
421
|
upload_from_source(io, title, params)
|
412
422
|
end
|
413
423
|
|
414
|
-
|
424
|
+
# @api private
|
425
|
+
def wrap_api_file(api_file)
|
415
426
|
case api_file.mime_type
|
416
427
|
when 'application/vnd.google-apps.folder'
|
417
428
|
return Collection.new(self, api_file)
|
@@ -422,7 +433,8 @@ module GoogleDrive
|
|
422
433
|
end
|
423
434
|
end
|
424
435
|
|
425
|
-
|
436
|
+
# @api private
|
437
|
+
def execute_paged!(opts, &block)
|
426
438
|
if block
|
427
439
|
page_token = nil
|
428
440
|
loop do
|
@@ -446,7 +458,8 @@ module GoogleDrive
|
|
446
458
|
end
|
447
459
|
end
|
448
460
|
|
449
|
-
|
461
|
+
# @api private
|
462
|
+
def request(method, url, params = {})
|
450
463
|
# Always uses HTTPS.
|
451
464
|
url = url.gsub(%r{^http://}, 'https://')
|
452
465
|
data = params[:data]
|
data/lib/google_drive/util.rb
CHANGED
@@ -15,7 +15,8 @@ module GoogleDrive
|
|
15
15
|
class Worksheet
|
16
16
|
include(Util)
|
17
17
|
|
18
|
-
|
18
|
+
# @api private
|
19
|
+
def initialize(session, spreadsheet, worksheet_feed_entry)
|
19
20
|
@session = session
|
20
21
|
@spreadsheet = spreadsheet
|
21
22
|
set_worksheet_feed_entry(worksheet_feed_entry)
|
@@ -188,29 +189,21 @@ module GoogleDrive
|
|
188
189
|
end
|
189
190
|
|
190
191
|
# Number of rows including empty rows.
|
191
|
-
|
192
|
-
reload_cells unless @cells
|
193
|
-
@max_rows
|
194
|
-
end
|
192
|
+
attr_reader :max_rows
|
195
193
|
|
196
194
|
# Updates number of rows.
|
197
195
|
# Note that update is not sent to the server until you call save().
|
198
196
|
def max_rows=(rows)
|
199
|
-
reload_cells unless @cells
|
200
197
|
@max_rows = rows
|
201
198
|
@meta_modified = true
|
202
199
|
end
|
203
200
|
|
204
201
|
# Number of columns including empty columns.
|
205
|
-
|
206
|
-
reload_cells unless @cells
|
207
|
-
@max_cols
|
208
|
-
end
|
202
|
+
attr_reader :max_cols
|
209
203
|
|
210
204
|
# Updates number of columns.
|
211
205
|
# Note that update is not sent to the server until you call save().
|
212
206
|
def max_cols=(cols)
|
213
|
-
reload_cells unless @cells
|
214
207
|
@max_cols = cols
|
215
208
|
@meta_modified = true
|
216
209
|
end
|
@@ -222,7 +215,8 @@ module GoogleDrive
|
|
222
215
|
@meta_modified = true
|
223
216
|
end
|
224
217
|
|
225
|
-
|
218
|
+
# @api private
|
219
|
+
def cells
|
226
220
|
reload_cells unless @cells
|
227
221
|
@cells
|
228
222
|
end
|
@@ -310,7 +304,7 @@ module GoogleDrive
|
|
310
304
|
<entry xmlns='http://www.w3.org/2005/Atom'
|
311
305
|
xmlns:gs='http://schemas.google.com/spreadsheets/2006'>
|
312
306
|
<title>#{h(title)}</title>
|
313
|
-
<gs:rowCount>#{h(
|
307
|
+
<gs:rowCount>#{h(max_rows)}</gs:rowCount>
|
314
308
|
<gs:colCount>#{h(max_cols)}</gs:colCount>
|
315
309
|
</entry>
|
316
310
|
EOS
|
@@ -471,14 +465,18 @@ module GoogleDrive
|
|
471
465
|
def set_worksheet_feed_entry(entry)
|
472
466
|
@worksheet_feed_entry = entry
|
473
467
|
@title = entry.css('title').text
|
468
|
+
set_max_values(entry)
|
474
469
|
@updated = Time.parse(entry.css('updated').text)
|
475
470
|
@meta_modified = false
|
476
471
|
end
|
472
|
+
|
473
|
+
def set_max_values(entry)
|
474
|
+
@max_rows = entry.css('gs|rowCount').text.to_i
|
475
|
+
@max_cols = entry.css('gs|colCount').text.to_i
|
476
|
+
end
|
477
477
|
|
478
478
|
def reload_cells
|
479
479
|
doc = @session.request(:get, cells_feed_url)
|
480
|
-
@max_rows = doc.css('gs|rowCount').text.to_i
|
481
|
-
@max_cols = doc.css('gs|colCount').text.to_i
|
482
480
|
|
483
481
|
@num_cols = nil
|
484
482
|
@num_rows = nil
|
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.1.
|
4
|
+
version: 2.1.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-
|
11
|
+
date: 2016-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -133,6 +133,7 @@ extra_rdoc_files: []
|
|
133
133
|
files:
|
134
134
|
- README.md
|
135
135
|
- lib/google_drive.rb
|
136
|
+
- lib/google_drive/access_token_credentials.rb
|
136
137
|
- lib/google_drive/acl.rb
|
137
138
|
- lib/google_drive/acl_entry.rb
|
138
139
|
- lib/google_drive/api_client_fetcher.rb
|