PageRenderTime 24ms CodeModel.GetById 10ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/ApiTestAppDelegate.m

http://rtm2cocoa.googlecode.com/
Objective C | 102 lines | 78 code | 14 blank | 10 comment | 9 complexity | e711327b11e73aed9a9c57fe5207955d MD5 | raw file
  1//
  2//  ApiTestAppDelegate.m
  3//  ApiTest
  4//
  5//  Created by kkillian on 08/11/2009.
  6//  Copyright 2009 shufflecodebox. All rights reserved.
  7//
  8
  9#import "ApiTestAppDelegate.h"
 10#import "DebugLog.h"
 11
 12@implementation ApiTestAppDelegate
 13
 14@synthesize window;
 15
 16- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
 17	
 18		// You have to insert your ApiKay and Secret
 19	NSString *apikay = @"";
 20	NSString *secret = @"";
 21		// Inizialize the RTMController with the api_key and the sicret code
 22	rtmController = [[NSRTM alloc] initWithApikey:apikay andSicret:secret];
 23	
 24	if([rtmController isRegistrated]) {
 25		NSLog(@"RTM Registred");
 26		[isAuthField setStringValue:@"YES"];
 27		[self getLists:nil];
 28	} else {
 29		NSLog(@"RTM NOT Registred");
 30		[isAuthField setStringValue:@"NO"];
 31		[rtmController authenticate:RTMAuthDelete];
 32	}
 33	
 34}
 35
 36-(IBAction)getLists:(id)sender {
 37	NSMutableArray *lists = [rtmController getFullTaskLists];
 38	NSMutableArray *allTasks = [[NSMutableArray alloc] init];
 39	NSEnumerator * enumerator = [lists objectEnumerator];
 40	NSRTMList *element;	
 41	while(element = [enumerator nextObject])
 42	{
 43		[allTasks removeAllObjects];
 44		if([element isSmart]) {
 45			NSLog(@"FILTER: %@",[element getFilter]);
 46			NSRTMPredicate *predicate = [[NSRTMPredicate alloc] initWithQuery:[element getFilter]];
 47			NSMutableArray *listtaskseries = [rtmController getTaskListWithPredicate:predicate lastSync:nil];
 48			NSEnumerator *enum2 = [listtaskseries objectEnumerator];
 49			NSRTMList *listElem;
 50			while (listElem = [enum2 nextObject]) {
 51				[allTasks addObjectsFromArray:[listElem getTaskseries]];
 52			}
 53			[element setTaskseries:[allTasks copy]];
 54		} else {
 55			[allTasks addObjectsFromArray:[element getTaskseries]];
 56		}
 57	}
 58	
 59	[listArrayController addObjects:lists];
 60}
 61
 62-(IBAction)getTasks:(id)sender {	
 63	NSMutableArray *lists = [rtmController getTaskList];
 64	NSLog(@"Tasks Lists : %@",[lists description]);
 65	NSEnumerator * enumerator = [lists objectEnumerator];
 66	NSRTMList *element;	
 67	while(element = [enumerator nextObject])
 68	{
 69			// Do your thing with the object.
 70		NSMutableArray *taskSeries = [element getTaskseries];
 71		NSLog(@"Tasks Info = %@",[taskSeries description]); 
 72	}
 73}
 74
 75-(IBAction)addNewTask:(id)sender {	
 76	if([[listArrayController selectedObjects] count] > 0) {
 77		NSRTMList *currentList = [[listArrayController selectedObjects] objectAtIndex:0];
 78		NSInteger listid = [[currentList getListId] integerValue];
 79		NSLog(@"Current list id = %d",listid);
 80		NSRTMList *resultList = [rtmController addNewTask:[newtaskField stringValue] atList:listid parse:NO];
 81		NSLog(@"Result List %@",resultList);
 82	} else {
 83		NSLog(@"NOT LIST SELECTED");
 84		[NSApp presentError:[[NSError alloc] initWithDomain:@"NO LIST SELECTE" code:999 userInfo:nil]];
 85	}
 86}
 87
 88-(IBAction)getTaskInfo:(id)sender {
 89	if([[listArrayController selectedObjects] count] > 0) {
 90		NSRTMList *currentList = [[listArrayController selectedObjects] objectAtIndex:0];
 91		NSLog(@"LIST DESK TASKSERIES %@",[[currentList getTaskseries] description]);
 92	}
 93	NSLog(@"TASKARRAY %@",[taskseriesArrayController description]);
 94	if([[taskseriesArrayController arrangedObjects] count] > 0) {
 95		NSRTMTaskseries *taskseries = [[taskseriesArrayController arrangedObjects] objectAtIndex:0];
 96
 97		NSLog(@"TEST: %@",[taskseries getCreated]);
 98		[dateExampleField setStringValue:[[taskseries getCreated] description]];
 99	}
100	
101}
102@end