Class: GoogleSpreadsheetFetcher::SheetsServiceBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/google_spreadsheet_fetcher/sheets_service_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(user_id, config: nil, application_name: nil) ⇒ SheetsServiceBuilder

Returns a new instance of SheetsServiceBuilder.

Parameters:



6
7
8
9
10
# File 'lib/google_spreadsheet_fetcher/sheets_service_builder.rb', line 6

def initialize(user_id, config: nil, application_name: nil)
  @user_id = user_id
  @config = config || GoogleSpreadsheetFetcher.config
  @application_name = application_name
end

Instance Method Details

#build(authorizer: nil) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/google_spreadsheet_fetcher/sheets_service_builder.rb', line 12

def build(authorizer: nil)
  authorizer = authorizer || config.authorizer || ::GoogleSpreadsheetFetcher::Authorizer::Oauth2::Authorizer.new
  raise 'Authorizer is not configured' if authorizer.blank?

  ::Google::Apis::SheetsV4::SheetsService.new.tap do |service|
    service.authorization = authorizer.fetch_credentials!(user_id: user_id)
    service.client_options.application_name = application_name if application_name.present?
  end
end