Skip to content

Commit 44002fd

Browse files
committed
- OCConnection+Spaces: add support for creating spaces from templates
- OCDrive: add new type OCDriveTemplate and a default template value
1 parent aa5547d commit 44002fd

File tree

6 files changed

+23
-8
lines changed

6 files changed

+23
-8
lines changed

ownCloudSDK/Connection/OCConnection+Spaces.m

+13-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
#import "OCConnection+GraphAPI.h"
2525
#import "OCMacros.h"
2626
#import "NSError+OCError.h"
27+
#import "NSURL+OCURLQueryParameterExtensions.h"
2728

2829
@implementation OCConnection (Drives)
2930

3031
#pragma mark - Creation
31-
- (nullable NSProgress *)createDriveWithName:(NSString *)name description:(nullable NSString *)description quota:(nullable NSNumber *)quotaBytes completionHandler:(OCConnectionDriveCompletionHandler)completionHandler
32+
- (nullable NSProgress *)createDriveWithName:(NSString *)name description:(nullable NSString *)description quota:(nullable NSNumber *)quotaBytes template:(nullable OCDriveTemplate)templateName completionHandler:(OCConnectionDriveCompletionHandler)completionHandler
3233
{
3334
GADrive *drive = [GADrive new];
3435
drive.name = name;
@@ -41,8 +42,16 @@ - (nullable NSProgress *)createDriveWithName:(NSString *)name description:(nulla
4142
drive.quota = quota;
4243
}
4344

44-
return ([self createODataObject:drive atURL:[self URLForEndpoint:OCConnectionEndpointIDGraphDrives options:nil] requireSignals:[NSSet setWithObject:OCConnectionSignalIDAuthenticationAvailable] parameters:nil responseEntityClass:Nil completionHandler:^(NSError * _Nullable error, id _Nullable response) {
45-
NSLog(@"New space: %@", response);
45+
NSURL *creationURL = [self URLForEndpoint:OCConnectionEndpointIDGraphDrives options:nil];
46+
if (templateName != nil)
47+
{
48+
creationURL = [creationURL urlByAppendingQueryParameters:@{
49+
@"template" : templateName
50+
} replaceExisting:NO];
51+
}
52+
53+
return ([self createODataObject:drive atURL:creationURL requireSignals:[NSSet setWithObject:OCConnectionSignalIDAuthenticationAvailable] parameters:nil responseEntityClass:Nil completionHandler:^(NSError * _Nullable error, id _Nullable response) {
54+
OCLogDebug(@"New space: %@", response);
4655
completionHandler(error, (response != nil) ? [OCDrive driveFromGADrive:(GADrive *)response] : nil);
4756
}]);
4857
}
@@ -119,7 +128,7 @@ - (nullable NSProgress *)updateDrive:(OCDrive *)drive properties:(NSDictionary<O
119128
}
120129

121130
return ([self updateODataObject:gaDriveUpdate atURL:[[self URLForEndpoint:OCConnectionEndpointIDGraphDrives options:nil] URLByAppendingPathComponent:drive.identifier] requireSignals:[NSSet setWithObject:OCConnectionSignalIDAuthenticationAvailable] parameters:nil responseEntityClass:GADrive.class completionHandler:^(NSError * _Nullable error, id _Nullable response) {
122-
NSLog(@"Updated space: %@", response);
131+
OCLogDebug(@"Updated space: %@", response);
123132
completionHandler(error, (response != nil) ? [OCDrive driveFromGADrive:(GADrive *)response] : nil);
124133
}]);
125134
}

ownCloudSDK/Connection/OCConnection.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ typedef void(^OCConnectionDriveManagementCompletionHandler)(NSError * _Nullable
359359
@interface OCConnection (Drives)
360360

361361
#pragma mark - Creation
362-
- (nullable NSProgress *)createDriveWithName:(NSString *)name description:(nullable NSString *)description quota:(nullable NSNumber *)quotaBytes completionHandler:(OCConnectionDriveCompletionHandler)completionHandler;
362+
- (nullable NSProgress *)createDriveWithName:(NSString *)name description:(nullable NSString *)description quota:(nullable NSNumber *)quotaBytes template:(nullable OCDriveTemplate)templateName completionHandler:(OCConnectionDriveCompletionHandler)completionHandler;
363363

364364
#pragma mark - Disable/Restore/Delete
365365
- (nullable NSProgress *)disableDrive:(OCDrive *)drive completionHandler:(OCConnectionDriveManagementCompletionHandler)completionHandler;

ownCloudSDK/Core/DriveManagement/OCCore+DriveManagement.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
@implementation OCCore (DriveManagement)
2828

2929
// Creation
30-
- (nullable NSProgress *)createDriveWithName:(NSString *)name description:(nullable NSString *)description quota:(nullable NSNumber *)quotaBytes completionHandler:(OCCoreDriveCompletionHandler)completionHandler
30+
- (nullable NSProgress *)createDriveWithName:(NSString *)name description:(nullable NSString *)description quota:(nullable NSNumber *)quotaBytes template:(nullable OCDriveTemplate)template completionHandler:(OCCoreDriveCompletionHandler)completionHandler
3131
{
32-
return ([self.connection createDriveWithName:name description:description quota:quotaBytes completionHandler:^(NSError * _Nullable error, OCDrive * _Nullable newDrive) {
32+
return ([self.connection createDriveWithName:name description:description quota:quotaBytes template:template completionHandler:^(NSError * _Nullable error, OCDrive * _Nullable newDrive) {
3333
if (error == nil) {
3434
[self fetchUpdatesWithCompletionHandler:nil];
3535
}

ownCloudSDK/Core/OCCore.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ typedef void(^OCCoreShareRoleRetrievalHandler)(NSError * _Nullable error, NSArra
516516
@interface OCCore (DriveManagement)
517517

518518
// Creation
519-
- (nullable NSProgress *)createDriveWithName:(NSString *)name description:(nullable NSString *)description quota:(nullable NSNumber *)quotaBytes completionHandler:(OCCoreDriveCompletionHandler)completionHandler;
519+
- (nullable NSProgress *)createDriveWithName:(NSString *)name description:(nullable NSString *)description quota:(nullable NSNumber *)quotaBytes template:(nullable OCDriveTemplate)templateName completionHandler:(OCCoreDriveCompletionHandler)completionHandler;
520520

521521
// Disable/Restore/Delete
522522
- (nullable NSProgress *)disableDrive:(OCDrive *)drive completionHandler:(OCCoreCompletionHandler)completionHandler;

ownCloudSDK/Drive/OCDrive.h

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ typedef NSString* OCDriveSpecialType NS_TYPED_ENUM;
3535

3636
typedef NSString* OCDriveProperty NS_TYPED_ENUM;
3737

38+
typedef NSString* OCDriveTemplate NS_TYPED_ENUM;
39+
3840
typedef NSString* OCDriveResource NS_TYPED_ENUM;
3941

4042
typedef NS_ENUM(NSInteger, OCDriveDetachedState)
@@ -102,6 +104,8 @@ extern OCDriveProperty OCDrivePropertyQuotaTotal; //!< The quota total of / spac
102104

103105
extern OCDriveID OCDriveIDSharesJail; //!< The static UUID of the Shares Jail
104106

107+
extern OCDriveTemplate OCDriveTemplateDefault; //!< The default template
108+
105109
extern OCDriveResource OCDriveResourceCoverImage; //!< The cover image of a drive/space
106110
extern OCDriveResource OCDriveResourceCoverDescription; //!< The MD description of a drive/space
107111
extern OCDriveResource OCDriveResourceSpaceFolder; //!< The folder typically used to store a drive's/space's cover image and/or MD description.

ownCloudSDK/Drive/OCDrive.m

+2
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ - (NSString *)description
309309
OCDriveProperty OCDrivePropertyDescription = @"desc"; // Must correspond to GADriveUpdate key path
310310
OCDriveProperty OCDrivePropertyQuotaTotal = @"quota.total"; // Must correspond to GADriveUpdate key path
311311

312+
OCDriveTemplate OCDriveTemplateDefault = @"default";
313+
312314
OCDriveResource OCDriveResourceCoverImage = @"image";
313315
OCDriveResource OCDriveResourceCoverDescription = @"description";
314316
OCDriveResource OCDriveResourceSpaceFolder = @"space-folder";

0 commit comments

Comments
 (0)