Class: Arquivo::C118sheets

Inherits:
Object
  • Object
show all
Defined in:
lib/arquivo/sheets.rb

Overview

acede a folhas-calculo c118

Direct Known Subclasses

C118bigquery

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeC118sheets

Returns acesso folhas-calculo c118.



14
15
16
# File 'lib/arquivo/sheets.rb', line 14

def initialize
  sheets_credentials
end

Instance Attribute Details

#folhasGoogle::Apis::SheetsV4::SheetsService (readonly)

Returns API folhas-calculo c118.

Returns:

  • (Google::Apis::SheetsV4::SheetsService)

    API folhas-calculo c118



11
12
13
# File 'lib/arquivo/sheets.rb', line 11

def folhas
  @folhas
end

Instance Method Details

#new_credentials(aut, oob) ⇒ Google::Auth::UserAuthorizer

inicializar OAuth2 authorization abrindo URL e copiando novo codigo

Returns:

  • (Google::Auth::UserAuthorizer)

    OAuth2 credentials



37
38
39
40
# 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_credentialsGoogle::Apis::SheetsV4::SheetsService

inicializar API sheets com ID cliente & credenciais

Returns:

  • (Google::Apis::SheetsV4::SheetsService)

    API folhas-calculo c118



21
22
23
24
25
26
27
28
29
30
31
32
# 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