From 397cb011a540d53974a87d94a8ff8576e2024b63 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Thu, 11 Sep 2025 12:32:54 +0200 Subject: Add create actions --- QSThingsPlugin/Actions/CreateTaskAction.m | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 QSThingsPlugin/Actions/CreateTaskAction.m (limited to 'QSThingsPlugin/Actions/CreateTaskAction.m') diff --git a/QSThingsPlugin/Actions/CreateTaskAction.m b/QSThingsPlugin/Actions/CreateTaskAction.m new file mode 100644 index 0000000..f11936f --- /dev/null +++ b/QSThingsPlugin/Actions/CreateTaskAction.m @@ -0,0 +1,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 -- cgit