-
Notifications
You must be signed in to change notification settings - Fork 244
/
CountlyEvent.m
81 lines (74 loc) · 3.96 KB
/
CountlyEvent.m
1
2
3
4
5
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// CountlyEvent.m
//
// This code is provided under the MIT License.
//
// Please visit www.count.ly for more information.
#import "CountlyCommon.h"
@implementation CountlyEvent
NSString* const kCountlyEventKeyKey = @"key";
NSString* const kCountlyEventKeyID = @"id";
NSString* const kCountlyEventKeyCVID = @"cvid";
NSString* const kCountlyEventKeyPVID = @"pvid";
NSString* const kCountlyEventKeyPEID = @"peid";
NSString* const kCountlyEventKeySegmentation = @"segmentation";
NSString* const kCountlyEventKeyCount = @"count";
NSString* const kCountlyEventKeySum = @"sum";
NSString* const kCountlyEventKeyTimestamp = @"timestamp";
NSString* const kCountlyEventKeyHourOfDay = @"hour";
NSString* const kCountlyEventKeyDayOfWeek = @"dow";
NSString* const kCountlyEventKeyDuration = @"dur";
- (NSDictionary *)dictionaryRepresentation
{
NSMutableDictionary* eventData = NSMutableDictionary.dictionary;
eventData[kCountlyEventKeyKey] = self.key;
if (self.segmentation)
{
eventData[kCountlyEventKeySegmentation] = self.segmentation;
}
eventData[kCountlyEventKeyID] = self.ID;
eventData[kCountlyEventKeyCVID] = self.CVID;
eventData[kCountlyEventKeyPVID] = self.PVID;
eventData[kCountlyEventKeyPEID] = self.PEID;
eventData[kCountlyEventKeyCount] = @(self.count);
eventData[kCountlyEventKeySum] = @(self.sum);
eventData[kCountlyEventKeyTimestamp] = @((long long)(self.timestamp * 1000));
eventData[kCountlyEventKeyHourOfDay] = @(self.hourOfDay);
eventData[kCountlyEventKeyDayOfWeek] = @(self.dayOfWeek);
eventData[kCountlyEventKeyDuration] = @(self.duration);
return eventData;
}
- (instancetype)initWithCoder:(NSCoder *)decoder
{
if (self = [super init])
{
self.key = [decoder decodeObjectForKey:NSStringFromSelector(@selector(key))];
self.ID = [decoder decodeObjectForKey:NSStringFromSelector(@selector(ID))];
self.CVID = [decoder decodeObjectForKey:NSStringFromSelector(@selector(CVID))];
self.PVID = [decoder decodeObjectForKey:NSStringFromSelector(@selector(PVID))];
self.PEID = [decoder decodeObjectForKey:NSStringFromSelector(@selector(PEID))];
self.segmentation = [decoder decodeObjectForKey:NSStringFromSelector(@selector(segmentation))];
self.count = [decoder decodeIntegerForKey:NSStringFromSelector(@selector(count))];
self.sum = [decoder decodeDoubleForKey:NSStringFromSelector(@selector(sum))];
self.timestamp = [decoder decodeDoubleForKey:NSStringFromSelector(@selector(timestamp))];
self.hourOfDay = [decoder decodeIntegerForKey:NSStringFromSelector(@selector(hourOfDay))];
self.dayOfWeek = [decoder decodeIntegerForKey:NSStringFromSelector(@selector(dayOfWeek))];
self.duration = [decoder decodeDoubleForKey:NSStringFromSelector(@selector(duration))];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:self.key forKey:NSStringFromSelector(@selector(key))];
[encoder encodeObject:self.ID forKey:NSStringFromSelector(@selector(ID))];
[encoder encodeObject:self.CVID forKey:NSStringFromSelector(@selector(CVID))];
[encoder encodeObject:self.PVID forKey:NSStringFromSelector(@selector(PVID))];
[encoder encodeObject:self.PEID forKey:NSStringFromSelector(@selector(PEID))];
[encoder encodeObject:self.segmentation forKey:NSStringFromSelector(@selector(segmentation))];
[encoder encodeInteger:self.count forKey:NSStringFromSelector(@selector(count))];
[encoder encodeDouble:self.sum forKey:NSStringFromSelector(@selector(sum))];
[encoder encodeDouble:self.timestamp forKey:NSStringFromSelector(@selector(timestamp))];
[encoder encodeInteger:self.hourOfDay forKey:NSStringFromSelector(@selector(hourOfDay))];
[encoder encodeInteger:self.dayOfWeek forKey:NSStringFromSelector(@selector(dayOfWeek))];
[encoder encodeDouble:self.duration forKey:NSStringFromSelector(@selector(duration))];
}
@end