Class: Etl::Integrations::Destination::GoogleSheets::Client
- Inherits:
-
DestinationConnector
- Object
- DestinationConnector
- Etl::Integrations::Destination::GoogleSheets::Client
- Includes:
- Core::Fullrefresher, Core::RateLimiter
- Defined in:
- lib/etl/integrations/destination/google_sheets/client.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- MAX_CHUNK_SIZE =
10_000
Instance Method Summary collapse
- #check_connection(connection_config) ⇒ Object
- #clear_all_records(sync_config) ⇒ Object
- #discover(connection_config) ⇒ Object
- #write(sync_config, records, action = "create") ⇒ Object
Instance Method Details
#check_connection(connection_config) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/etl/integrations/destination/google_sheets/client.rb', line 14 def check_connection(connection_config) connection_config = connection_config.with_indifferent_access (connection_config) fetch_google_spread_sheets(connection_config) success_status rescue StandardError => e handle_exception("GOOGLE_SHEETS:CRM:DISCOVER:EXCEPTION", "error", e) failure_status(e) end |
#clear_all_records(sync_config) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/etl/integrations/destination/google_sheets/client.rb', line 41 def clear_all_records(sync_config) setup_write_environment(sync_config, "clear") connection_specification = sync_config.destination.connection_specification.with_indifferent_access spreadsheet = fetch_google_spread_sheets(connection_specification) sheet_ids = spreadsheet.sheets.map(&:properties).map(&:sheet_id) delete_extra_sheets(sheet_ids) unless sheet_ids.empty? clear_response = clear_sheet_data(spreadsheet.sheets.first.properties.title) return ("Successfully cleared data.", "succeeded") if clear_response&.cleared_range end ("Failed to clear data.", "failed") rescue StandardError => e (e., "failed") end |
#discover(connection_config) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/etl/integrations/destination/google_sheets/client.rb', line 24 def discover(connection_config) connection_config = connection_config.with_indifferent_access (connection_config) spreadsheets = fetch_google_spread_sheets(connection_config) catalog = build_catalog_from_spreadsheets(spreadsheets, connection_config) catalog. rescue StandardError => e handle_exception("GOOGLE_SHEETS:CRM:DISCOVER:EXCEPTION", "error", e) end |
#write(sync_config, records, action = "create") ⇒ Object
34 35 36 37 38 39 |
# File 'lib/etl/integrations/destination/google_sheets/client.rb', line 34 def write(sync_config, records, action = "create") setup_write_environment(sync_config, action) process_record_chunks(records, sync_config) rescue StandardError => e handle_exception("GOOGLE_SHEETS:CRM:WRITE:EXCEPTION", "error", e) end |