Module: Remote

Defined in:
lib/jekyll/remote.rb

Overview

——————- Isn’t actually implemented right now ——————- #

Constant Summary collapse

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::

Class Method Summary collapse

Class Method Details

.authorizeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jekyll/remote.rb', line 13

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

.list_files_in_drive(directory_id) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/jekyll/remote.rb', line 29

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