Class: GoogleDriveDotenv::App

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/google_drive_dotenv/cli.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.credentialsObject

Returns the value of attribute credentials.



12
13
14
# File 'lib/google_drive_dotenv/cli.rb', line 12

def credentials
  @credentials
end

.keyObject

Returns the value of attribute key.



12
13
14
# File 'lib/google_drive_dotenv/cli.rb', line 12

def key
  @key
end

.outputObject

Returns the value of attribute output.



12
13
14
# File 'lib/google_drive_dotenv/cli.rb', line 12

def output
  @output
end

Class Method Details

.export_env(authorization_code) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/google_drive_dotenv/cli.rb', line 14

def export_env(authorization_code)
  credentials.code = authorization_code
  credentials.fetch_access_token!

  session = GoogleDrive::Session.from_credentials(credentials)

  sheet = session.spreadsheet_by_key(key).worksheets[0]
  File.open(output, 'wb') do |file|
    (1..sheet.num_rows).each do |row|
      key = sheet[row, 1]
      value = sheet[row, 2]
      file.puts([key, value].join('='))
    end
  end

end