google_drive 2.1.7 → 2.1.8

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: d1a4942b505b1a7c2b0c9f5c5ad4b6b07def0a52
4
- data.tar.gz: 8a85586bb36e68b20d899fabdea7c10a1e60e3bd
3
+ metadata.gz: a307d368da1d8c3aaddcc80fce8e3ab842e31fbc
4
+ data.tar.gz: f638dfeb91a08128bfca2e547973efd2b1172a42
5
5
  SHA512:
6
- metadata.gz: 32427d7303d783f1d846e81dc6eb201691e584550f6cb8a85a35b8fad129ba5993d79347504c94ff68c7b74d57dc9d29b26286a213fbd96d7b33f66b7ff94b4e
7
- data.tar.gz: 56ec22afaab23abaf16ee0b398b65eadecb296353a44f6a0c81e30bc5a979a3890c75f908c11b460de276f1b7edacdf650f4d3f20b9b687bb817fba8751663e2
6
+ metadata.gz: f6ead9f1d7cedf6efedd25b88b0d36d8599c63824ed616d3401eebaf9d0431c29e4d41ef6e4ec1cfa1754de76dc47c23754946c17334bcd264929e37ffd1e40a
7
+ data.tar.gz: 56a2e06379ea4a54efbc2c2ac53d65c1f93b89ab7036f6989ce79b143c45b3d43dee68d1fe9d9102b1133a5aab82f94d6d1ce8332475eafd2e2b55c65be4e87b
data/README.md CHANGED
@@ -1,15 +1,28 @@
1
+ # google-drive-ruby [![Build Status](https://travis-ci.org/gimite/google-drive-ruby.svg?branch=master)](https://travis-ci.org/gimite/google-drive-ruby)
2
+
1
3
  This is a Ruby library to read/write files/spreadsheets in Google Drive/Docs.
2
4
 
3
5
  NOTE: This is NOT a library to create Google Drive App.
4
6
 
5
7
 
6
- ## Migration from ver. 0.x.x / 1.x.x to to ver. 2.x.x
8
+ * [Migration from ver. 0.x.x / 1.x.x](#migration)
9
+ * [How to install](#install)
10
+ * [How to use](#use)
11
+ * [API documentation](http://www.rubydoc.info/gems/google_drive)
12
+ * [Authorization](https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md)
13
+ * [Github](http://github.com/gimite/google-drive-ruby)
14
+ * [License](#license)
15
+ * [Supported environments](#environments)
16
+ * [Author](#author)
17
+
18
+
19
+ ## <a name="migration">Migration from ver. 0.x.x / 1.x.x</a>
7
20
 
8
21
  There are some incompatible API changes. See
9
22
  [MIGRATING.md](https://github.com/gimite/google-drive-ruby/blob/master/MIGRATING.md).
10
23
 
11
24
 
12
- ## How to install
25
+ ## <a name="install">How to install</a>
13
26
 
14
27
  Add this line to your application's Gemfile:
15
28
 
@@ -35,7 +48,7 @@ If you need system wide installation, execute below:
35
48
  $ sudo gem install google_drive
36
49
  ```
37
50
 
38
- ## How to use
51
+ ## <a name="use">How to use</a>
39
52
 
40
53
  ### Authorization
41
54
 
@@ -107,20 +120,17 @@ p ws.rows #==> [["fuga", ""], ["foo", "bar]]
107
120
  ws.reload
108
121
  ```
109
122
 
110
- ## Learn more
111
123
 
112
- * [API documentation](http://www.rubydoc.info/gems/google_drive)
113
- * [Authorization](https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md)
114
- * [Github](http://github.com/gimite/google-drive-ruby)
115
-
116
- ## License
124
+ ## <a name="license">License</a>
117
125
 
118
126
  New BSD Licence.
119
127
 
120
- ## Supported environments
121
128
 
122
- Ruby 2.0.0 or later. Checked with Ruby 2.3.0.
129
+ ## <a name="environments">Supported environments</a>
130
+
131
+ Ruby 2.0.0 or later. Checked with Ruby 2.4.1.
132
+
123
133
 
124
- ## Author
134
+ ## <a name="author">Author</a>
125
135
 
126
136
  [Hiroshi Ichikawa](http://gimite.net/en/index.php?Contact)
@@ -6,25 +6,27 @@ require 'google_drive/error'
6
6
  require 'google_drive/spreadsheet'
7
7
 
8
8
  module GoogleDrive
9
+ # Represents a folder in Google Drive.
10
+ #
9
11
  # Use GoogleDrive::Session#root_collection, GoogleDrive::Collection#subcollections,
10
12
  # or GoogleDrive::Session#collection_by_url to get GoogleDrive::Collection object.
11
13
  class Collection < GoogleDrive::File
12
14
  include(Util)
13
15
 
14
- alias_method :collection_feed_url, :document_feed_url
16
+ alias collection_feed_url document_feed_url
15
17
 
16
- # Adds the given GoogleDrive::File to the collection.
18
+ # Adds the given GoogleDrive::File to the folder.
17
19
  def add(file)
18
20
  @session.drive.update_file(file.id, add_parents: self.id, fields: '', supports_team_drives: true)
19
21
  nil
20
22
  end
21
23
 
22
- # Removes the given GoogleDrive::File from the collection.
24
+ # Removes the given GoogleDrive::File from the folder.
23
25
  def remove(file)
24
26
  @session.drive.update_file(file.id, remove_parents: self.id, fields: '', supports_team_drives: true)
25
27
  end
26
28
 
27
- # Creates a sub-collection with given title. Returns GoogleDrive::Collection object.
29
+ # Creates a sub-folder with given title. Returns GoogleDrive::Collection object.
28
30
  def create_subcollection(title)
29
31
  file_metadata = {
30
32
  name: title,
@@ -34,19 +36,21 @@ module GoogleDrive
34
36
  file = @session.drive.create_file(file_metadata, fields: '*', supports_team_drives: true)
35
37
  @session.wrap_api_file(file)
36
38
  end
39
+
40
+ alias create_subfolder create_subcollection
37
41
 
38
- # Returns true if this is a root collection
42
+ # Returns true if this is a root folder.
39
43
  def root?
40
44
  !api_file.parents || api_file.parents.empty?
41
45
  end
42
46
 
43
- # Returns all the files (including spreadsheets, documents, subcollections) in the collection.
47
+ # Returns all the files (including spreadsheets, documents, subfolders) in the folder.
44
48
  # You can specify parameters documented at
45
49
  # https://developers.google.com/drive/v3/web/search-parameters
46
50
  #
47
51
  # e.g.
48
52
  #
49
- # # Gets all the files in the collection, including subcollections.
53
+ # # Gets all the files in the folder, including subfolders.
50
54
  # collection.files
51
55
  #
52
56
  # # Gets only files with title "hoge".
@@ -61,19 +65,19 @@ module GoogleDrive
61
65
  files_with_type(nil, params, &block)
62
66
  end
63
67
 
64
- # Same as Session#upload_from_file. It uploads file to current collection
68
+ # Uploads a file to this folder. See Session#upload_from_file for details.
65
69
  def upload_from_file(path, title = nil, params = {})
66
70
  params = {parents: [self.id]}.merge(params)
67
71
  @session.upload_from_file(path, title, params)
68
72
  end
69
73
 
70
- # Same as Session#upload_from_io. It uploads file to current collection
74
+ # Uploads a file to this folder. See Session#upload_from_io for details.
71
75
  def upload_from_io(io, title = 'Untitled', params = {})
72
76
  params = {parents: [self.id]}.merge(params)
73
77
  @session.upload_from_io(io, title, params)
74
78
  end
75
79
 
76
- # Same as Session#upload_from_string. It uploads file to current collection
80
+ # Uploads a file to this folder. See Session#upload_from_string for details.
77
81
  def upload_from_string(content, title = 'Untitled', params = {})
78
82
  params = {parents: [self.id]}.merge(params)
79
83
  @session.upload_from_string(content, title, params)
@@ -81,7 +85,7 @@ module GoogleDrive
81
85
 
82
86
  alias_method :contents, :files
83
87
 
84
- # Returns all the spreadsheets in the collection.
88
+ # Returns all the spreadsheets in the folder.
85
89
  #
86
90
  # By default, it returns the first 100 spreadsheets. See document of GoogleDrive::Session#files method
87
91
  # for how to get all spreadsheets.
@@ -89,7 +93,7 @@ module GoogleDrive
89
93
  files_with_type('application/vnd.google-apps.spreadsheet', params, &block)
90
94
  end
91
95
 
92
- # Returns all the Google Docs documents in the collection.
96
+ # Returns all the Google Docs documents in the folder.
93
97
  #
94
98
  # By default, it returns the first 100 documents. See document of GoogleDrive::Session#files method
95
99
  # for how to get all documents.
@@ -97,33 +101,39 @@ module GoogleDrive
97
101
  files_with_type('application/vnd.google-apps.document', params, &block)
98
102
  end
99
103
 
100
- # Returns all its subcollections.
104
+ # Returns all its subfolders.
101
105
  #
102
- # By default, it returns the first 100 subcollections. See document of GoogleDrive::Session#files method
103
- # for how to get all subcollections.
106
+ # By default, it returns the first 100 subfolders. See document of GoogleDrive::Session#files method
107
+ # for how to get all subfolders.
104
108
  def subcollections(params = {}, &block)
105
109
  files_with_type('application/vnd.google-apps.folder', params, &block)
106
110
  end
111
+
112
+ alias subfolders subcollections
107
113
 
108
- # Returns a file (can be a spreadsheet, document, subcollection or other files) in the
109
- # collection which exactly matches +title+ as GoogleDrive::File.
110
- # Returns nil if not found. If multiple collections with the +title+ are found, returns
114
+ # Returns a file (can be a spreadsheet, document, subfolder or other files) in the
115
+ # folder which exactly matches +title+ as GoogleDrive::File.
116
+ # Returns nil if not found. If multiple folders with the +title+ are found, returns
111
117
  # one of them.
112
118
  #
113
- # If given an Array, does a recursive subcollection traversal.
119
+ # If given an Array, does a recursive subfolder traversal.
114
120
  def file_by_title(title)
115
121
  file_by_title_with_type(title, nil)
116
122
  end
123
+
124
+ alias file_by_name file_by_title
117
125
 
118
- # Returns its subcollection whose title exactly matches +title+ as GoogleDrive::Collection.
119
- # Returns nil if not found. If multiple collections with the +title+ are found, returns
126
+ # Returns its subfolder whose title exactly matches +title+ as GoogleDrive::Collection.
127
+ # Returns nil if not found. If multiple folders with the +title+ are found, returns
120
128
  # one of them.
121
129
  #
122
- # If given an Array, does a recursive subcollection traversal.
130
+ # If given an Array, does a recursive subfolder traversal.
123
131
  def subcollection_by_title(title)
124
132
  file_by_title_with_type(title, 'application/vnd.google-apps.folder')
125
133
  end
126
134
 
135
+ alias subfolder_by_name subcollection_by_title
136
+
127
137
  # Returns URL of the deprecated contents feed.
128
138
  def contents_url
129
139
  document_feed_url + '/contents'
@@ -144,6 +154,8 @@ module GoogleDrive
144
154
  files_with_type(type, q: ['name = ?', title], page_size: 1)[0]
145
155
  end
146
156
  end
157
+
158
+ alias file_by_name_with_type file_by_title_with_type
147
159
 
148
160
  private
149
161
 
@@ -159,4 +171,6 @@ module GoogleDrive
159
171
  @session.files(params, &block)
160
172
  end
161
173
  end
174
+
175
+ Folder = Collection
162
176
  end
@@ -6,7 +6,7 @@ require 'json'
6
6
  module GoogleDrive
7
7
  # @api private
8
8
  class Config
9
- FIELDS = %w(client_id client_secret scope refresh_token).freeze
9
+ FIELDS = %w(client_id client_secret scope refresh_token type).freeze
10
10
  attr_accessor(*FIELDS)
11
11
 
12
12
  def initialize(config_path)
@@ -65,6 +65,8 @@ module GoogleDrive
65
65
  reload_metadata if params[:reload]
66
66
  api_file.name
67
67
  end
68
+
69
+ alias name title
68
70
 
69
71
  # URL to view/edit the file in a Web browser.
70
72
  #
@@ -93,7 +93,12 @@ module GoogleDrive
93
93
  # save
94
94
  def self.from_config(config, options = {})
95
95
  if config.is_a?(String)
96
- config = Config.new(config)
96
+ config_path = config
97
+ config = Config.new(config_path)
98
+ if config.type == 'service_account'
99
+ return from_service_account_key(
100
+ config_path, options[:scope] || DEFAULT_SCOPE)
101
+ end
97
102
  end
98
103
 
99
104
  config.scope ||= DEFAULT_SCOPE
@@ -198,7 +203,7 @@ module GoogleDrive
198
203
  # GoogleDrive::Collection). Returns nil if not found. If multiple files with the +title+ are
199
204
  # found, returns one of them.
200
205
  #
201
- # If given an Array, traverses collections by title. e.g.
206
+ # If given an Array, traverses folders by title. e.g.
202
207
  # session.file_by_title(["myfolder", "mysubfolder/even/w/slash", "myfile"])
203
208
  def file_by_title(title)
204
209
  if title.is_a?(Array)
@@ -207,6 +212,8 @@ module GoogleDrive
207
212
  files(q: ['name = ?', title], page_size: 1)[0]
208
213
  end
209
214
  end
215
+
216
+ alias file_by_name file_by_title
210
217
 
211
218
  # Returns a file (including a spreadsheet and a folder) with a given +id+.
212
219
  #
@@ -285,6 +292,8 @@ module GoogleDrive
285
292
  def spreadsheet_by_title(title)
286
293
  spreadsheets(q: ['name = ?', title], page_size: 1)[0]
287
294
  end
295
+
296
+ alias spreadsheet_by_name spreadsheet_by_title
288
297
 
289
298
  # Returns GoogleDrive::Worksheet with given +url+.
290
299
  # You must specify URL of either worksheet feed or cell-based feed of the worksheet.
@@ -313,47 +322,50 @@ module GoogleDrive
313
322
  Worksheet.new(self, nil, worksheet_feed_entry)
314
323
  end
315
324
 
316
- # Returns the root collection.
325
+ # Returns the root folder.
317
326
  def root_collection
318
327
  @root_collection ||= file_by_id('root')
319
328
  end
329
+
330
+ alias root_folder root_collection
320
331
 
321
- # Returns the top-level collections (direct children of the root collection).
332
+ # Returns the top-level folders (direct children of the root folder).
322
333
  #
323
- # By default, it returns the first 100 collections. See document of files method for how to get
324
- # all collections.
334
+ # By default, it returns the first 100 folders. See document of files method for how to get
335
+ # all folders.
325
336
  def collections(params = {}, &block)
326
337
  root_collection.subcollections(params, &block)
327
338
  end
339
+
340
+ alias folders collections
328
341
 
329
- # Returns a top-level collection whose title exactly matches +title+ as
342
+ # Returns a top-level folder whose title exactly matches +title+ as
330
343
  # GoogleDrive::Collection.
331
- # Returns nil if not found. If multiple collections with the +title+ are found, returns
344
+ # Returns nil if not found. If multiple folders with the +title+ are found, returns
332
345
  # one of them.
333
346
  def collection_by_title(title)
334
347
  root_collection.subcollection_by_title(title)
335
348
  end
349
+
350
+ alias folders_by_name collection_by_title
336
351
 
337
352
  # Returns GoogleDrive::Collection with given +url+.
338
- # You must specify either of:
339
- # - URL of the page you get when you go to https://docs.google.com/ with your browser and
340
- # open a collection
341
- # - URL of collection (folder) feed
353
+ #
354
+ # You must specify the URL of the page you get when you go to https://drive.google.com/
355
+ # with your browser and open a folder.
342
356
  #
343
357
  # e.g.
344
358
  # session.collection_by_url(
345
- # "https://drive.google.com/#folders/" +
346
- # "0B9GfDpQ2pBVUODNmOGE0NjIzMWU3ZC00NmUyLTk5NzEtYaFkZjY1MjAyxjMc")
347
- # session.collection_by_url(
348
- # "http://docs.google.com/feeds/default/private/full/folder%3A" +
349
- # "0B9GfDpQ2pBVUODNmOGE0NjIzMWU3ZC00NmUyLTk5NzEtYaFkZjY1MjAyxjMc")
359
+ # "https://drive.google.com/drive/folders/1u99gpfHIk08RVK5q_vXxUqkxR1r6FUJH")
350
360
  def collection_by_url(url)
351
361
  file = file_by_url(url)
352
362
  unless file.is_a?(Collection)
353
- fail(GoogleDrive::Error, 'The file with the URL is not a collection: %s' % url)
363
+ fail(GoogleDrive::Error, 'The file with the URL is not a folder: %s' % url)
354
364
  end
355
365
  file
356
366
  end
367
+
368
+ alias folder_by_url collection_by_url
357
369
 
358
370
  # Creates new spreadsheet and returns the new GoogleDrive::Spreadsheet.
359
371
  #
@@ -547,7 +559,7 @@ module GoogleDrive
547
559
  # Human-readable new spreadsheet/document.
548
560
  when /\/d\/([^\/]+)/
549
561
  return Regexp.last_match(1)
550
- # Human-readable new collection page.
562
+ # Human-readable new folder page.
551
563
  when /^\/drive\/[^\/]+\/([^\/]+)/
552
564
  return Regexp.last_match(1)
553
565
  # Human-readable old folder view.
@@ -558,7 +570,7 @@ module GoogleDrive
558
570
  return Regexp.last_match(1) if (uri.query || '').split(/&/).find { |s| s =~ /^key=(.*)$/ }
559
571
  end
560
572
  case uri.fragment
561
- # Human-readable old collection page.
573
+ # Human-readable old folder page.
562
574
  when /^folders\/(.+)$/
563
575
  return Regexp.last_match(1)
564
576
  end
@@ -12,7 +12,8 @@ require 'google_drive/file'
12
12
  module GoogleDrive
13
13
  # A spreadsheet.
14
14
  #
15
- # Use methods in GoogleDrive::Session to get GoogleDrive::Spreadsheet object.
15
+ # e.g., Use methods spreadsheet_by_title, spreadsheet_by_url, create_spreadsheet in GoogleDrive::Session
16
+ # to get GoogleDrive::Spreadsheet object.
16
17
  class Spreadsheet < GoogleDrive::File
17
18
  include(Util)
18
19
 
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.7
4
+ version: 2.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Ichikawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-18 00:00:00.000000000 Z
11
+ date: 2018-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  version: '0'
170
170
  requirements: []
171
171
  rubyforge_project:
172
- rubygems_version: 2.5.1
172
+ rubygems_version: 2.6.14
173
173
  signing_key:
174
174
  specification_version: 4
175
175
  summary: A library to read/write files/spreadsheets in Google Drive/Docs.