Class: Outhad::Integrations::Destination::MicrosoftExcel::Client
- Inherits:
-
DestinationConnector
- Object
- DestinationConnector
- Outhad::Integrations::Destination::MicrosoftExcel::Client
- Includes:
- Core::RateLimiter
- Defined in:
- lib/outhad/integrations/destination/microsoft_excel/client.rb
Instance Method Summary collapse
- #check_connection(connection_config) ⇒ Object
- #discover(connection_config) ⇒ Object
- #write(sync_config, records, _action = "destination_insert") ⇒ Object
Instance Method Details
#check_connection(connection_config) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/outhad/integrations/destination/microsoft_excel/client.rb', line 8 def check_connection(connection_config) connection_config = connection_config.with_indifferent_access drive_id = create_connection(connection_config) if drive_id success_status else failure_status(nil) end rescue StandardError => e handle_exception(e, { context: "MICROSOFT:EXCEL:CHECK_CONNECTION:EXCEPTION", type: "error" }) failure_status(e) end |
#discover(connection_config) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/outhad/integrations/destination/microsoft_excel/client.rb', line 24 def discover(connection_config) catalog_json = read_json(CATALOG_SPEC_PATH) connection_config = connection_config.with_indifferent_access token = connection_config[:token] drive_id = create_connection(connection_config) records = get_file(token, drive_id) records.each do |record| file_id = record[:id] record[:worksheets] = get_file_data(token, drive_id, file_id) end catalog = Catalog.new(streams: create_streams(records, catalog_json)) catalog. rescue StandardError => e handle_exception(e, { context: "MICROSOFT:EXCEL:DISCOVER:EXCEPTION", type: "error" }) end |
#write(sync_config, records, _action = "destination_insert") ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/outhad/integrations/destination/microsoft_excel/client.rb', line 43 def write(sync_config, records, _action = "destination_insert") connection_config = sync_config.destination.connection_specification.with_indifferent_access token = connection_config[:token] file_name = sync_config.stream.name.split(", ").first sheet_name = sync_config.stream.name.split(", ").last drive_id = create_connection(connection_config) excel_files = get_file(token, drive_id) worksheet = excel_files.find { |file| file[:name] == file_name } item_id = worksheet[:id] table = get_table(token, drive_id, item_id, sheet_name) write_url = format(MS_EXCEL_TABLE_ROW_WRITE_API, drive_id: drive_id, item_id: item_id, sheet_name: sheet_name, table_name: table["name"]) payload = { values: records.map(&:values) } process_write_request(write_url, payload, token, sync_config) end |