class Arquivo::C118sheets

acede a folhas-calculo c118

Attributes

folhas[R]

@return (see sheets_credentials)

Public Class Methods

new() click to toggle source

@return [C118sheets] acesso folhas-calculo c118

# File lib/arquivo/sheets.rb, line 14
def initialize
  sheets_credentials
end

Public Instance Methods

new_credentials(aut, oob) click to toggle source

inicializar OAuth2 authorization abrindo URL e copiando novo codigo

@return [Google::Auth::UserAuthorizer] OAuth2 credentials

# File lib/arquivo/sheets.rb, line 37
def new_credentials(aut, oob)
  puts 'Open URL and copy code after authorization, in <codigo-aqui>', aut.get_authorization_url(base_url: oob)
  aut.get_and_store_credentials_from_code(user_id: 'default', code: '<codigo-aqui>', base_url: oob)
end
sheets_credentials() click to toggle source

inicializar API sheets com ID cliente & credenciais

@return [Google::Apis::SheetsV4::SheetsService] API folhas-calculo c118

# File lib/arquivo/sheets.rb, line 21
def sheets_credentials
  l = '/home/c118/.sheets.'
  # file obtido console.cloud.google.com/apis OAuth 2.0 client IDs
  i = Google::Auth::ClientId.from_file(l + 'json')
  s = Google::Apis::SheetsV4::AUTH_SPREADSHEETS_READONLY
  # file criado aquando new_credentials is executed
  f = Google::Auth::Stores::FileTokenStore.new(file: l + 'yaml')
  z = Google::Auth::UserAuthorizer.new(i, s, f)
  @folhas = Google::Apis::SheetsV4::SheetsService.new
  @folhas.client_options.application_name = 'c118-arquivo'
  @folhas.authorization = z.get_credentials('default') || new_credentials(z, 'urn:ietf:wg:oauth:2.0:oob')
end