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

NS_ASSUME_NONNULL_BEGIN

@implementation CompleteTaskAction

- (QSObject *)completeTask:(QSObject *)directObject
{
  NSSet *validTypes = [NSSet setWithObjects:kProjectType, kTaskType, nil];
  NSString *authenticationKey = [KeychainHelper authenticationKey];
  
  if (!authenticationKey) {
    NSLog(@"There is no authentication key.");
  }

  if (authenticationKey && [validTypes containsObject:directObject.primaryType]) {
    NSDictionary *contents = [directObject objectForType:directObject.primaryType];
    NSString *path = @"update";
    if (directObject.primaryType == kProjectType) {
      path = @"update-project";
    }
    if (contents) {
      NSString *uuid = [contents objectForKey:@"uuid"];
      if (uuid) {
        NSString *urlString = [NSString stringWithFormat:@"things:///%@?id=%@&auth-token=%@&completed=true", path, uuid, authenticationKey];
        NSURL *url = [NSURL URLWithString:urlString];
                
        [[NSWorkspace sharedWorkspace] openURL:url];
      } else {
        NSLog(@"Things object did not have a uuid.");
      }
    } else {
      NSLog(@"Could not get the contents of the Things object.");
    }
  }
  return directObject;
}

@end

NS_ASSUME_NONNULL_END