6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/default_context_event_serializer.rb', line 6
def serialize(event)
units = event.units.nil? ? [] : event.units.map do |unit|
{
type: unit.type,
uid: unit.uid,
}
end
req = {}
unless units.empty?
req = {
publishedAt: event.published_at,
units: units,
hashed: event.hashed
}
end
req[:goals] = event.goals.map do |x|
{
name: x.name,
achievedAt: x.achieved_at,
properties: x.properties,
}
end unless event.goals.nil?
req[:exposures] = event.exposures.select { |x| !x.id.nil? }.map do |x|
{
id: x.id,
name: x.name,
unit: x.unit,
exposedAt: x.exposed_at.to_i,
variant: x.variant,
assigned: x.assigned,
eligible: x.eligible,
overridden: x.overridden,
fullOn: x.full_on,
custom: x.custom,
audienceMismatch: x.audience_mismatch
}
end unless event.exposures.nil?
req[:attributes] = event.attributes.map do |x|
{
name: x.name,
value: x.value,
setAt: x.set_at,
}
end unless event.attributes.nil?
return nil if req.empty?
req.to_json
end
|