Method: TransyncConfig.init_spreadsheet

Defined in:
lib/transync/transync_config.rb

.init_spreadsheetObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/transync/transync_config.rb', line 16

def self.init_spreadsheet
  # Authorizes with OAuth and gets an access token.
  client             = Google::APIClient.new(
    application_name: 'Transync',
    application_version: Transync::VERSION
  )
  auth               = client.authorization
  auth.client_id     = CONFIG['GDOC']['client_id'] # "YOUR CLIENT ID"
  auth.client_secret = CONFIG['GDOC']['client_secret'] # "YOUR CLIENT SECRET"
  auth.scope = [
      'https://www.googleapis.com/auth/drive',
      'https://spreadsheets.google.com/feeds/'
  ]
  auth.redirect_uri = 'urn:ietf:wg:oauth:2.0:oob'
  print("1. Open this page:\n%s\n\n" % auth.authorization_uri)
  print('2. Enter the authorization code shown in the page: ')
  auth.code = $stdin.gets.chomp
  auth.fetch_access_token!
  access_token = auth.access_token

  # session     = GoogleDrive.login_with_oauth(CONFIG['GDOC']['email'], CONFIG['GDOC']['password'])
  session     = GoogleDrive.(access_token)
  spreadsheet = session.spreadsheet_by_key(CONFIG['GDOC']['key'])
  worksheets  = spreadsheet.worksheets

  return spreadsheet, worksheets
end