aboutsummaryrefslogtreecommitdiff
path: root/QSThingsPlugin/Actions/CreateTaskAction.m
blob: f11936f8d43682d449d0dc5b1652f6498a19e0cd (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
#import "CreateTaskAction.h"

NS_ASSUME_NONNULL_BEGIN

@implementation CreateTaskAction

- (QSObject *)createTask:(QSObject *)directObject
{
  NSString *contents = [directObject displayName];
  if (contents) {
    NSDictionary *parameters = [TextParsingHelper parseText: contents];
      [ThingsHelper callRoute:ThingsURLRouteAdd withParameters:parameters];
  } else {
    NSLog(@"Could not get the text of the Things object.");
  }
  return directObject;
}

- (QSObject *)createTask:(QSObject *)directObject in:(QSObject *)indirectObject
{
  NSString *contents = [directObject displayName];
  
  NSDictionary *indirectContents = [indirectObject objectForType:indirectObject.primaryType];
  NSString *listId = nil;
  if (indirectContents) {
    listId = [indirectContents objectForKey:@"uuid"];
  } else {
    NSLog(@"Could not read the contents for the indirect object");
  }
  
  if (contents) {
    NSMutableDictionary *parameters = [TextParsingHelper parseText: contents];
    if (listId) {
      [parameters setObject:listId forKey:@"list-id"];
    } else {
      NSLog(@"Could not find a list id");
    }
    [ThingsHelper callRoute:ThingsURLRouteAdd withParameters:parameters];
  } else {
    NSLog(@"Could not get the text of the Things object.");
  }
  return directObject;
}

@end

NS_ASSUME_NONNULL_END