Module: Lexdrill::OauthRemote

Defined in:
lib/lexdrill/oauth_remote.rb

Overview

Global "which Google Sheet to export to via the OAuth device-flow login" setting. Lives at ~/.drill.oauth-remote as a plain spreadsheet id, parsed out of a normal Google Sheets share URL. Set via drill oauth <url>. See Lexdrill::Remote for the separate, service-account-based flow.

Constant Summary collapse

PATH =
File.join(Dir.home, ".drill.oauth-remote")
URL_PATTERN =
%r{/spreadsheets/d/([a-zA-Z0-9_-]+)}

Class Method Summary collapse

Class Method Details

.configured?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/lexdrill/oauth_remote.rb', line 22

def self.configured?
  File.exist?(PATH)
end

.extract_id(url) ⇒ Object



18
19
20
# File 'lib/lexdrill/oauth_remote.rb', line 18

def self.extract_id(url)
  url[URL_PATTERN, 1]
end

.set(url) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
# File 'lib/lexdrill/oauth_remote.rb', line 11

def self.set(url)
  id = extract_id(url)
  raise ArgumentError, "no spreadsheet id found in #{url.inspect}" unless id

  File.write(PATH, id)
end

.spreadsheet_idObject



26
27
28
# File 'lib/lexdrill/oauth_remote.rb', line 26

def self.spreadsheet_id
  File.read(PATH).strip if configured?
end