summaryrefslogtreecommitdiffstats
path: root/Classes/Source.m
blob: bde21b0c7ea00a068fcd1f8fdada56415460bf88 (plain)
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
//
//  Source.m
//  PicCast
//
//  Created by Matthew Handler on 4/25/11.
//  Copyright 2011 Earl Industries. All rights reserved.
//

#import "Source.h"
#import "FMDatabase.h"
#import "FMResultSet.h"

@implementation Source

@synthesize title, foreignId, subscribed, category, favicon;

//+ (Topic *) initFromDatabaseRow:(FMResultSet *)result {
//	NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
//    [dateFormatter setDateStyle:NSDateFormatterLongStyle];
//    [dateFormatter setTimeStyle:NSDateFormatterNoStyle];
//    [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"US"] autorelease]];
//	
//	Topic *topic = [[[Topic alloc] init] autorelease];
//	
//	topic.guid = [result stringForColumn:@"link"];
//	topic.title = [result stringForColumn:@"title"];
//	topic.iconUrl = [result stringForColumn:@"iconUrl"];
//	topic.description = [result stringForColumn:@"description"];
//	topic.releaseDate = [Topic stringToDate:[result stringForColumn:@"releaseDate"]];
//	topic.category = [result stringForColumn:@"category"];
//	topic.picCount = [result intForColumn:@"picCount"];
//	
//	return topic;
//}

+ (Source *) initFromDatabaseRow:(FMResultSet *)result {
	
	Source *source = [[[Source alloc] init] autorelease];
	
	source.title = [result stringForColumn:@"title"];
	source.foreignId = [NSNumber numberWithInt:[result intForColumn:@"foreignId"]];
	source.subscribed = [result intForColumn:@"subscribed"] == 0 ? false : true;
	source.category = [result stringForColumn:@"category"];
	source.favicon = [result stringForColumn:@"favicon"];
	
	return source;
}

+ (Source *) initWithJsonObject:(NSDictionary *)obj {
	
	Source *source = [[[Source alloc] init] autorelease];
	
	//NSDictionary *info = [obj objectForKey:@"fields"];
	source.favicon = [NSString stringWithFormat:@"http://www.%@.com/favicon.ico", [obj objectForKey:@"shortname"]]; //[obj objectForKey:@"favicon"];
	source.title = [obj objectForKey:@"title"];
	source.foreignId = [obj objectForKey:@"id"];
	source.subscribed = false;
	source.category = [obj objectForKey:@"category"];
	
	return source;
}

- (void) serializeToDb:(FMDatabase *)db {
	[db retain];
	
	[db executeUpdate:@"INSERT INTO subscribedSources \
	 (foreignId, title, subscribed, category, favicon) \
	 VALUES \
	 (?, ?, ?, ?, ?);",
	 foreignId, title, [NSNumber numberWithInt:(subscribed ? 1 : 0)], category, favicon];
	
	[db release];	
}

@end