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