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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fff5ef1112cf60c78cc1cbd54372ec34a87e3aad
4
- data.tar.gz: 5448d5cba8278598b46b432e1b5e812ac33e0f87
3
+ metadata.gz: 584b24ba7f2e0849c5209e2343f33f553dc920f6
4
+ data.tar.gz: b6a5d71757609057cb510ea4177a14e9cb8355a4
5
5
  SHA512:
6
- metadata.gz: ffc511d0d0aba64d4510753abde1fac34fc4940bfc6233d04c0bd4093b3af53ae4c663aba856032b09e11300b10a7b31130dad7638abfb982b6e1a5d6aa3b8c5
7
- data.tar.gz: 076cf4ceeaec5fb63ea8374a940c091544a413ca8c7cd5604d5a2cc642715e2f3513fb641230c560371d89bda2fb1a70d014631030ff2038c3be31b4d7fe9b41
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
- ## Full API documentation
106
+ ## Learn more
107
107
 
108
- [API documentation in RubyDoc.info](http://www.rubydoc.info/gems/google_drive)
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
- ## Source code
112
+ ## License
111
113
 
112
- [Github](http://github.com/gimite/google-drive-ruby)
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
@@ -16,7 +16,8 @@ module GoogleDrive
16
16
  include(Util)
17
17
  extend(Forwardable)
18
18
 
19
- def initialize(session, file) #:nodoc:
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
- # * :emailMessage -- A custom message to include in notification emails
37
- # * :sendNotificationEmails -- Whether to send notification emails
38
- # when sharing to users or groups.
39
- #
40
- # NOTE: This sends email to the new people.
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
- # {sendNotificationEmails: false})
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
- def update_role(entry) #:nodoc:
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
- attr_reader(:params) #:nodoc:
33
- attr_accessor(:api_permission) #:nodoc:
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/v2/reference/files/list
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("q" => "title = 'hoge'")
53
+ # collection.files(q: "name = 'hoge'")
54
+ #
54
55
  # # Same as above with a placeholder.
55
- # collection.files("q" => ["title = ?", "hoge"])
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.
@@ -4,7 +4,8 @@
4
4
  require 'json'
5
5
 
6
6
  module GoogleDrive
7
- class Config #:nodoc:
7
+ # @api private
8
+ class Config
8
9
  FIELDS = %w(client_id client_secret scope refresh_token).freeze
9
10
  attr_accessor(*FIELDS)
10
11
 
@@ -23,7 +23,8 @@ module GoogleDrive
23
23
  include(Util)
24
24
  extend(Forwardable)
25
25
 
26
- def initialize(session, api_file) #:nodoc:
26
+ # @api private
27
+ def initialize(session, api_file)
27
28
  @session = session
28
29
  @api_file = api_file
29
30
  @acl = nil
@@ -15,7 +15,8 @@ module GoogleDrive
15
15
  class List
16
16
  include(Enumerable)
17
17
 
18
- def initialize(worksheet) #:nodoc:
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
- def get(index, key) #:nodoc:
94
+ # @api private
95
+ def get(index, key)
94
96
  @worksheet[index + 2, key_to_col(key)]
95
97
  end
96
98
 
97
- def numeric_value(index, key) #:nodoc:
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
- def input_value(index, key) #:nodoc:
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
- def set(index, key, value) #:nodoc:
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
- def initialize(list, index) #:nodoc:
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
- def initialize(code, body, method, url) #:nodoc:#
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)])
@@ -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
- # Use GoogleDrive.login_with_oauth or GoogleDrive.saved_session to get
24
- # GoogleDrive::Session object.
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 = Google::Auth::UserRefreshCredentials.new(
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 = Google::Auth::UserRefreshCredentials.new(
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 GoogleDrive::File or its subclass whose title exactly matches +title+.
195
- # Returns nil if not found. If multiple files with the +title+ are found, returns
196
- # one of them.
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 GoogleDrive::File or its subclass with a given +id+.
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 GoogleDrive::File or its subclass with a given +url+. +url+ must be eitehr of:
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
- def wrap_api_file(api_file) #:nodoc:
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
- def execute_paged!(opts, &block) #:nodoc:
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
- def request(method, url, params = {}) #:nodoc:
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]
@@ -4,7 +4,8 @@
4
4
  require 'cgi'
5
5
 
6
6
  module GoogleDrive
7
- module Util #:nodoc:
7
+ # @api private
8
+ module Util
8
9
  EXT_TO_CONTENT_TYPE = {
9
10
  '.csv' => 'text/csv',
10
11
  '.tsv' => 'text/tab-separated-values',
@@ -15,7 +15,8 @@ module GoogleDrive
15
15
  class Worksheet
16
16
  include(Util)
17
17
 
18
- def initialize(session, spreadsheet, worksheet_feed_entry) #:nodoc:
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
- def max_rows
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
- def max_cols
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
- def cells #:nodoc:
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(self.max_rows)}</gs:rowCount>
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.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-08-02 00:00:00.000000000 Z
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