google_drive 2.1.11 → 2.1.12

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: ab18bbc182b3ffa7d363b03b7969457b311158af
4
- data.tar.gz: 3a1803545d767797bd8062b1c8bf7010f628be87
3
+ metadata.gz: a6e8bc240087cb507a378a4ff02886cad3e2b7ed
4
+ data.tar.gz: 07a8f238c8cc89072248fd6db3b2ca0b7ab18d37
5
5
  SHA512:
6
- metadata.gz: 5066596c8f5720484ba23f18690164cbb796d4e4e7748a1b1f16f1fcf6240b47bcff1580101c1d9f69e4f00f05f683bbb74335f3a473d407c65a3b487d6c1702
7
- data.tar.gz: ef1b363d2a00c794d2a00a2837a178dc3215886a3b9fbc4ddcde6c6f854fde11b7e38cf6ad78a0c1490e06b53cbc24cb5f975bc4b3f562bb0f3a0c1fd817cbfc
6
+ metadata.gz: 55ff686961a787c15738c8177f6aada5b4df2851019116e120310e2523684fed2d389b9658ad7f7d832ce125bcaf608467e7f7244a76109c0c649491d14ac773
7
+ data.tar.gz: b89df0376ae01ef915ae88193059a809eccbfa410f2a84a0e30c35415f08789f4021567d8da52a85e8f7cddd53319b084ddbc161deeb6ba19f0a0dd072e3cfec
@@ -17,7 +17,7 @@ module GoogleDrive
17
17
  attr_reader(:code, :body)
18
18
  end
19
19
 
20
- def initialize(authorization)
20
+ def initialize(authorization, client_options, request_options)
21
21
  @drive = Google::Apis::DriveV3::DriveService.new
22
22
  @drive.authorization = authorization
23
23
 
@@ -28,6 +28,18 @@ module GoogleDrive
28
28
  @drive.client_options.open_timeout_sec = t
29
29
  @drive.client_options.read_timeout_sec = t
30
30
  @drive.client_options.send_timeout_sec = t
31
+
32
+ if client_options
33
+ @drive.client_options.members.each do |name|
34
+ if !client_options[name].nil?
35
+ @drive.client_options[name] = client_options[name]
36
+ end
37
+ end
38
+ end
39
+
40
+ if request_options
41
+ @drive.request_options = @drive.request_options.merge(request_options)
42
+ end
31
43
  end
32
44
 
33
45
  attr_reader(:drive)
@@ -50,13 +50,19 @@ module GoogleDrive
50
50
  # See
51
51
  # https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md
52
52
  # for a usage example.
53
- def self.from_credentials(credentials)
54
- Session.new(credentials)
53
+ #
54
+ # See from_config documentation for an explanation of client_options and
55
+ # request_options.
56
+ def self.from_credentials(credentials, client_options = nil, request_options = nil)
57
+ Session.new(credentials, nil, client_options, request_options)
55
58
  end
56
59
 
57
60
  # Constructs a GoogleDrive::Session object from OAuth2 access token string.
58
- def self.from_access_token(access_token)
59
- Session.new(access_token)
61
+ #
62
+ # See from_config documentation for an explanation of client_options and
63
+ # request_options.
64
+ def self.from_access_token(access_token, client_options = nil, request_options = nil)
65
+ Session.new(access_token, nil, client_options, request_options)
60
66
  end
61
67
 
62
68
  # Constructs a GoogleDrive::Session object from a service account key JSON.
@@ -67,23 +73,28 @@ module GoogleDrive
67
73
  # See
68
74
  # https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md
69
75
  # for a usage example.
76
+ #
77
+ # As with from_config, you can configure Google API client behavior with
78
+ # +client_options+ and +request_options+. Unlike in from_config, these
79
+ # are passed as positional arguments.
70
80
  def self.from_service_account_key(
71
- json_key_path_or_io, scope = DEFAULT_SCOPE
81
+ json_key_path_or_io, scope = DEFAULT_SCOPE, client_options = nil,
82
+ request_options = nil
72
83
  )
73
84
  if json_key_path_or_io.is_a?(String)
74
85
  open(json_key_path_or_io) do |f|
75
- from_service_account_key(f, scope)
86
+ from_service_account_key(f, scope, client_options, request_options)
76
87
  end
77
88
  else
78
89
  credentials = Google::Auth::ServiceAccountCredentials.make_creds(
79
90
  json_key_io: json_key_path_or_io, scope: scope
80
91
  )
81
- Session.new(credentials)
92
+ Session.new(credentials, nil, client_options, request_options)
82
93
  end
83
94
  end
84
95
 
85
96
  # Returns GoogleDrive::Session constructed from a config JSON file at
86
- # +config+.
97
+ # +config+, potenially modified with +options+.
87
98
  #
88
99
  # +config+ is the path to the config file.
89
100
  #
@@ -102,13 +113,24 @@ module GoogleDrive
102
113
  # scope
103
114
  # scope=
104
115
  # save
116
+ #
117
+ # +options+ is a hash which may contain the following keys:
118
+ # client_secret: if present, this will overwrite config.client_secret
119
+ # client_id: if present, this will overwrite config.client_id
120
+ # client_options: a hash or ::Google::Apis::ClientOptions. See
121
+ # https://www.rubydoc.info/github/google/google-api-ruby-client/Google/Apis/ClientOptions
122
+ # for an explanation of legal sub-fields.
123
+ # request_options: a hash or ::Google::Apis::RequestOptions. See
124
+ # https://www.rubydoc.info/github/google/google-api-ruby-client/Google/Apis/RequestOptions
125
+ # for an explanation of legal sub-fields.
105
126
  def self.from_config(config, options = {})
106
127
  if config.is_a?(String)
107
128
  config_path = config
108
129
  config = Config.new(config_path)
109
130
  if config.type == 'service_account'
110
131
  return from_service_account_key(
111
- config_path, options[:scope] || DEFAULT_SCOPE
132
+ config_path, options[:scope] || DEFAULT_SCOPE, options[:client_options],
133
+ options[:request_options]
112
134
  )
113
135
  end
114
136
  end
@@ -153,10 +175,15 @@ module GoogleDrive
153
175
 
154
176
  config.save
155
177
 
156
- Session.new(credentials)
178
+ Session.new(
179
+ credentials, nil, options[:client_options], options[:request_options]
180
+ )
157
181
  end
158
182
 
159
- def initialize(credentials_or_access_token, proxy = nil)
183
+ def initialize(
184
+ credentials_or_access_token, proxy = nil, client_options = nil,
185
+ request_options = nil
186
+ )
160
187
  if proxy
161
188
  raise(
162
189
  ArgumentError,
@@ -179,7 +206,9 @@ module GoogleDrive
179
206
  else
180
207
  credentials = credentials_or_access_token
181
208
  end
182
- @fetcher = ApiClientFetcher.new(credentials)
209
+ @fetcher = ApiClientFetcher.new(
210
+ credentials, client_options, request_options
211
+ )
183
212
  else
184
213
  @fetcher = nil
185
214
  end
@@ -418,6 +447,24 @@ module GoogleDrive
418
447
 
419
448
  alias folder_by_url collection_by_url
420
449
 
450
+ # Returns GoogleDrive::Collection with given +id+.
451
+ #
452
+ # e.g.
453
+ # # https://drive.google.com/drive/folders/1rPPuzAew4tO3ORc88Vz1JscPCcnrX7-J
454
+ # session.collection_by_id("1rPPuzAew4tO3ORc88Vz1JscPCcnrX7-J")
455
+ def collection_by_id(id)
456
+ file = file_by_id(id)
457
+ unless file.is_a?(Collection)
458
+ raise(
459
+ GoogleDrive::Error,
460
+ format('The file with the ID is not a folder: %s', id)
461
+ )
462
+ end
463
+ file
464
+ end
465
+
466
+ alias folder_by_id collection_by_id
467
+
421
468
  # Creates a top-level folder with given title. Returns GoogleDrive::Collection
422
469
  # object.
423
470
  def create_collection(title, file_properties = {})
@@ -24,7 +24,7 @@ module GoogleDrive
24
24
  def key
25
25
  id
26
26
  end
27
-
27
+
28
28
  # URL of worksheet-based feed of the spreadsheet.
29
29
  def worksheets_feed_url
30
30
  format(
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.11
4
+ version: 2.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Ichikawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-13 00:00:00.000000000 Z
11
+ date: 2018-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri