class AdLocalize::Requests::GSpreadsheetOptions

Attributes

export_all[RW]
service_account_config[RW]
sheet_ids[RW]
spreadsheet_id[RW]

Public Class Methods

new(**args) click to toggle source
# File lib/ad_localize/requests/g_spreadsheet_options.rb, line 11
def initialize(**args)
  @spreadsheet_id = args[:spreadsheet_id]
  @sheet_ids = Array(args[:sheet_ids])
  @export_all = args[:export_all] || false
  @service_account_config = args[:service_account_config].presence
end

Public Instance Methods

has_multiple_sheets?() click to toggle source
# File lib/ad_localize/requests/g_spreadsheet_options.rb, line 31
def has_multiple_sheets?
  export_all || @sheet_ids.size > 1
end
public_download_urls() click to toggle source
# File lib/ad_localize/requests/g_spreadsheet_options.rb, line 22
def public_download_urls
  return [] if @service_account_config
  if @sheet_ids.size.zero?
    [public_download_url(sheet_id: nil)]
  else
    @sheet_ids.map { |sheet_id| public_download_url(sheet_id: sheet_id) }
  end
end
valid?() click to toggle source
# File lib/ad_localize/requests/g_spreadsheet_options.rb, line 18
def valid?
  (spreadsheet_id && !export_all) || (spreadsheet_id && service_account_config.present?)
end

Private Instance Methods

public_download_url(sheet_id:) click to toggle source
# File lib/ad_localize/requests/g_spreadsheet_options.rb, line 37
def public_download_url(sheet_id:)
  query_id = sheet_id.blank? ? "id=#{@spreadsheet_id}" : "gid=#{sheet_id}"
  "https://docs.google.com/spreadsheets/d/#{@spreadsheet_id}/export?format=csv&#{query_id}"
end
valid_export_all_config() click to toggle source
# File lib/ad_localize/requests/g_spreadsheet_options.rb, line 42
def valid_export_all_config
  export_all && service_account_config.present?
end