Module: PlatformSdk::ActiveRecord::DataPipelineable

Extended by:
ActiveSupport::Concern
Defined in:
lib/platform_sdk/active_record/data_pipelineable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.pipeline_metaObject

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/platform_sdk/active_record/data_pipelineable.rb', line 42

def self.pipeline_meta
  raise NotImplementedError, 'You must implement the pipeline_meta class method, an example value is { "source": "strongmind-central" }'
end

.pipeline_nounObject

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/platform_sdk/active_record/data_pipelineable.rb', line 38

def self.pipeline_noun
  raise NotImplementedError, 'You must implement the pipeline_noun class method'
end

Instance Method Details

#one_roster_pipeline_payload(deleted: false) ⇒ Object



67
68
69
# File 'lib/platform_sdk/active_record/data_pipelineable.rb', line 67

def one_roster_pipeline_payload(deleted: false)
  {}
end

#pipeline_additional_attributesObject



63
64
65
# File 'lib/platform_sdk/active_record/data_pipelineable.rb', line 63

def pipeline_additional_attributes
  {}
end

#pipeline_data(action) ⇒ Object



56
57
58
59
60
61
# File 'lib/platform_sdk/active_record/data_pipelineable.rb', line 56

def pipeline_data(action)
  attributes.symbolize_keys
    .merge(pipeline_additional_attributes)
    .except(*pipeline_excluded_attributes)
    .merge(action:)
end

#pipeline_excluded_attributesObject



46
47
48
# File 'lib/platform_sdk/active_record/data_pipelineable.rb', line 46

def pipeline_excluded_attributes
  []
end

#pipeline_identifiersObject



50
51
52
53
54
# File 'lib/platform_sdk/active_record/data_pipelineable.rb', line 50

def pipeline_identifiers
  {
    "id": id
  }
end

#pipeline_payload(action) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/platform_sdk/active_record/data_pipelineable.rb', line 27

def pipeline_payload(action)
  {
    "noun": self.class.pipeline_noun,
    "identifiers": pipeline_identifiers,
    "meta": self.class.pipeline_meta,
    "data": pipeline_data(action),
    "envelope_version": '1.0.0',
    "message_timestamp": Time.current.utc.iso8601
  }
end

#send_pipeline_createObject



15
16
17
# File 'lib/platform_sdk/active_record/data_pipelineable.rb', line 15

def send_pipeline_create
  send_to_pipeline('created')
end

#send_pipeline_destroyObject



23
24
25
# File 'lib/platform_sdk/active_record/data_pipelineable.rb', line 23

def send_pipeline_destroy
  send_to_pipeline('destroyed')
end

#send_pipeline_updateObject



19
20
21
# File 'lib/platform_sdk/active_record/data_pipelineable.rb', line 19

def send_pipeline_update
  send_to_pipeline('modified')
end

#send_to_pipeline(action) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/platform_sdk/active_record/data_pipelineable.rb', line 71

def send_to_pipeline(action)
  credentials = {
    pipeline_host: ENV.fetch('DATA_PIPELINE_HOST', 'stage-di-data-pipeline-api.strongmind.com'),
    pipeline_username: ENV.fetch('DATA_PIPELINE_USERNAME', 'canvas_prod'),
    pipeline_password: ENV.fetch('DATA_PIPELINE_PASSWORD', '')
  }
  client = PlatformSdk::DataPipeline::Client.new(credentials)

  client.post(pipeline_payload(action)) unless Rails.env.development?
  return unless respond_to?(:one_roster_data_type) && !Rails.env.development? && one_roster_pipeline_payload(deleted: action == "destroyed").present?

  client.post(one_roster_pipeline_payload(deleted: action == "destroyed"))
end