Class: Outhad::Integrations::Destination::GoogleSheets::Client
- Inherits:
-
DestinationConnector
- Object
- DestinationConnector
- Outhad::Integrations::Destination::GoogleSheets::Client
- Includes:
- Core::Fullrefresher, Core::RateLimiter
- Defined in:
- lib/outhad/integrations/destination/google_sheets/client.rb
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 |
# File 'lib/outhad/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 failure_status(e) end |
#clear_all_records(sync_config) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/outhad/integrations/destination/google_sheets/client.rb', line 48 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
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/outhad/integrations/destination/google_sheets/client.rb', line 23 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(e, { context: "GOOGLE_SHEETS:CRM:DISCOVER:EXCEPTION", type: "error" }) end |
#write(sync_config, records, action = "create") ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/outhad/integrations/destination/google_sheets/client.rb', line 36 def write(sync_config, records, action = "create") setup_write_environment(sync_config, action) process_record_chunks(records, sync_config) rescue StandardError => e handle_exception(e, { context: "GOOGLE_SHEETS:CRM:WRITE:EXCEPTION", type: "error", sync_id: sync_config.sync_id, sync_run_id: sync_config.sync_run_id }) end |