-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCSTimelineEntry.m
executable file
·129 lines (105 loc) · 4.35 KB
/
CSTimelineEntry.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
CoreStack v1.0 : CSTimelineEntry.m
Copyright (c) 2010 Adam Wright
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#import "CSTimelineEntry.h"
#import "NSDictionary+JSONDecoder.h"
@implementation CSTimelineEntry
@synthesize user_id;
@synthesize timeline_type;
@synthesize post_id;
@synthesize post_type;
@synthesize comment_id;
@synthesize action;
@synthesize creation_date;
@synthesize description;
@synthesize detail;
+ (NSString*)identifierKey
{
return @"user_timelines";
}
- (id)initWithCoder:(NSCoder *)decoder
{
self = [super initWithCoder:decoder];
user_id = [decoder decodeIntForKey:@"user_id"];
timeline_type = (enum CSTimelineType)[decoder decodeIntForKey:@"timeline_type"];
post_id = [decoder decodeIntForKey:@"post_id"];
post_type = [decoder decodeIntForKey:@"post_type"];
comment_id = [decoder decodeIntForKey:@"comment_id"];
action = [[decoder decodeObjectForKey:@"action"] retain];
creation_date = [[decoder decodeObjectForKey:@"creation_date"] retain];
description = [[decoder decodeObjectForKey:@"description"] retain];
detail = [[decoder decodeObjectForKey:@"detail"] retain];
return self;
}
- (void)dealloc
{
[action release];
[creation_date release];
[description release];
[detail release];
[super dealloc];
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[super encodeWithCoder:encoder];
[encoder encodeInt:user_id forKey:@"user_id"];
[encoder encodeInt:timeline_type forKey:@"timeline_type"];
[encoder encodeInt:post_id forKey:@"post_id"];
[encoder encodeInt:post_type forKey:@"post_type"];
[encoder encodeInt:comment_id forKey:@"comment_id"];
[encoder encodeObject:action forKey:@"action"];
[encoder encodeObject:creation_date forKey:@"creation_date"];
[encoder encodeObject:description forKey:@"description"];
[encoder encodeObject:detail forKey:@"detail"];
}
- (BOOL)updateFromJSON:(id)json error:(NSError**)error
{
if (![super updateFromJSON:json error:error])
return FALSE;
[json extract:@"user_id" intoInt:&user_id];
[json extract:@"comment_id" intoInt:&comment_id];
[json extract:@"post_id" intoInt:&post_id];
[json extract:@"description" intoString:&description];
[json extract:@"detail" intoString:&detail];
[json extract:@"action" intoString:&action];
if (![json extract:@"creation_date" intoDate:&creation_date error:error])
return FALSE;
NSString *timelineTypeStr = [json objectForKey:@"timeline_type"];
if ([timelineTypeStr isEqualToString:@"comment"])
timeline_type = CSTimelineTypeComment;
else if ([timelineTypeStr isEqualToString:@"askoranswered"])
timeline_type = CSTimelineTypeAskOrAnswered;
else if ([timelineTypeStr isEqualToString:@"badge"])
timeline_type = CSTimelineTypeBadge;
else if ([timelineTypeStr isEqualToString:@"revision"])
timeline_type = CSTimelineTypeRevision;
else if ([timelineTypeStr isEqualToString:@"accepted"])
timeline_type = CSTimelineTypeAccepted;
else
timeline_type = CSTimelineTypeUnknown;
NSString *postTypeStr = [json objectForKey:@"post_type"];
if ([postTypeStr isEqualToString:@"question"])
post_type = CSPostTypeQuestion;
else if ([postTypeStr isEqualToString:@"answer"])
post_type = CSPostTypeAnswer;
else
post_type = CSPostTypeUnknown;
return TRUE;
}
@end