Class: FlashFlow::Release::GoogleDrive
- Inherits:
-
Object
- Object
- FlashFlow::Release::GoogleDrive
- Defined in:
- lib/flash_flow/google_drive.rb
Constant Summary collapse
- DRIVE =
Google::Apis::DriveV3
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #find_files(query) ⇒ Object
-
#initialize ⇒ GoogleDrive
constructor
A new instance of GoogleDrive.
- #set_file_permissions(file_id, config = {}) ⇒ Object
- #upload_file(local_file, config = {}) ⇒ Object
Constructor Details
#initialize ⇒ GoogleDrive
Returns a new instance of GoogleDrive.
12 13 14 15 16 |
# File 'lib/flash_flow/google_drive.rb', line 12 def initialize scopes = [DRIVE::AUTH_DRIVE] @client = DRIVE::DriveService.new @client. = Google::Auth.get_application_default(scopes) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/flash_flow/google_drive.rb', line 8 def client @client end |
Instance Method Details
#find_files(query) ⇒ Object
24 25 26 27 |
# File 'lib/flash_flow/google_drive.rb', line 24 def find_files(query) response = @client.list_files(q: query) response.files end |
#set_file_permissions(file_id, config = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/flash_flow/google_drive.rb', line 29 def (file_id, config={}) @client.batch do %w(group user).each do |type| %w(reader writer).each do |role| # owner is currently not supported config.dig('permissions', type, role).to_s.split(',').each do |email| = DRIVE::Permission.new(role: role, type: type, email_address: email) @client.(file_id, , email_message: config[:email_body], send_notification_email: config['notify']) end end end end end |
#upload_file(local_file, config = {}) ⇒ Object
18 19 20 21 22 |
# File 'lib/flash_flow/google_drive.rb', line 18 def upload_file(local_file, config={}) = DRIVE::File.new(name: File.basename(local_file), extension: 'pdf') = @client.create_file(, upload_source: local_file, content_type: 'application/pdf') (.id, config) end |