Class: Multiwoven::Integrations::Source::MicrosoftDynamics::Client

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

Instance Method Summary collapse

Instance Method Details

#check_connection(connection_config) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/multiwoven/integrations/source/microsoft_dynamics/client.rb', line 20

def check_connection(connection_config)
  connection_config = connection_config.with_indifferent_access
  create_connection(connection_config)
  response = dynamics_request(whoami_url)
  response_body = JSON.parse(response.body)

  if success?(response) && response_body.key?("UserId")
    success_status
  else
    failure_status(nil)
  end
rescue StandardError => e
  handle_exception(e, {
                     context: "MICROSOFT:DYNAMICS:CHECK_CONNECTION:EXCEPTION",
                     type: "error"
                   })
  failure_status(e)
end

#discover(connection_config) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/multiwoven/integrations/source/microsoft_dynamics/client.rb', line 39

def discover(connection_config)
  connection_config = connection_config.with_indifferent_access
  create_connection(connection_config)

  streams = DYNAMICS_OBJECTS.filter_map do |entity|
    create_stream_for_entity(entity)
  rescue StandardError => e
    handle_exception(e, {
                       context: "MICROSOFT:DYNAMICS:DISCOVER:LOOP_EXCEPTION",
                       type: "error"
                     })
    nil
  end

  Catalog.new(streams: streams).to_multiwoven_message
rescue StandardError => e
  handle_exception(e, {
                     context: "MICROSOFT:DYNAMICS:DISCOVER:EXCEPTION",
                     type: "error"
                   })
end

#read(sync_config) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/multiwoven/integrations/source/microsoft_dynamics/client.rb', line 61

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

  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(nil, query)
rescue StandardError => e
  handle_exception(e, {
                     context: "MICROSOFT:DYNAMICS:READ:EXCEPTION",
                     type: "error",
                     sync_id: sync_config.sync_id,
                     sync_run_id: sync_config.sync_run_id
                   })
end