aboutsummaryrefslogtreecommitdiff
path: root/QSThingsPlugin/Actions/CreateProjectAction.m
blob: 38a0a5f9d06c5db09dfa238a3373254e337c5581 (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 "CreateProjectAction.h"

NS_ASSUME_NONNULL_BEGIN

@implementation CreateProjectAction

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

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

@end

NS_ASSUME_NONNULL_END