Class: Multiwoven::Integrations::Source::OneDrive::Client

Inherits:
UnstructuredSourceConnector
  • Object
show all
Defined in:
lib/multiwoven/integrations/source/one_drive/client.rb

Constant Summary collapse

SPREADSHEET_EXTENSIONS =
%w[.csv .xlsx .xls .xlsm].freeze
EXPIRED_ACCESS_TOKEN_ERROR_CODE =
"InvalidAuthenticationToken"

Instance Method Summary collapse

Instance Method Details

#check_connection(connection_config) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/multiwoven/integrations/source/one_drive/client.rb', line 10

def check_connection(connection_config)
  connection_config = connection_config.with_indifferent_access
  if unstructured_data?(connection_config)
    create_connection(connection_config)
    fetch_list_items
  else
    conn = create_connection(connection_config)
    @sync_id = "check_connection"
    files = spreadsheet_files(fetch_list_items)
    raise StandardError, "No spreadsheet files found" if files.empty?

    files.each { |file| describe_spreadsheet_file(conn, file) }
  end

  success_status
rescue StandardError, NotImplementedError => e
  handle_exception(e, {
                     context: "ONE_DRIVE:CHECK_CONNECTION:EXCEPTION",
                     type: "error"
                   })
  failure_status(e)
end

#discover(connection_config) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/multiwoven/integrations/source/one_drive/client.rb', line 33

def discover(connection_config)
  connection_config = connection_config.with_indifferent_access

  streams = if unstructured_data?(connection_config)
              [create_unstructured_stream]
            else
              conn = create_connection(connection_config)
              @sync_id = "discover"
              files = spreadsheet_files(fetch_list_items)
              raise StandardError, "No spreadsheet files found" if files.empty?

              files.map { |file| discover_stream_for_file(conn, file) }
            end
  catalog = Catalog.new(streams: streams)
  catalog.to_multiwoven_message
rescue StandardError => e
  handle_exception(e, { context: "ONE_DRIVE:DISCOVER:EXCEPTION", type: "error" })
end

#read(sync_config) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/multiwoven/integrations/source/one_drive/client.rb', line 52

def read(sync_config)
  connection_config = sync_config.source.connection_specification.with_indifferent_access
  @connector_instance = sync_config&.source&.connector_instance

  return handle_unstructured_data(sync_config) if unstructured_data?(connection_config)

  conn = create_connection(connection_config)

  @connection_config = connection_config
  @sync_id = sync_config.sync_id

  query = sync_config.model.query
  query = batched_query(query, sync_config.limit, sync_config.offset) unless sync_config.limit.nil? && sync_config.offset.nil?
  query(conn, query)
rescue StandardError => e
  handle_exception(e, {
                     context: "ONE_DRIVE:READ:EXCEPTION",
                     type: "error",
                     sync_id: sync_config.sync_id,
                     sync_run_id: sync_config.sync_run_id
                   })
end