Sha256: 337c1a25199cf304a60dc55bda0735322f95ee85924fa64e593e5ee14e9aafb8
Contents?: true
Size: 1.4 KB
Versions: 21
Compression:
Stored size: 1.4 KB
Contents
require "google/apis/drive_v3" require "googleauth" require "googleauth/stores/file_token_store" require "fileutils" # ------------------- Isn't actually implemented right now ------------------- # module Remote OOB_URI = "urn:ietf:wg:oauth:2.0:oob" APPLICATION_NAME = "Drive API Ruby Quickstart" CREDENTIALS_PATH = ".json" TOKEN_PATH = "token.yaml" SCOPE = Google::Apis::DriveV3::AUTH_DRIVE_METADATA_READONLY def self.authorize client_id = Google::Auth::ClientId.from_file(CREDENTIALS_PATH) token_store = Google::Auth::Stores::FileTokenStore.new(file: TOKEN_PATH) authorizer = Google::Auth::UserAuthorizer.new(client_id, SCOPE, token_store) user_id = "default" credentials = authorizer.get_credentials(user_id) if credentials.nil? url = authorizer.get_authorization_url(base_url: OOB_URI) puts "Open the following URL in the browser and enter the " \ "resulting code after authorization:\n" + url code = gets credentials = authorizer.get_credentials_from_code(user_id: user_id, code: code, base_url: OOB_URI) end credentials end def self.list_files_in_drive(directory_id) drive_service = Google::Apis::DriveV3::DriveService.new drive_service.client_options.application_name = APPLICATION_NAME drive_service.authorization = authorize response = drive_service.list_files(q: "'#{directory_id}' in parents") response.files end end
Version data entries
21 entries across 21 versions & 1 rubygems