// // 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