Class: Connectors::Example::Connector

Inherits:
Base::Connector show all
Defined in:
lib/connectors/example/connector.rb

Instance Attribute Summary

Attributes inherited from Base::Connector

#advanced_filter_config, #rules

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base::Connector

configurable_fields_indifferent_access, #do_health_check!, filter_transformers, #is_healthy?, kibana_features, #metadata, simple_rules_validators, validate_filtering, #yield_with_handling_tolerable_errors

Constructor Details

#initialize(configuration: {}, job_description: nil) ⇒ Connector

Returns a new instance of Connector.



39
40
41
# File 'lib/connectors/example/connector.rb', line 39

def initialize(configuration: {}, job_description: nil)
  super
end

Class Method Details

.advanced_snippet_validatorsObject



50
51
52
# File 'lib/connectors/example/connector.rb', line 50

def self.advanced_snippet_validators
  ExampleAdvancedSnippetValidator
end

.configurable_fieldsObject

Field ‘Foo’ won’t have a default value. Field ‘Bar’ will have the default value ‘Value’.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/connectors/example/connector.rb', line 26

def self.configurable_fields
  {
    'foo' => {
      'label' => 'Foo',
      'value' => nil
    },
    :bar => {
      :label => 'Bar',
      :value => 'Value'
    }
  }
end

.display_nameObject



21
22
23
# File 'lib/connectors/example/connector.rb', line 21

def self.display_name
  'Example Connector'
end

.service_typeObject



17
18
19
# File 'lib/connectors/example/connector.rb', line 17

def self.service_type
  'example'
end

Instance Method Details

#do_health_checkObject



43
44
45
46
47
48
# File 'lib/connectors/example/connector.rb', line 43

def do_health_check
  # Do the health check by trying to access 3rd-party system just to verify that everything is set up properly.
  #
  # To emulate unhealthy 3rd-party system situation, uncomment the following line:
  # raise 'something went wrong'
end

#yield_documentsObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/connectors/example/connector.rb', line 54

def yield_documents
  attachments = [
    load_attachment('first_attachment.txt'),
    load_attachment('second_attachment.txt'),
    load_attachment('third_attachment.txt'),
  ]

  attachments.each_with_index do |att, index|
    data = { id: (index + 1).to_s, name: "example document #{index + 1}", _attachment: File.read(att) }

    # Uncomment one of these two lines to simulate longer running sync jobs
    #
    # sleep(rand(10..60).seconds)
    # sleep(rand(1..10).minutes)

    yield data
  end
end