Class: ForestLiana::MixpanelController

Inherits:
ApplicationController show all
Defined in:
app/controllers/forest_liana/mixpanel_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_user_from_jwt, #forest_user, #internal_server_error, papertrail?, #serialize_model, #serialize_models

Methods inherited from BaseController

#route_not_found

Instance Method Details

#get_serializer_type(suffix) ⇒ Object



23
24
25
# File 'app/controllers/forest_liana/mixpanel_controller.rb', line 23

def get_serializer_type(suffix)
  "#{params[:collection]}_#{suffix}"
end

#last_eventsObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/forest_liana/mixpanel_controller.rb', line 3

def last_events
  collection_name = params[:collection]
  mapping = ForestLiana.integrations[:mixpanel][:mapping]
  mapping_for_current_collection = mapping.find { |item| item.start_with?(collection_name) }
  field_name = mapping_for_current_collection.split('.')[1]
  id = params[:id]
  field_value = collection_name.constantize.find_by('id': id)[field_name]

  getter = ForestLiana::MixpanelLastEventsGetter.new(params)
  getter.perform(field_name, field_value)

  custom_properties = ForestLiana.integrations[:mixpanel][:custom_properties]
  MixpanelEventSerializer.attributes(*custom_properties)

  render serializer: nil, json: serialize_models(getter.records, {
    context: { type: get_serializer_type('mixpanel_events') },
    count: getter.count,
  })
end