main-branch/drive_v3

View on GitHub
examples/permission_delete

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby
# frozen_string_literal: true

# List permissions for a file or folder

require 'drive_v3'

file_id = ARGV.shift || ENV.fetch('FILE_ID', nil)
raise 'Missing file_id' unless file_id

permission_id = ARGV.shift || ENV.fetch('PERMISSION_ID', nil)
raise 'Missing permission_id' unless permission_id

raise "Extra arguments: #{ARGV}" unless ARGV.empty?

drive_service = DriveV3.drive_service

# Indicate that this application supports files in shared drives. An error will
# result if this is false (or omitted) AND you are trying to delete the permissions
# on a file in a shared drive.
#
supports_all_drives = true

begin
  drive_service.delete_permission(file_id, permission_id, supports_all_drives:)
rescue StandardError => e
  puts "An error occurred: #{e.message}"
end