Class: TreatanyoneCommonApi::Kinesis

Inherits:
Object
  • Object
show all
Defined in:
lib/treatanyone_common_api/kinesis.rb

Constant Summary collapse

DEFAULT_REGION =
"us-west-2".freeze
DEFAULT_STREAM_NAME =
"treatanyone-domain-stream-dev".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_type, model_object, user_id, options = {}) ⇒ Kinesis

Returns a new instance of Kinesis.



13
14
15
16
17
18
19
20
21
# File 'lib/treatanyone_common_api/kinesis.rb', line 13

def initialize(event_type, model_object, user_id, options = {})
  @event_type = event_type
  @model_object = model_object
  @user_id = user_id
  @data = options[:data]
  @aggregate_type = options[:aggregate_type].presence || model_object.class.name
  @lambda_arn = options[:lambda_arn].presence
  @region = options[:region].presence || TreatanyoneCommonApi::Kinesis::DEFAULT_REGION
end

Instance Attribute Details

#aggregate_typeObject (readonly)

Returns the value of attribute aggregate_type.



10
11
12
# File 'lib/treatanyone_common_api/kinesis.rb', line 10

def aggregate_type
  @aggregate_type
end

#dataObject (readonly)

Returns the value of attribute data.



10
11
12
# File 'lib/treatanyone_common_api/kinesis.rb', line 10

def data
  @data
end

#event_typeObject (readonly)

Returns the value of attribute event_type.



10
11
12
# File 'lib/treatanyone_common_api/kinesis.rb', line 10

def event_type
  @event_type
end

#lambda_arnObject (readonly)

Returns the value of attribute lambda_arn.



10
11
12
# File 'lib/treatanyone_common_api/kinesis.rb', line 10

def lambda_arn
  @lambda_arn
end

#model_objectObject (readonly)

Returns the value of attribute model_object.



10
11
12
# File 'lib/treatanyone_common_api/kinesis.rb', line 10

def model_object
  @model_object
end

#regionObject (readonly)

Returns the value of attribute region.



10
11
12
# File 'lib/treatanyone_common_api/kinesis.rb', line 10

def region
  @region
end

#user_idObject (readonly)

Returns the value of attribute user_id.



10
11
12
# File 'lib/treatanyone_common_api/kinesis.rb', line 10

def user_id
  @user_id
end

Instance Method Details

#publish_eventObject



23
24
25
26
27
28
29
# File 'lib/treatanyone_common_api/kinesis.rb', line 23

def publish_event
  client.put_record(
    stream_name: kinesis_stream_name,
    data: event_data_as_json,
    partition_key: partition_key
  )
end