Class: GoogleSheets::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/google_sheets/session.rb

Constant Summary collapse

OOB_URI =
'urn:ietf:wg:oauth:2.0:oob'
CREDENTIALS_FILENAME =
'token.yaml'
SCOPE =
Google::Apis::SheetsV4::AUTH_SPREADSHEETS

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service) ⇒ Session

Accepts a Google::Apis::SheetsV4::SheetsService through which we can read/write gsheets


19
20
21
# File 'lib/google_sheets/session.rb', line 19

def initialize service
  @service = service
end

Class Method Details

.start_session(client_id:, client_secret:, token_path: '.') ⇒ GoogleSheets::Session

Everything starts from this method - authorizes the user and creates a Session object, through which we can read spreadsheets.


74
75
76
77
78
79
80
81
# File 'lib/google_sheets/session.rb', line 74

def self.start_session client_id:, client_secret:, token_path: '.'
  # Initialize the API
  service = Google::Apis::SheetsV4::SheetsService.new
  # service.client_options.application_name = APPLICATION_NAME
  service.authorization = authorize(client_id, client_secret, token_path)

  Session.new(service)
end

Instance Method Details

#spreadsheet_from_key(key) ⇒ GoogleSheets::Spreadsheet

instantiates and returns a Spreadsheet object from a key


25
26
27
# File 'lib/google_sheets/session.rb', line 25

def spreadsheet_from_key key
  Spreadsheet.new @service, key
end