/NSRTM.m

http://rtm2cocoa.googlecode.com/ · Objective C · 1245 lines · 1037 code · 113 blank · 95 comment · 156 complexity · 4a41a6d2240d2d842158c5325753a7f5 MD5 · raw file

  1. /*
  2. * NSRTM.m
  3. * RTMApiTest
  4. *
  5. * Created by kkillian on 17/11/09.
  6. * Copyright 2009 shufflecodebox. All rights reserved.
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. /**
  22. * NSRTM is the main class of the Cocoa2RTM framework
  23. * Usage:
  24. * User Authentication
  25. * Generate a frob code
  26. * With the frob code generate a auth process and allow application in the user account. This process will generate a token code
  27. * Request the token code.
  28. * Now you are ready to work with RTM
  29. */
  30. #import "NSRTM.h"
  31. #import "DebugLog.h"
  32. #import "NSRTMMethod.h"
  33. #import "NSRTMInvoker.h"
  34. #import "NSRTMService.h"
  35. #import "NSRTMController.h"
  36. #import "NSRTMTagCriteria.h"
  37. #import "NSRTMParamsCriteria.h"
  38. // AUTH METHODS
  39. #define RTM_AUTH_checkToken @"rtm.auth.checkToken"
  40. #define RTM_AUTH_getFrob @"rtm.auth.getFrob"
  41. #define RTM_AUTH_getToken @"rtm.auth.getToken"
  42. // CONTACTS METHOD
  43. #define RTM_CONTACTS_add @"rtm.contacts.add"
  44. #define RTM_CONTACTS_delete @"rtm.contacts.delete"
  45. #define RTM_CONTACTS_getList @"rtm.contacts.getList"
  46. // GROUP METHODS
  47. #define RTM_GROUPS_add @"rtm.groups.add"
  48. #define RTM_GROUPS_addContact @"rtm.groups.addContact"
  49. #define RTM_GROUPS_delete @"rtm.groups.delete"
  50. #define RTM_GROUPS_getList @"rtm.groups.getList"
  51. #define RTM_GROUPS_removeContact @"rtm.groups.removeContact"
  52. //LISTS METHODS
  53. #define RTM_LISTS_add @"rtm.lists.add"
  54. #define RTM_LISTS_archive @"rtm.lists.archive"
  55. #define RTM_LISTS_delete @"rtm.lists.delete"
  56. #define RTM_LISTS_getList @"rtm.lists.getList"
  57. #define RTM_LISTS_setDefaultList @"rtm.lists.setDefaultList"
  58. #define RTM_LISTS_setName @"rtm.lists.setName"
  59. #define RTM_LISTS_unarchive @"rtm.lists.unarchive"
  60. // LOCATION METHOD
  61. #define RTM_LOCATIONS_getList @"rtm.locations.getList"
  62. // REFLECTION METHOD
  63. #define RTM_REFLECTION_getMethodInfo @"rtm.reflection.getMethodInfo"
  64. #define RTM_REFLECTION_getMethods @"rtm.reflection.getMethods"
  65. // SETTINGS METHOD
  66. #define RTM_SETTINGS_getList @"rtm.settings.getList"
  67. // TASKS METHODS
  68. #define RTM_TASKS_add @"rtm.tasks.add"
  69. #define RTM_TASKS_addTags @"rtm.tasks.addTags"
  70. #define RTM_TASKS_complete @"rtm.tasks.complete"
  71. #define RTM_TASKS_delete @"rtm.tasks.delete"
  72. #define RTM_TASKS_getList @"rtm.tasks.getList"
  73. #define RTM_TASKS_movePriority @"rtm.tasks.movePriority"
  74. #define RTM_TASKS_moveTo @"rtm.tasks.moveTo"
  75. #define RTM_TASKS_notes_add @"rtm.tasks.notes.add"
  76. #define RTM_TASKS_notes_delete @"rtm.tasks.notes.delete"
  77. #define RTM_TASKS_notes_edit @"rtm.tasks.notes.edit"
  78. #define RTM_TASKS_postpone @"rtm.tasks.postpone"
  79. #define RTM_TASKS_removeTags @"rtm.tasks.removeTags"
  80. #define RTM_TASKS_setDueDate @"rtm.tasks.setDueDate"
  81. #define RTM_TASKS_seEstimate @"rtm.tasks.setEstimate"
  82. #define RTM_TASKS_setLocation @"rtm.tasks.setLocation"
  83. #define RTM_TASKS_setName @"rtm.tasks.setName"
  84. #define RTM_TASKS_setPriority @"rtm.tasks.setPriority"
  85. #define RTM_TASKS_setRecurrence @"rtm.tasks.setRecurrence"
  86. #define RTM_TASKS_setTags @"rtm.tasks.setTags"
  87. #define RTM_TASKS_setURL @"rtm.tasks.setURL"
  88. #define RTM_TASKS_uncomplete @"rtm.tasks.uncomplete"
  89. // NOTE METHODS
  90. #define RTM_NOTE_add @"rtm.tasks.notes.add"
  91. #define RTM_NOTE_delete @"rtm.tasks.notes.delete"
  92. #define RTM_NOTE_edit @"rtm.tasks.note.edit"
  93. // TEST METHODS
  94. #define RTM_TEST_echo @"rtm.test.echo"
  95. #define RTM_TEST_login @"rtm.test.login"
  96. // TIME METHODS
  97. #define RTM_TIME_convert @"rtm.time.convert"
  98. #define RTM_TIME_parse @"rtm.time.parse"
  99. // OTHERS
  100. #define RTM_TIMELINES_create @"rtm.timelines.create"
  101. #define RTM_TIMEZONES_getList @"rtm.timezones.getList"
  102. #define RTM_TRANSACTIONS_undo @"rtm.transactions.undo"
  103. #define RTMPrefSavedToken @"rtm.cocoa.token.pref"
  104. #define RTMPrefSavedFrob @"rtm.cocoa.frob.pref"
  105. @implementation NSRTM
  106. /**
  107. * Inizialize the RTM controller
  108. * @param apikey the apikey for all the methos
  109. * @param sicretvalue the sicret given with the apikey
  110. */
  111. #pragma mark Inizialize
  112. -(id)initWithApikey:(NSString *)apikey andSicret:(NSString *)sicretvalue {
  113. self = [super init];
  114. if(![self loadMyNibFile]) {
  115. NSException *exception = [NSException exceptionWithName:@"ComponenteException" reason:@"Unable to load the bundle" userInfo:nil];
  116. @throw exception;
  117. }
  118. if (self != nil) {
  119. api_key = apikey;
  120. sicret = sicretvalue;
  121. if(api_key != nil && sicret != nil) {
  122. mainInvoker = [[NSRTMInvoker alloc] initWithApiKey:api_key andSicret:sicret];
  123. if(mainInvoker != nil) {
  124. mainService = [[NSRTMService alloc] initWithInvoker:mainInvoker];
  125. }
  126. }
  127. defaults = [NSUserDefaults standardUserDefaults];
  128. if([defaults stringForKey:RTMPrefSavedToken] != NULL) {
  129. token = [defaults stringForKey:RTMPrefSavedToken];
  130. }
  131. } else {
  132. NSException *exception = [NSException exceptionWithName:@"InitException" reason:@"apikey and sicretValue can't be nil" userInfo:nil];
  133. @throw exception;
  134. }
  135. return self;
  136. }
  137. - (BOOL)loadMyNibFile {
  138. // The myNib file must be in the bundle that defines self's class.
  139. dialogController = [[NSRTMController alloc] init];
  140. [dialogController setDelegate:self];
  141. if (![NSBundle loadNibNamed:@"rtm" owner:dialogController]) {
  142. DLog(@"Warning! Could not load myNib file.\n");
  143. return NO;
  144. }
  145. return YES;
  146. }
  147. -(void)dealloc {
  148. [mainInvoker release];
  149. [mainService release];
  150. [dialogController release];
  151. [super dealloc];
  152. }
  153. #pragma mark -
  154. #pragma mark Delegate
  155. -(void)setDelegate:(id)val {
  156. rtmDelegate = val;
  157. }
  158. -(id)delegate {
  159. return rtmDelegate;
  160. }
  161. - (void)manageError:(NSRTMError *)error {
  162. if ([rtmDelegate respondsToSelector:@selector(manageRTMError:)]) {
  163. [rtmDelegate manageRTMError:error];
  164. } else {
  165. [NSApp presentError:error];
  166. // [NSException raise:NSInternalInconsistencyException format:@"Delegate doesn't respond to manageRTMError"];
  167. }
  168. }
  169. #pragma mark -
  170. #pragma mark Extra
  171. /*
  172. -(NSMutableArray *)getAllTasks {
  173. NSMutableArray *tasks = [[NSMutableArray alloc] init];
  174. NSMutableArray *fullists = [self getTaskList];
  175. NSEnumerator * enumerator = [fullists objectEnumerator];
  176. NSRTMList *element;
  177. while(element = [enumerator nextObject])
  178. {
  179. [tasks addObjectsFromArray:[element getTaskseries]];
  180. }
  181. return tasks;
  182. }*/
  183. -(NSMutableArray *)getFullTaskLists {
  184. NSMutableArray *lists = [self getLists];
  185. if(lists != nil && [lists count] > 0) {
  186. NSMutableArray *fullists = [self getTaskList];
  187. NSEnumerator * enumerator = [lists objectEnumerator];
  188. NSRTMList *element;
  189. while(element = [enumerator nextObject])
  190. {
  191. NSInteger foundIndex = [fullists indexOfObject:element];
  192. if(foundIndex != NSNotFound) {
  193. NSRTMList *fullList = [fullists objectAtIndex:foundIndex];
  194. [element setTaskseries:[fullList getTaskseries]];
  195. }
  196. }
  197. }
  198. return lists;
  199. }
  200. -(NSMutableArray *)getFullTaskLists:(BOOL)completed {
  201. NSMutableArray *lists = [self getLists];
  202. if(lists != nil && [lists count] > 0) {
  203. NSMutableArray *fullists = [self getTaskList];
  204. NSEnumerator * enumerator = [lists objectEnumerator];
  205. NSRTMList *element;
  206. while(element = [enumerator nextObject])
  207. {
  208. NSInteger foundIndex = [fullists indexOfObject:element];
  209. if(foundIndex != NSNotFound) {
  210. NSRTMList *fullList = [fullists objectAtIndex:foundIndex];
  211. NSMutableArray *taskseries = [fullList getTaskseries:completed];
  212. [element setTaskseries:taskseries];
  213. }
  214. }
  215. }
  216. return lists;
  217. }
  218. -(NSMutableArray *)getFullTaskLists2:(BOOL)completed {
  219. NSMutableArray *lists = [self getLists];
  220. if(lists != nil && [lists count] > 0) {
  221. NSRTMParamsCriteria *paramCriteria = [NSRTMParamsCriteria criteriaWithStatus:NSRTMTaskStatusInCompleted];
  222. NSRTMPredicate *predicate = [[NSRTMPredicate alloc] initPredicateWithCriteria:paramCriteria];
  223. DLog(@"%@ %d",[predicate formattedPredicate],[predicate getCriteriaCount]);
  224. NSEnumerator * enumerator = [lists objectEnumerator];
  225. NSRTMList *element;
  226. while(element = [enumerator nextObject])
  227. {
  228. NSRTMList *listtaskseries = [self getTaskListWithId:[[element getListId] intValue] filter:predicate lastSync:nil];
  229. DLog(@"%@",[listtaskseries description]);
  230. [element setTaskseries:[listtaskseries getTaskseries]];
  231. }
  232. }
  233. // NSRTMTagCriteria *tagCriteria = [NSRTMTagCriteria criteriaWithTagConteins:@"@"];
  234. //DLog(@"%@",[tagCriteria getFormattedCriteria]);
  235. return lists;
  236. }
  237. #pragma mark -
  238. #pragma mark MainMethods
  239. /**
  240. * Method can be called without authenticate
  241. * return a list of all the available api methods
  242. * @return NSRTMResponse
  243. */
  244. -(NSRTMResponse *)getMethods {
  245. NSRTMError *error = nil;
  246. NSMutableArray *params = [[NSMutableArray alloc] init];
  247. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_REFLECTION_getMethods]];
  248. if([mainService execute:params error:&error]) {
  249. return [mainService getResponse];
  250. } else {
  251. [self manageError:error];
  252. return nil;
  253. }
  254. }
  255. #pragma mark -
  256. #pragma mark Authenticate
  257. -(BOOL)isRegistrated {
  258. BOOL isRegistrated = NO;
  259. if([defaults stringForKey:RTMPrefSavedToken] != NULL) {
  260. token = [defaults stringForKey:RTMPrefSavedToken];
  261. if([self checkToken]) {
  262. isRegistrated = YES;
  263. } else {
  264. [defaults removeObjectForKey:RTMPrefSavedToken];
  265. }
  266. }
  267. return isRegistrated;
  268. }
  269. /**
  270. * This method generate the process for the authentication
  271. * @param level the level of authentication
  272. * @see generateFrob
  273. */
  274. -(void)authenticate:(NSString *)level {
  275. [dialogController openDialog:self];
  276. levelAuth = level;
  277. }
  278. -(void)authenticateSelf {
  279. frob = [self generateFrob];
  280. DLog(@"My Frob: %@",frob);
  281. NSMutableArray *params = [[NSMutableArray alloc] init];
  282. [params addObject:[[NSRTMParam alloc] initWithKey:@"perms" value:levelAuth]];
  283. [params addObject:[[NSRTMParam alloc] initWithKey:@"frob" value:frob]];
  284. [mainService auth:params];
  285. }
  286. /**
  287. * Generate Frob
  288. * with this method send a request for generate frob string
  289. * @return NSRTMResponse
  290. */
  291. -(NSString *)generateFrob {
  292. NSRTMError *error = nil;
  293. NSMutableArray *params = [[NSMutableArray alloc] init];
  294. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_AUTH_getFrob]];
  295. NSRTMResponse *response = [mainService execute:params error:&error];
  296. if (error) {
  297. [self manageError:error];
  298. return nil;
  299. } else {
  300. return [response getFrob];
  301. }
  302. }
  303. /**
  304. * Generate the auth token
  305. */
  306. -(NSString *)getToken {
  307. NSRTMError *error = nil;
  308. if(frob != NULL) {
  309. NSMutableArray *params = [[NSMutableArray alloc] init];
  310. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_AUTH_getToken]];
  311. [params addObject:[[NSRTMParam alloc] initWithKey:@"frob" value:frob]];
  312. NSRTMResponse *response = [mainService execute:params error:&error];
  313. if(error) {
  314. [self manageError:error];
  315. return nil;
  316. } else {
  317. return [[response getAuth] getToken];
  318. }
  319. } else {
  320. return nil;
  321. }
  322. }
  323. /**
  324. * Check the auth token
  325. */
  326. -(BOOL)checkToken {
  327. NSRTMError *error = nil;
  328. NSMutableArray *params = [[NSMutableArray alloc] init];
  329. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_AUTH_checkToken]];
  330. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  331. [mainService execute:params error:&error];
  332. if(error) {
  333. [self manageError:error];
  334. return NO;
  335. } else {
  336. return YES;
  337. }
  338. }
  339. /**
  340. * This method save the auth token in the preferencies
  341. */
  342. -(BOOL)saveToken {
  343. BOOL isSaved = NO;
  344. if(frob != NULL) {
  345. NSString *theToken = [self getToken];
  346. DLog(@"theToken: %@",theToken);
  347. if(theToken != NULL) {
  348. [defaults setObject:theToken forKey:RTMPrefSavedToken];
  349. isSaved = YES;
  350. }
  351. }
  352. return isSaved;
  353. }
  354. #pragma mark -
  355. #pragma mark Methos
  356. /**
  357. * Test method can be called without any api key
  358. * if you send some parameters it will respont with an acho of that parameters
  359. * @param params the listo of parameters to sent in the interface request
  360. * @return NSRTMResponse
  361. */
  362. -(NSString *)testEcho:(NSMutableArray *)params {
  363. NSRTMError *error = nil;
  364. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TEST_echo]];
  365. NSRTMResponse *response = [mainService execute:params error:&error];
  366. if(error) {
  367. [self manageError:error];
  368. return nil;
  369. } else {
  370. return [response description];
  371. }
  372. }
  373. #pragma mark -
  374. #pragma mark MethodsContacts
  375. -(NSString *)addContact:(NSString *)contact {
  376. NSRTMError *error = nil;
  377. NSMutableArray *params = [[NSMutableArray alloc] init];
  378. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_CONTACTS_add]];
  379. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  380. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  381. [params addObject:[[NSRTMParam alloc] initWithKey:@"contact" value:contact]];
  382. NSRTMResponse *response = [mainService execute:params error:&error];
  383. if(error) {
  384. [self manageError:error];
  385. return nil;
  386. } else {
  387. return [[response getContact] getContact_id];
  388. }
  389. }
  390. -(BOOL)deleteContact:(NSString *)contactId {
  391. NSRTMError *error = nil;
  392. NSMutableArray *params = [[NSMutableArray alloc] init];
  393. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_CONTACTS_delete]];
  394. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  395. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  396. [params addObject:[[NSRTMParam alloc] initWithKey:@"contact_id" value:contactId]];
  397. [mainService execute:params error:&error];
  398. if(error) {
  399. [self manageError:error];
  400. return NO;
  401. } else {
  402. return YES;
  403. }
  404. }
  405. -(NSMutableArray *)getContactsList {
  406. NSRTMError *error = nil;
  407. NSMutableArray *params = [[NSMutableArray alloc] init];
  408. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_CONTACTS_getList]];
  409. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  410. NSRTMResponse *response = [mainService execute:params error:&error];
  411. if(error) {
  412. [self manageError:error];
  413. return nil;
  414. } else {
  415. return [response getContacts];
  416. }
  417. }
  418. #pragma mark -
  419. #pragma mark Timeline
  420. -(NSString *)createTimeline {
  421. NSRTMError *error = nil;
  422. NSString *timelineString = nil;
  423. NSMutableArray *params = [[NSMutableArray alloc] init];
  424. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TIMELINES_create]];
  425. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  426. NSRTMResponse *response = [mainService execute:params error:&error];
  427. if(error) {
  428. [self manageError:error];
  429. return nil;
  430. } else {
  431. NSRTMTimeline *timeline = [response getTimeline];
  432. timelineString = [NSString stringWithString:[timeline getValue]];
  433. lastTimeline = timelineString;
  434. }
  435. return timelineString;
  436. }
  437. -(NSString *)getLastTimeline {
  438. return lastTimeline;
  439. }
  440. -(BOOL)undo:(NSString *)transactionid {
  441. NSRTMError *error = nil;
  442. NSMutableArray *params = [[NSMutableArray alloc] init];
  443. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TRANSACTIONS_undo]];
  444. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  445. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:lastTimeline]];
  446. [params addObject:[[NSRTMParam alloc] initWithKey:@"transaction_id" value:transactionid]];
  447. [mainService execute:params error:&error];
  448. if(error) {
  449. [self manageError:error];
  450. return NO;
  451. } else {
  452. return YES;
  453. }
  454. }
  455. #pragma mark -
  456. #pragma mark ListMethods
  457. -(NSRTMList *)addList:(NSString *)name filter:(NSRTMPredicate *)predicate {
  458. NSRTMError *error = nil;
  459. NSMutableArray *params = [[NSMutableArray alloc] init];
  460. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_LISTS_add]];
  461. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  462. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  463. [params addObject:[[NSRTMParam alloc] initWithKey:@"name" value:name]];
  464. [params addObject:[[NSRTMParam alloc] initWithKey:@"filter" value:[predicate formattedPredicate]]];
  465. NSRTMResponse *response = [mainService execute:params error:&error];
  466. if(error) {
  467. [self manageError:error];
  468. return nil;
  469. } else {
  470. return [response getList];
  471. }
  472. }
  473. -(BOOL)archiveList:(NSInteger)listId {
  474. NSRTMError *error = nil;
  475. NSMutableArray *params = [[NSMutableArray alloc] init];
  476. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_LISTS_archive]];
  477. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  478. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  479. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[[NSNumber numberWithInteger:listId] stringValue]]];
  480. [mainService execute:params error:&error];
  481. if(error) {
  482. [self manageError:error];
  483. return NO;
  484. } else {
  485. return YES;
  486. }
  487. }
  488. -(BOOL)unarchiveList:(NSInteger)listId{
  489. NSRTMError *error = nil;
  490. NSMutableArray *params = [[NSMutableArray alloc] init];
  491. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_LISTS_unarchive]];
  492. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  493. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  494. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[[NSNumber numberWithInteger:listId] stringValue]]];
  495. [mainService execute:params error:&error];
  496. if(error) {
  497. [self manageError:error];
  498. return NO;
  499. } else {
  500. return YES;
  501. }
  502. }
  503. -(BOOL)deleteList:(NSInteger)listId{
  504. NSRTMError *error = nil;
  505. NSMutableArray *params = [[NSMutableArray alloc] init];
  506. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_LISTS_delete]];
  507. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  508. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  509. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[[NSNumber numberWithInteger:listId] stringValue]]];
  510. [mainService execute:params error:&error];
  511. if(error) {
  512. [self manageError:error];
  513. return NO;
  514. } else {
  515. return YES;
  516. }
  517. }
  518. -(NSMutableArray *)getLists{
  519. NSRTMError *error = nil;
  520. NSMutableArray *params = [[NSMutableArray alloc] init];
  521. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_LISTS_getList]];
  522. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  523. NSRTMResponse *response = [mainService execute:params error:&error];
  524. if(error) {
  525. [self manageError:error];
  526. return nil;
  527. } else {
  528. return [response getLists];
  529. }
  530. }
  531. -(BOOL)setDefaultList:(NSInteger)listId{
  532. NSRTMError *error = nil;
  533. NSMutableArray *params = [[NSMutableArray alloc] init];
  534. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_LISTS_setDefaultList]];
  535. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  536. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  537. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[[NSNumber numberWithInteger:listId] stringValue]]];
  538. [mainService execute:params error:&error];
  539. if(error) {
  540. [self manageError:error];
  541. return NO;
  542. } else {
  543. return YES;
  544. }
  545. }
  546. -(NSRTMList *)setListName:(NSString *)name withId:(NSInteger)listId{
  547. NSRTMError *error = nil;
  548. NSMutableArray *params = [[NSMutableArray alloc] init];
  549. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_LISTS_delete]];
  550. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  551. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  552. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[[NSNumber numberWithInteger:listId] stringValue]]];
  553. [params addObject:[[NSRTMParam alloc] initWithKey:@"name" value:name]];
  554. NSRTMResponse *response = [mainService execute:params error:&error];
  555. if(error) {
  556. [self manageError:error];
  557. return nil;
  558. } else {
  559. return [response getList];
  560. }
  561. }
  562. #pragma mark -
  563. #pragma mark LocationMethods
  564. -(NSMutableArray *)getLocationsList {
  565. NSRTMError *error = nil;
  566. NSMutableArray *params = [[NSMutableArray alloc] init];
  567. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_LOCATIONS_getList]];
  568. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  569. NSRTMResponse *response = [mainService execute:params error:&error];
  570. if(error) {
  571. [self manageError:error];
  572. return nil;
  573. } else {
  574. return [response getLocations];
  575. }
  576. }
  577. -(NSRTMSettings *)getSettingsList {
  578. NSRTMError *error = nil;
  579. NSMutableArray *params = [[NSMutableArray alloc] init];
  580. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_SETTINGS_getList]];
  581. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  582. NSRTMResponse *response = [mainService execute:params error:&error];
  583. if(error) {
  584. [self manageError:error];
  585. return nil;
  586. } else {
  587. return [response getSettings];
  588. }
  589. }
  590. -(NSMutableArray *)getTinmezones {
  591. NSRTMError *error = nil;
  592. NSMutableArray *params = [[NSMutableArray alloc] init];
  593. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TIMEZONES_getList]];
  594. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  595. NSRTMResponse *response = [mainService execute:params error:&error];
  596. if(error) {
  597. [self manageError:error];
  598. return nil;
  599. } else {
  600. return [response getTimezones];
  601. }
  602. }
  603. #pragma mark -
  604. -(NSRTMList *)addNewTask:(NSString *)name atList:(NSInteger)listId parse:(BOOL)option {
  605. NSRTMError *error = nil;
  606. NSMutableArray *params = [[NSMutableArray alloc] init];
  607. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_add]];
  608. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  609. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  610. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[[NSNumber numberWithInteger:listId] stringValue]]];
  611. [params addObject:[[NSRTMParam alloc] initWithKey:@"name" value:name]];
  612. if(option) [params addObject:[[NSRTMParam alloc] initWithKey:@"parse" value:@"1"]];
  613. NSRTMResponse *response = [mainService execute:params error:&error];
  614. if(error) {
  615. [self manageError:error];
  616. return nil;
  617. } else {
  618. return [response getList];
  619. }
  620. }
  621. -(NSRTMList *)addTags:(NSMutableArray *)tags withLocator:(NSRTMLocator *)locator{
  622. NSRTMError *error = nil;
  623. NSMutableArray *params = [[NSMutableArray alloc] init];
  624. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_add]];
  625. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  626. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  627. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  628. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  629. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  630. [params addObject:[[NSRTMParam alloc] initWithKey:@"tags" value:[tags componentsJoinedByString:@","]]];
  631. NSRTMResponse *response = [mainService execute:params error:&error];
  632. if(error) {
  633. [self manageError:error];
  634. return nil;
  635. } else {
  636. return [response getList];
  637. }
  638. }
  639. -(NSRTMList *)completeTask:(NSRTMLocator *)locator{
  640. NSRTMError *error = nil;
  641. NSMutableArray *params = [[NSMutableArray alloc] init];
  642. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_complete]];
  643. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  644. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  645. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  646. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  647. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  648. NSRTMResponse *response = [mainService execute:params error:&error];
  649. if(error) {
  650. [self manageError:error];
  651. return nil;
  652. } else {
  653. return [response getList];
  654. }
  655. }
  656. -(NSRTMList *)deleteTask:(NSRTMLocator *)locator {
  657. NSRTMError *error = nil;
  658. NSMutableArray *params = [[NSMutableArray alloc] init];
  659. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_delete]];
  660. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  661. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  662. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  663. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  664. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  665. NSRTMResponse *response = [mainService execute:params error:&error];
  666. if(error) {
  667. [self manageError:error];
  668. return nil;
  669. } else {
  670. return [response getList];
  671. }
  672. }
  673. -(NSMutableArray *)getTaskList {
  674. NSRTMError *error = nil;
  675. NSMutableArray *params = [[NSMutableArray alloc] init];
  676. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_getList]];
  677. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  678. NSRTMResponse *response = [mainService execute:params error:&error];
  679. if(error) {
  680. [self manageError:error];
  681. return nil;
  682. } else {
  683. return [response getListsTasks];
  684. }
  685. }
  686. -(NSMutableArray *)getTaskListWithId:(NSInteger)listId {
  687. NSRTMError *error = nil;
  688. NSMutableArray *params = [[NSMutableArray alloc] init];
  689. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_getList]];
  690. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  691. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[[NSNumber numberWithInteger:listId] stringValue]]];
  692. NSRTMResponse *response = [mainService execute:params error:&error];
  693. if(error) {
  694. [self manageError:error];
  695. return nil;
  696. } else {
  697. return [response getListsTasks];
  698. }
  699. }
  700. -(NSRTMList *)getTaskListWithId:(NSInteger)listId filter:(NSRTMPredicate *)predicate lastSync:(NSDate *)time {
  701. NSRTMError *error = nil;
  702. NSMutableArray *params = [[NSMutableArray alloc] init];
  703. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_getList]];
  704. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  705. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[[NSNumber numberWithInteger:listId] stringValue]]];
  706. if(predicate != nil) {
  707. [params addObject:[[NSRTMParam alloc] initWithKey:@"filter" value:[predicate formattedPredicate]]];
  708. }
  709. if(time != nil) {
  710. [params addObject:[[NSRTMParam alloc] initWithKey:@"last_sync" value:[time description]]];
  711. }
  712. NSRTMResponse *response = [mainService execute:params error:&error];
  713. if(error) {
  714. [self manageError:error];
  715. return nil;
  716. } else {
  717. if ([[response getListsTasks] count] > 0) {
  718. return (NSRTMList*)[[response getListsTasks] objectAtIndex:0];
  719. } else {
  720. return nil;
  721. }
  722. }
  723. }
  724. -(NSMutableArray *)getTaskListWithPredicate:(NSRTMPredicate *)predicate lastSync:(NSDate *)time {
  725. NSRTMError *error = nil;
  726. NSMutableArray *params = [[NSMutableArray alloc] init];
  727. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_getList]];
  728. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  729. if(predicate != nil) {
  730. [params addObject:[[NSRTMParam alloc] initWithKey:@"filter" value:[predicate formattedPredicate]]];
  731. }
  732. if(time != nil) {
  733. [params addObject:[[NSRTMParam alloc] initWithKey:@"last_sync" value:[time description]]];
  734. }
  735. NSRTMResponse *response = [mainService execute:params error:&error];
  736. if(error) {
  737. [self manageError:error];
  738. return nil;
  739. } else {
  740. if ([[response getListsTasks] count] > 0) {
  741. return [response getListsTasks];
  742. } else {
  743. return nil;
  744. }
  745. }
  746. }
  747. -(NSRTMList *)movePriority:(NSRTMPriorityDirection)direction withLocator:(NSRTMLocator *)locator{
  748. NSRTMError *error = nil;
  749. NSMutableArray *params = [[NSMutableArray alloc] init];
  750. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_movePriority]];
  751. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  752. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  753. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  754. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  755. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  756. if(direction == NSRTMDirectionUp) {
  757. [params addObject:[[NSRTMParam alloc] initWithKey:@"direction" value:@"up"]];
  758. } else {
  759. [params addObject:[[NSRTMParam alloc] initWithKey:@"direction" value:@"down"]];
  760. }
  761. NSRTMResponse *response = [mainService execute:params error:&error];
  762. if(error) {
  763. [self manageError:error];
  764. return nil;
  765. } else {
  766. return [response getList];
  767. }
  768. }
  769. -(NSRTMList *)moveToList:(NSInteger)fromId withLocator:(NSRTMLocator *)locator{
  770. NSRTMError *error = nil;
  771. NSMutableArray *params = [[NSMutableArray alloc] init];
  772. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_moveTo]];
  773. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  774. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  775. [params addObject:[[NSRTMParam alloc] initWithKey:@"to_list_id" value:[locator getListId]]];
  776. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  777. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  778. [params addObject:[[NSRTMParam alloc] initWithKey:@"from_task_id" value:[[NSNumber numberWithInt:fromId] stringValue]]];
  779. NSRTMResponse *response = [mainService execute:params error:&error];
  780. if(error) {
  781. [self manageError:error];
  782. return nil;
  783. } else {
  784. return [response getList];
  785. }
  786. }
  787. -(NSRTMList *)posponeTask:(NSRTMLocator *)locator{
  788. NSRTMError *error = nil;
  789. NSMutableArray *params = [[NSMutableArray alloc] init];
  790. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_postpone]];
  791. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  792. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  793. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  794. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  795. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  796. NSRTMResponse *response = [mainService execute:params error:&error];
  797. if(error) {
  798. [self manageError:error];
  799. return nil;
  800. } else {
  801. return [response getList];
  802. }
  803. }
  804. -(NSRTMList *)removeTags:(NSMutableArray *)tags withLocator:(NSRTMLocator *)locator{
  805. NSRTMError *error = nil;
  806. NSMutableArray *params = [[NSMutableArray alloc] init];
  807. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_removeTags]];
  808. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  809. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  810. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  811. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  812. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  813. [params addObject:[[NSRTMParam alloc] initWithKey:@"tags" value:[tags componentsJoinedByString:@","]]];
  814. NSRTMResponse *response = [mainService execute:params error:&error];
  815. if(error) {
  816. [self manageError:error];
  817. return nil;
  818. } else {
  819. return [response getList];
  820. }
  821. }
  822. #pragma mark Dasistemare
  823. -(NSRTMList *)setDueDate:(NSDate *)date withLocator:(NSRTMLocator *)locator{
  824. NSRTMError *error = nil;
  825. NSMutableArray *params = [[NSMutableArray alloc] init];
  826. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_setDueDate]];
  827. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  828. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  829. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  830. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  831. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  832. [params addObject:[[NSRTMParam alloc] initWithKey:@"due" value:[date description]]];
  833. NSRTMResponse *response = [mainService execute:params error:&error];
  834. if(error) {
  835. [self manageError:error];
  836. return nil;
  837. } else {
  838. return [response getList];
  839. }
  840. }
  841. -(NSRTMList *)setDueDateWithString:(NSString *)date withLocator:(NSRTMLocator *)locator{
  842. NSRTMError *error = nil;
  843. NSMutableArray *params = [[NSMutableArray alloc] init];
  844. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_setDueDate]];
  845. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  846. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  847. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  848. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  849. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  850. [params addObject:[[NSRTMParam alloc] initWithKey:@"due" value:date]];
  851. NSRTMResponse *response = [mainService execute:params error:&error];
  852. if(error) {
  853. [self manageError:error];
  854. return nil;
  855. } else {
  856. return [response getList];
  857. }
  858. }
  859. -(NSRTMList *)removeDueDate:(NSRTMLocator *)locator{
  860. NSRTMError *error = nil;
  861. NSMutableArray *params = [[NSMutableArray alloc] init];
  862. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_setDueDate]];
  863. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  864. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  865. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  866. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  867. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  868. // [params addObject:[[NSRTMParam alloc] initWithKey:@"due" value:date]];
  869. NSRTMResponse *response = [mainService execute:params error:&error];
  870. if(error) {
  871. [self manageError:error];
  872. return nil;
  873. } else {
  874. return [response getList];
  875. }
  876. }
  877. #pragma mark -
  878. -(NSRTMList *)setEstimate:(NSInteger)time withLocator:(NSRTMLocator *)locator{
  879. NSRTMError *error = nil;
  880. NSMutableArray *params = [[NSMutableArray alloc] init];
  881. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_seEstimate]];
  882. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  883. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  884. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  885. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  886. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  887. [params addObject:[[NSRTMParam alloc] initWithKey:@"estimate" value:[[NSNumber numberWithInt:time] stringValue]]];
  888. NSRTMResponse *response = [mainService execute:params error:&error];
  889. if(error) {
  890. [self manageError:error];
  891. return nil;
  892. } else {
  893. return [response getList];
  894. }
  895. }
  896. -(NSRTMList *)removeEstimate:(NSRTMLocator *)locator{
  897. NSRTMError *error = nil;
  898. NSMutableArray *params = [[NSMutableArray alloc] init];
  899. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_seEstimate]];
  900. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  901. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  902. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  903. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  904. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  905. // [params addObject:[[NSRTMParam alloc] initWithKey:@"estimate" value:[[NSNumber numberWithInt:time] stringValue]]];
  906. NSRTMResponse *response = [mainService execute:params error:&error];
  907. if(error) {
  908. [self manageError:error];
  909. return nil;
  910. } else {
  911. return [response getList];
  912. }
  913. }
  914. -(NSRTMList *)setLocation:(NSRTMLocation *)location withLocator:(NSRTMLocator *)locator{
  915. NSRTMError *error = nil;
  916. NSMutableArray *params = [[NSMutableArray alloc] init];
  917. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_setLocation]];
  918. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  919. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  920. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  921. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  922. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  923. [params addObject:[[NSRTMParam alloc] initWithKey:@"location_id" value:[location getLocationId]]];
  924. NSRTMResponse *response = [mainService execute:params error:&error];
  925. if(error) {
  926. [self manageError:error];
  927. return nil;
  928. } else {
  929. return [response getList];
  930. }
  931. }
  932. -(NSRTMList *)setName:(NSString *)name withLocator:(NSRTMLocator *)locator{
  933. NSRTMError *error = nil;
  934. NSMutableArray *params = [[NSMutableArray alloc] init];
  935. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_setName]];
  936. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  937. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  938. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  939. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  940. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  941. [params addObject:[[NSRTMParam alloc] initWithKey:@"name" value:name]];
  942. NSRTMResponse *response = [mainService execute:params error:&error];
  943. if(error) {
  944. [self manageError:error];
  945. return nil;
  946. } else {
  947. return [response getList];
  948. }
  949. }
  950. -(NSRTMList *)setPriority:(NSRTMPriority)priority withLocator:(NSRTMLocator *)locator{
  951. NSRTMError *error = nil;
  952. NSMutableArray *params = [[NSMutableArray alloc] init];
  953. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_setPriority]];
  954. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  955. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  956. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  957. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  958. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  959. if(priority == NSRTMPriorityN) {
  960. [params addObject:[[NSRTMParam alloc] initWithKey:@"priority" value:@"N"]];
  961. } else {
  962. [params addObject:[[NSRTMParam alloc] initWithKey:@"priority" value:[[NSNumber numberWithInt:priority] stringValue]]];
  963. }
  964. NSRTMResponse *response = [mainService execute:params error:&error];
  965. if(error) {
  966. [self manageError:error];
  967. return nil;
  968. } else {
  969. return [response getList];
  970. }
  971. }
  972. -(NSRTMList *)removePriority:(NSRTMLocator *)locator{
  973. NSRTMError *error = nil;
  974. NSMutableArray *params = [[NSMutableArray alloc] init];
  975. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_setPriority]];
  976. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  977. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  978. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  979. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  980. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  981. NSRTMResponse *response = [mainService execute:params error:&error];
  982. if(error) {
  983. [self manageError:error];
  984. return nil;
  985. } else {
  986. return [response getList];
  987. }
  988. }
  989. -(NSRTMList *)setRecurrence:(NSRTMRecurrence *)recurrence withLocator:(NSRTMLocator *)locator{
  990. NSRTMError *error = nil;
  991. NSMutableArray *params = [[NSMutableArray alloc] init];
  992. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_setRecurrence]];
  993. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  994. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  995. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  996. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  997. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  998. [params addObject:[[NSRTMParam alloc] initWithKey:@"repeat" value:[recurrence getPeriod]]];
  999. NSRTMResponse *response = [mainService execute:params error:&error];
  1000. if(error) {
  1001. [self manageError:error];
  1002. return nil;
  1003. } else {
  1004. return [response getList];
  1005. }
  1006. }
  1007. -(NSRTMList *)setTags:(NSMutableArray *)tags withLocator:(NSRTMLocator *)locator{
  1008. NSRTMError *error = nil;
  1009. NSMutableArray *params = [[NSMutableArray alloc] init];
  1010. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_setTags]];
  1011. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  1012. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  1013. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  1014. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  1015. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  1016. [params addObject:[[NSRTMParam alloc] initWithKey:@"tags" value:[tags componentsJoinedByString:@","]]];
  1017. NSRTMResponse *response = [mainService execute:params error:&error];
  1018. if(error) {
  1019. [self manageError:error];
  1020. return nil;
  1021. } else {
  1022. return [response getList];
  1023. }
  1024. }
  1025. -(NSRTMList *)setUrl:(NSURL *)url withLocator:(NSRTMLocator *)locator{
  1026. NSRTMError *error = nil;
  1027. NSMutableArray *params = [[NSMutableArray alloc] init];
  1028. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_setURL]];
  1029. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  1030. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  1031. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  1032. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  1033. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  1034. [params addObject:[[NSRTMParam alloc] initWithKey:@"url" value:[url host]]];
  1035. NSRTMResponse *response = [mainService execute:params error:&error];
  1036. if(error) {
  1037. [self manageError:error];
  1038. return nil;
  1039. } else {
  1040. return [response getList];
  1041. }
  1042. }
  1043. -(NSRTMList *)removeUrl:(NSRTMLocator *)locator{
  1044. NSRTMError *error = nil;
  1045. NSMutableArray *params = [[NSMutableArray alloc] init];
  1046. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_setURL]];
  1047. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  1048. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  1049. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  1050. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  1051. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  1052. NSRTMResponse *response = [mainService execute:params error:&error];
  1053. if(error) {
  1054. [self manageError:error];
  1055. return nil;
  1056. } else {
  1057. return [response getList];
  1058. }
  1059. }
  1060. -(NSRTMList *)uncompleteTask:(NSRTMLocator *)locator{
  1061. NSRTMError *error = nil;
  1062. NSMutableArray *params = [[NSMutableArray alloc] init];
  1063. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_TASKS_uncomplete]];
  1064. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  1065. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  1066. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  1067. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  1068. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  1069. NSRTMResponse *response = [mainService execute:params error:&error];
  1070. if(error) {
  1071. [self manageError:error];
  1072. return nil;
  1073. } else {
  1074. return [response getList];
  1075. }
  1076. }
  1077. #pragma mark -
  1078. #pragma mark NoteMethods
  1079. -(NSRTMNote *)addNoteWithTitle:(NSString *)title andText:(NSString *)text withLocator:(NSRTMLocator *)locator{
  1080. NSRTMError *error = nil;
  1081. NSMutableArray *params = [[NSMutableArray alloc] init];
  1082. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_NOTE_add]];
  1083. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  1084. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  1085. [params addObject:[[NSRTMParam alloc] initWithKey:@"list_id" value:[locator getListId]]];
  1086. [params addObject:[[NSRTMParam alloc] initWithKey:@"taskseries_id" value:[locator getTaskSeriesId]]];
  1087. [params addObject:[[NSRTMParam alloc] initWithKey:@"task_id" value:[locator getTaskId]]];
  1088. [params addObject:[[NSRTMParam alloc] initWithKey:@"note_title" value:title]];
  1089. [params addObject:[[NSRTMParam alloc] initWithKey:@"note_text" value:text]];
  1090. NSRTMResponse *response = [mainService execute:params error:&error];
  1091. if(error) {
  1092. [self manageError:error];
  1093. return nil;
  1094. } else {
  1095. return [response getNote];
  1096. }
  1097. }
  1098. -(BOOL)removeNote:(NSInteger)noteId{
  1099. NSRTMError *error = nil;
  1100. NSMutableArray *params = [[NSMutableArray alloc] init];
  1101. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_NOTE_delete]];
  1102. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  1103. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  1104. [params addObject:[[NSRTMParam alloc] initWithKey:@"note_id" value:[[NSNumber numberWithInt:noteId] stringValue]]];
  1105. [mainService execute:params error:&error];
  1106. if(error) {
  1107. [self manageError:error];
  1108. return NO;
  1109. } else {
  1110. return YES;
  1111. }
  1112. }
  1113. -(NSRTMNote *)editNote:(NSInteger)noteId title:(NSString *)titlevalue andText:(NSString *)text{
  1114. NSRTMError *error = nil;
  1115. NSMutableArray *params = [[NSMutableArray alloc] init];
  1116. [params addObject:[[NSRTMMethod alloc] initWithMethod:RTM_NOTE_edit]];
  1117. [params addObject:[[NSRTMParam alloc] initWithKey:@"auth_token" value:token]];
  1118. [params addObject:[[NSRTMParam alloc] initWithKey:@"timeline" value:[self createTimeline]]];
  1119. [params addObject:[[NSRTMParam alloc] initWithKey:@"note_id" value:[[NSNumber numberWithInt:noteId] stringValue]]];
  1120. [params addObject:[[NSRTMParam alloc] initWithKey:@"note_title" value:titlevalue]];
  1121. [params addObject:[[NSRTMParam alloc] initWithKey:@"note_text" value:text]];
  1122. NSRTMResponse *response = [mainService execute:params error:&error];
  1123. if(error) {
  1124. [self manageError:error];
  1125. return nil;
  1126. } else {
  1127. return [response getNote];
  1128. }
  1129. }
  1130. #pragma mark -
  1131. @end