Skip to content

Commit b81a291

Browse files
committed
- GADriveItem: change type of identifier to OCFileID
- GAEducationClass: update from latest Open API yaml file - OCConnection+Spaces: add new method to update the resources (special items) for a drive with a provided item
1 parent a6408a6 commit b81a291

File tree

6 files changed

+76
-16
lines changed

6 files changed

+76
-16
lines changed

ownCloudSDK/Connection/OCConnection+Spaces.m

+58
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
#import "OCConnection.h"
2020
#import "GADrive.h"
2121
#import "GADriveUpdate.h"
22+
#import "GADriveItem.h"
2223
#import "OCConnection+OData.h"
2324
#import "OCConnection+GraphAPI.h"
25+
#import "OCMacros.h"
26+
#import "NSError+OCError.h"
2427

2528
@implementation OCConnection (Drives)
2629

@@ -121,4 +124,59 @@ - (nullable NSProgress *)updateDrive:(OCDrive *)drive properties:(NSDictionary<O
121124
}]);
122125
}
123126

127+
- (NSProgress *)updateDrive:(OCDrive *)drive resourceFor:(OCDataItemPresentableResource)resource withItem:(nullable OCItem *)item completionHandler:(void(^)(NSError * _Nullable error, OCDrive * _Nullable drive))completionHandler
128+
{
129+
// Compose drive item
130+
GADriveItem *driveItem = [GADriveItem new];
131+
132+
// - set special folder name based on OCDataItemPresentableResource
133+
driveItem.specialFolder = [GASpecialFolder new];
134+
if ([resource isEqual:OCDataItemPresentableResourceCoverImage]) {
135+
driveItem.specialFolder.name = GASpecialFolderNameImage;
136+
} else if ([resource isEqual:OCDataItemPresentableResourceCoverDescription]) {
137+
driveItem.specialFolder.name = GASpecialFolderNameReadme;
138+
} else {
139+
// Unknown/unsupported resource type -> return error
140+
completionHandler(OCError(OCErrorInvalidParameter), nil);
141+
}
142+
143+
// - set item identifier
144+
if (item != nil)
145+
{
146+
// update/set item as driveItem
147+
driveItem.identifier = item.fileID;
148+
}
149+
else
150+
{
151+
// remove item as driveItem
152+
driveItem.identifier = (OCFileID)NSNull.null;
153+
}
154+
155+
// Compose drive update
156+
GADriveUpdate *driveUpdate = [GADriveUpdate new];
157+
driveUpdate.special = @[ driveItem ];
158+
159+
// Encode & send drive update
160+
NSURL *url = [[self URLForEndpoint:OCConnectionEndpointIDGraphDrives options:nil] URLByAppendingPathComponent:drive.identifier];
161+
162+
return ([self updateODataObject:driveUpdate atURL:url requireSignals:[NSSet setWithObject:OCConnectionSignalIDAuthenticationAvailable] parameters:nil responseEntityClass:GADrive.class completionHandler:^(NSError * _Nullable error, id _Nullable response) {
163+
OCDrive *ocDrive = nil;
164+
165+
if (error == nil)
166+
{
167+
// Convert GADrive to OCDrive
168+
GADrive *gaDrive;
169+
170+
if ((gaDrive = OCTypedCast(response, GADrive)) != nil)
171+
{
172+
ocDrive = [OCDrive driveFromGADrive:gaDrive];
173+
}
174+
}
175+
176+
OCLogDebug(@"Drives response: drive=%@, error=%@", ocDrive, error);
177+
178+
completionHandler(error, ocDrive);
179+
}]);
180+
}
181+
124182
@end

ownCloudSDK/Connection/OCConnection.h

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#import "OCDrive.h"
3838
#import "OCAppProviderApp.h"
3939
#import "OCFeatureAvailability.h"
40+
#import "OCDataItemPresentable.h"
4041

4142
@class OCBookmark;
4243
@class OCAuthenticationMethod;
@@ -367,6 +368,7 @@ typedef void(^OCConnectionDriveManagementCompletionHandler)(NSError * _Nullable
367368

368369
#pragma mark - Change attributes
369370
- (nullable NSProgress *)updateDrive:(OCDrive *)drive properties:(NSDictionary<OCDriveProperty, id> *)updateProperties completionHandler:(OCConnectionDriveCompletionHandler)completionHandler;
371+
- (nullable NSProgress *)updateDrive:(OCDrive *)drive resourceFor:(OCDataItemPresentableResource)resource withItem:(nullable OCItem *)item completionHandler:(void(^)(NSError * _Nullable error, OCDrive * _Nullable drive))completionHandler; //!< Updates special items of a drive with the provided item.
370372

371373
@end
372374

ownCloudSDK/GraphAPI/GeneratedTypes/GADriveItem.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//
22
// GADriveItem.h
33
// Autogenerated / Managed by ocapigen
4-
// Copyright (C) 2024 ownCloud GmbH. All rights reserved.
4+
// Copyright (C) 2025 ownCloud GmbH. All rights reserved.
55
//
66

77
/*
8-
* Copyright (C) 2024, ownCloud GmbH.
8+
* Copyright (C) 2025, ownCloud GmbH.
99
*
1010
* This code is covered by the GNU Public License Version 3.
1111
*
@@ -43,8 +43,8 @@
4343
NS_ASSUME_NONNULL_BEGIN
4444
@interface GADriveItem : NSObject <GAGraphObject, NSSecureCoding>
4545

46-
// occgen: type properties { "customPropertyTypes" : { "eTag" : "OCFileETag" }}
47-
@property(strong, nullable) NSString *identifier; //!< Read-only.
46+
// occgen: type properties { "customPropertyTypes" : { "eTag" : "OCFileETag", "identifier" : "OCFileID" }}
47+
@property(strong, nullable) OCFileID identifier; //!< Read-only.
4848
@property(strong, nullable) GAIdentitySet *createdBy; //!< Identity of the user, device, or application which created the item. Read-only.
4949
@property(strong, nullable) NSDate *createdDateTime; //!< [string:date-time] Date and time of item creation. Read-only. | pattern: ^[0-9]{4,}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]{1,12})?([Zz]|[+-][0-9][0-9]:[0-9][0-9])$
5050
@property(strong, nullable) NSString *desc; //!< Provides a user-visible description of the item. Optional.

ownCloudSDK/GraphAPI/GeneratedTypes/GADriveItem.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//
22
// GADriveItem.m
33
// Autogenerated / Managed by ocapigen
4-
// Copyright (C) 2024 ownCloud GmbH. All rights reserved.
4+
// Copyright (C) 2025 ownCloud GmbH. All rights reserved.
55
//
66

77
/*
8-
* Copyright (C) 2024, ownCloud GmbH.
8+
* Copyright (C) 2025, ownCloud GmbH.
99
*
1010
* This code is covered by the GNU Public License Version 3.
1111
*

ownCloudSDK/GraphAPI/GeneratedTypes/GAEducationClass.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//
22
// GAEducationClass.h
33
// Autogenerated / Managed by ocapigen
4-
// Copyright (C) 2024 ownCloud GmbH. All rights reserved.
4+
// Copyright (C) 2025 ownCloud GmbH. All rights reserved.
55
//
66

77
/*
8-
* Copyright (C) 2024, ownCloud GmbH.
8+
* Copyright (C) 2025, ownCloud GmbH.
99
*
1010
* This code is covered by the GNU Public License Version 3.
1111
*
@@ -28,10 +28,10 @@ NS_ASSUME_NONNULL_BEGIN
2828
// occgen: type properties
2929
@property(strong, nullable) NSString *identifier; //!< Read-only.
3030
@property(strong, nullable) NSString *desc; //!< An optional description for the group. Returned by default.
31-
@property(strong) NSString *displayName; //!< The display name for the group. This property is required when a group is created and cannot be cleared during updates. Returned by default. Supports $search and $orderBy.
31+
@property(strong, nullable) NSString *displayName; //!< The display name for the group. This property is required when a group is created and cannot be cleared during updates. Returned by default. Supports $search and $orderBy.
3232
@property(strong, nullable) NSArray<GAUser *> *members; //!< Users and groups that are members of this group. HTTP Methods: GET (supported for all groups), Nullable. Supports $expand.
3333
// @property(strong, nullable) NSArray<NSString *> *[email protected]; //!< A list of member references to the members to be added. Up to 20 members can be added with a single request
34-
@property(strong) NSString *classification; //!< Classification of the group, i.e. "class" or "course"
34+
@property(strong, nullable) NSString *classification; //!< Classification of the group, i.e. "class" or "course"
3535
@property(strong, nullable) NSString *externalId; //!< An external unique ID for the class
3636

3737
// occgen: type protected {"locked":true}

ownCloudSDK/GraphAPI/GeneratedTypes/GAEducationClass.m

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//
22
// GAEducationClass.m
33
// Autogenerated / Managed by ocapigen
4-
// Copyright (C) 2024 ownCloud GmbH. All rights reserved.
4+
// Copyright (C) 2025 ownCloud GmbH. All rights reserved.
55
//
66

77
/*
8-
* Copyright (C) 2024, ownCloud GmbH.
8+
* Copyright (C) 2025, ownCloud GmbH.
99
*
1010
* This code is covered by the GNU Public License Version 3.
1111
*
@@ -28,10 +28,10 @@ + (nullable instancetype)decodeGraphData:(GAGraphData)structure context:(nullabl
2828

2929
GA_MAP(identifier, "id", NSString, Nil);
3030
GA_MAP(desc, "description", NSString, Nil);
31-
GA_SET_REQ(displayName, NSString, Nil);
31+
GA_SET(displayName, NSString, Nil);
3232
GA_SET(members, GAUser, NSArray.class);
3333
// GA_SET([email protected], NSString, NSArray.class);
34-
GA_SET_REQ(classification, NSString, Nil);
34+
GA_SET(classification, NSString, Nil);
3535
GA_SET(externalId, NSString, Nil);
3636

3737
return (instance);
@@ -43,10 +43,10 @@ - (nullable GAGraphStruct)encodeToGraphStructWithContext:(nullable GAGraphContex
4343
GA_ENC_INIT
4444
GA_ENC_ADD(_identifier, "id", NO);
4545
GA_ENC_ADD(_desc, "description", NO);
46-
GA_ENC_ADD(_displayName, "displayName", YES);
46+
GA_ENC_ADD(_displayName, "displayName", NO);
4747
GA_ENC_ADD(_members, "members", NO);
4848
// GA_ENC_ADD([email protected], "[email protected]", NO);
49-
GA_ENC_ADD(_classification, "classification", YES);
49+
GA_ENC_ADD(_classification, "classification", NO);
5050
GA_ENC_ADD(_externalId, "externalId", NO);
5151
GA_ENC_RETURN
5252
}

0 commit comments

Comments
 (0)