Class: AdLocalize::Repositories::GSheetsRepository
- Inherits:
-
Object
- Object
- AdLocalize::Repositories::GSheetsRepository
- Defined in:
- lib/ad_localize/repositories/g_sheets_repository.rb
Constant Summary collapse
- SCOPES =
[Google::Apis::SheetsV4::AUTH_SPREADSHEETS_READONLY]
- ROWS_MAJOR_DIMENSION =
'ROWS'.freeze
- SPREADSHEET_APPLICATION_NAME =
'ad_localize'.freeze
Instance Method Summary collapse
- #get_sheets_values(g_spreadsheet_options:) ⇒ Object
-
#initialize ⇒ GSheetsRepository
constructor
A new instance of GSheetsRepository.
Constructor Details
#initialize ⇒ GSheetsRepository
Returns a new instance of GSheetsRepository.
8 9 10 11 |
# File 'lib/ad_localize/repositories/g_sheets_repository.rb', line 8 def initialize @service = Google::Apis::SheetsV4::SheetsService.new @service..application_name = SPREADSHEET_APPLICATION_NAME end |
Instance Method Details
#get_sheets_values(g_spreadsheet_options:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ad_localize/repositories/g_sheets_repository.rb', line 13 def get_sheets_values(g_spreadsheet_options:) configure(json_configuration: .service_account_config) if @service..nil? spreadsheet = @service.get_spreadsheet(.spreadsheet_id) if .export_all spreadsheet.sheets.map { |sheet| get_sheet_values(spreadsheet_id: .spreadsheet_id, sheet: sheet) } elsif .sheet_ids.nil? || .sheet_ids.size.zero? spreadsheet.sheets[0..0].map { |sheet| get_sheet_values(spreadsheet_id: .spreadsheet_id, sheet: sheet) } else spreadsheet.sheets.select do |sheet| .sheet_ids.include?(sheet.properties.sheet_id.to_s) end.map do |sheet| get_sheet_values(spreadsheet_id: .spreadsheet_id, sheet: sheet) end end end |