Skip to content
This repository was archived by the owner on Apr 18, 2023. It is now read-only.

Commit d6ed26e

Browse files
author
Vikas Dadheech
committed
Added classes to support Batch Requests and Unit tests for those classes.
1 parent 58b0665 commit d6ed26e

File tree

14 files changed

+808
-0
lines changed

14 files changed

+808
-0
lines changed

MSGraphCoreSDK/MSGraphCoreSDK.xcodeproj/project.pbxproj

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
E5069AD9211C1AD500432372 /* MSGraphCoreSDKTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E5069AD8211C1AD500432372 /* MSGraphCoreSDKTests.m */; };
1313
E5069ADB211C1AD500432372 /* MSGraphCoreSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5DC73DA211412BF0040BAB6 /* MSGraphCoreSDK.framework */; };
1414
E5069AE2211C323D00432372 /* MSURLSessionManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E5069AE1211C323D00432372 /* MSURLSessionManagerTests.m */; };
15+
E5204FEE216F1D9900E64160 /* MSBatchRequestContent.h in Headers */ = {isa = PBXBuildFile; fileRef = E5204FE8216F1D9800E64160 /* MSBatchRequestContent.h */; settings = {ATTRIBUTES = (Public, ); }; };
16+
E5204FEF216F1D9900E64160 /* MSBatchRequestStep.h in Headers */ = {isa = PBXBuildFile; fileRef = E5204FE9216F1D9800E64160 /* MSBatchRequestStep.h */; settings = {ATTRIBUTES = (Public, ); }; };
17+
E5204FF0216F1D9900E64160 /* MSBatchResponseContent.m in Sources */ = {isa = PBXBuildFile; fileRef = E5204FEA216F1D9800E64160 /* MSBatchResponseContent.m */; };
18+
E5204FF1216F1D9900E64160 /* MSBatchRequestContent.m in Sources */ = {isa = PBXBuildFile; fileRef = E5204FEB216F1D9800E64160 /* MSBatchRequestContent.m */; };
19+
E5204FF2216F1D9900E64160 /* MSBatchResponseContent.h in Headers */ = {isa = PBXBuildFile; fileRef = E5204FEC216F1D9900E64160 /* MSBatchResponseContent.h */; settings = {ATTRIBUTES = (Public, ); }; };
20+
E5204FF3216F1D9900E64160 /* MSBatchRequestStep.m in Sources */ = {isa = PBXBuildFile; fileRef = E5204FED216F1D9900E64160 /* MSBatchRequestStep.m */; };
21+
E5204FF7216F371400E64160 /* MSErrorCodes.m in Sources */ = {isa = PBXBuildFile; fileRef = E5204FF5216F371400E64160 /* MSErrorCodes.m */; };
22+
E5204FF8216F371400E64160 /* MSErrorCodes.h in Headers */ = {isa = PBXBuildFile; fileRef = E5204FF6216F371400E64160 /* MSErrorCodes.h */; settings = {ATTRIBUTES = (Public, ); }; };
23+
E5204FFF2173A7C200E64160 /* MSBatchRequestStepTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E5204FFE2173A7C200E64160 /* MSBatchRequestStepTests.m */; };
24+
E52050012173AEA900E64160 /* MSBatchRequestContentTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E52050002173AEA900E64160 /* MSBatchRequestContentTests.m */; };
25+
E52050042174C1DB00E64160 /* MSBatchResponseContentTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E52050032174C1DB00E64160 /* MSBatchResponseContentTests.m */; };
26+
E52050062175B10800E64160 /* BatchResponse.json in Resources */ = {isa = PBXBuildFile; fileRef = E52050052175B10800E64160 /* BatchResponse.json */; };
1527
E52AD978212D27DC005FED47 /* MSURLSessionDataTask.m in Sources */ = {isa = PBXBuildFile; fileRef = E52AD970212D27DB005FED47 /* MSURLSessionDataTask.m */; };
1628
E52AD979212D27DC005FED47 /* MSURLSessionTask.m in Sources */ = {isa = PBXBuildFile; fileRef = E52AD971212D27DB005FED47 /* MSURLSessionTask.m */; };
1729
E52AD97A212D27DC005FED47 /* MSURLSessionUploadTask.h in Headers */ = {isa = PBXBuildFile; fileRef = E52AD972212D27DB005FED47 /* MSURLSessionUploadTask.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -71,6 +83,18 @@
7183
E5069AD8211C1AD500432372 /* MSGraphCoreSDKTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSGraphCoreSDKTests.m; sourceTree = "<group>"; };
7284
E5069ADA211C1AD500432372 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7385
E5069AE1211C323D00432372 /* MSURLSessionManagerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MSURLSessionManagerTests.m; sourceTree = "<group>"; };
86+
E5204FE8216F1D9800E64160 /* MSBatchRequestContent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSBatchRequestContent.h; sourceTree = "<group>"; };
87+
E5204FE9216F1D9800E64160 /* MSBatchRequestStep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSBatchRequestStep.h; sourceTree = "<group>"; };
88+
E5204FEA216F1D9800E64160 /* MSBatchResponseContent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MSBatchResponseContent.m; sourceTree = "<group>"; };
89+
E5204FEB216F1D9800E64160 /* MSBatchRequestContent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MSBatchRequestContent.m; sourceTree = "<group>"; };
90+
E5204FEC216F1D9900E64160 /* MSBatchResponseContent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSBatchResponseContent.h; sourceTree = "<group>"; };
91+
E5204FED216F1D9900E64160 /* MSBatchRequestStep.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MSBatchRequestStep.m; sourceTree = "<group>"; };
92+
E5204FF5216F371400E64160 /* MSErrorCodes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MSErrorCodes.m; sourceTree = "<group>"; };
93+
E5204FF6216F371400E64160 /* MSErrorCodes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSErrorCodes.h; sourceTree = "<group>"; };
94+
E5204FFE2173A7C200E64160 /* MSBatchRequestStepTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSBatchRequestStepTests.m; sourceTree = "<group>"; };
95+
E52050002173AEA900E64160 /* MSBatchRequestContentTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSBatchRequestContentTests.m; sourceTree = "<group>"; };
96+
E52050032174C1DB00E64160 /* MSBatchResponseContentTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSBatchResponseContentTests.m; sourceTree = "<group>"; };
97+
E52050052175B10800E64160 /* BatchResponse.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = BatchResponse.json; sourceTree = "<group>"; };
7498
E52AD970212D27DB005FED47 /* MSURLSessionDataTask.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MSURLSessionDataTask.m; sourceTree = "<group>"; };
7599
E52AD971212D27DB005FED47 /* MSURLSessionTask.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MSURLSessionTask.m; sourceTree = "<group>"; };
76100
E52AD972212D27DB005FED47 /* MSURLSessionUploadTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSURLSessionUploadTask.h; sourceTree = "<group>"; };
@@ -178,13 +202,16 @@
178202
E52AD96F212D271C005FED47 /* Session Tasks */,
179203
E5069AC6211AAEC900432372 /* MSConstants.h */,
180204
E5069AC7211AAEC900432372 /* MSConstants.m */,
205+
E5204FF6216F371400E64160 /* MSErrorCodes.h */,
206+
E5204FF5216F371400E64160 /* MSErrorCodes.m */,
181207
);
182208
path = Common;
183209
sourceTree = "<group>";
184210
};
185211
E5069AD7211C1AD500432372 /* MSGraphCoreSDKTests */ = {
186212
isa = PBXGroup;
187213
children = (
214+
E5204FFC2173A79100E64160 /* GraphContent */,
188215
E5B6DB6921497A3300836E1D /* Frameworks */,
189216
E573EE1121367A4000C5E884 /* HTTPClient */,
190217
E573EE0E2136568700C5E884 /* Resources */,
@@ -198,6 +225,45 @@
198225
path = MSGraphCoreSDKTests;
199226
sourceTree = "<group>";
200227
};
228+
E5204FE6216F1D4200E64160 /* GraphContent */ = {
229+
isa = PBXGroup;
230+
children = (
231+
E5204FE7216F1D7300E64160 /* BatchContent */,
232+
);
233+
path = GraphContent;
234+
sourceTree = "<group>";
235+
};
236+
E5204FE7216F1D7300E64160 /* BatchContent */ = {
237+
isa = PBXGroup;
238+
children = (
239+
E5204FE9216F1D9800E64160 /* MSBatchRequestStep.h */,
240+
E5204FED216F1D9900E64160 /* MSBatchRequestStep.m */,
241+
E5204FE8216F1D9800E64160 /* MSBatchRequestContent.h */,
242+
E5204FEB216F1D9800E64160 /* MSBatchRequestContent.m */,
243+
E5204FEC216F1D9900E64160 /* MSBatchResponseContent.h */,
244+
E5204FEA216F1D9800E64160 /* MSBatchResponseContent.m */,
245+
);
246+
path = BatchContent;
247+
sourceTree = "<group>";
248+
};
249+
E5204FFC2173A79100E64160 /* GraphContent */ = {
250+
isa = PBXGroup;
251+
children = (
252+
E5204FFD2173A79E00E64160 /* BatchContent */,
253+
);
254+
path = GraphContent;
255+
sourceTree = "<group>";
256+
};
257+
E5204FFD2173A79E00E64160 /* BatchContent */ = {
258+
isa = PBXGroup;
259+
children = (
260+
E5204FFE2173A7C200E64160 /* MSBatchRequestStepTests.m */,
261+
E52050002173AEA900E64160 /* MSBatchRequestContentTests.m */,
262+
E52050032174C1DB00E64160 /* MSBatchResponseContentTests.m */,
263+
);
264+
path = BatchContent;
265+
sourceTree = "<group>";
266+
};
201267
E52AD96F212D271C005FED47 /* Session Tasks */ = {
202268
isa = PBXGroup;
203269
children = (
@@ -235,6 +301,7 @@
235301
E573EE0E2136568700C5E884 /* Resources */ = {
236302
isa = PBXGroup;
237303
children = (
304+
E52050052175B10800E64160 /* BatchResponse.json */,
238305
E573EE0F2136569F00C5E884 /* UserPhoto.jpg */,
239306
);
240307
path = Resources;
@@ -319,6 +386,7 @@
319386
E5DC73DD211412BF0040BAB6 /* MSGraphCoreSDK.h */,
320387
E5069AC2211AACB600432372 /* Authentication */,
321388
E5069AC5211AAE6900432372 /* Common */,
389+
E5204FE6216F1D4200E64160 /* GraphContent */,
322390
E5DC73E5211418040040BAB6 /* HTTPClient */,
323391
E5DC73EA211418040040BAB6 /* Middleware */,
324392
E5DC73DE211412BF0040BAB6 /* Info.plist */,
@@ -398,6 +466,10 @@
398466
E52AD97C212D27DC005FED47 /* MSURLSessionDataTask.h in Headers */,
399467
E5DC7406211418050040BAB6 /* MSURLSessionTaskDelegate.h in Headers */,
400468
E5ECE09721427A6400A289C2 /* MSMiddlewareFactory.h in Headers */,
469+
E5204FEE216F1D9900E64160 /* MSBatchRequestContent.h in Headers */,
470+
E5204FF2216F1D9900E64160 /* MSBatchResponseContent.h in Headers */,
471+
E5204FF8216F371400E64160 /* MSErrorCodes.h in Headers */,
472+
E5204FEF216F1D9900E64160 /* MSBatchRequestStep.h in Headers */,
401473
E5ECE0A42146657900A289C2 /* MSRedirectHandler.h in Headers */,
402474
E5DC73DF211412BF0040BAB6 /* MSGraphCoreSDK.h in Headers */,
403475
);
@@ -485,6 +557,7 @@
485557
buildActionMask = 2147483647;
486558
files = (
487559
E573EE102136569F00C5E884 /* UserPhoto.jpg in Resources */,
560+
E52050062175B10800E64160 /* BatchResponse.json in Resources */,
488561
);
489562
runOnlyForDeploymentPostprocessing = 0;
490563
};
@@ -502,7 +575,10 @@
502575
isa = PBXSourcesBuildPhase;
503576
buildActionMask = 2147483647;
504577
files = (
578+
E52050012173AEA900E64160 /* MSBatchRequestContentTests.m in Sources */,
505579
E573EE0D213525BA00C5E884 /* MSGraphWorkloadsTests.m in Sources */,
580+
E5204FFF2173A7C200E64160 /* MSBatchRequestStepTests.m in Sources */,
581+
E52050042174C1DB00E64160 /* MSBatchResponseContentTests.m in Sources */,
506582
E573EE072133FFF200C5E884 /* MSHTTPClientTests.m in Sources */,
507583
E52AD9E6212E8845005FED47 /* MSGraphCoreSDKTests.h in Sources */,
508584
E56678302150E1AF00C6B7AE /* MSAuthenticationHandlerTests.m in Sources */,
@@ -523,13 +599,17 @@
523599
isa = PBXSourcesBuildPhase;
524600
buildActionMask = 2147483647;
525601
files = (
602+
E5204FF1216F1D9900E64160 /* MSBatchRequestContent.m in Sources */,
603+
E5204FF7216F371400E64160 /* MSErrorCodes.m in Sources */,
526604
E5DC741A21142C430040BAB6 /* MSClientFactory.m in Sources */,
527605
E5069AC9211AAEC900432372 /* MSConstants.m in Sources */,
528606
E5ECE0A52146657900A289C2 /* MSRedirectHandler.m in Sources */,
529607
E5ECE09821427A6400A289C2 /* MSMiddlewareFactory.m in Sources */,
530608
E52AD97F212D27DC005FED47 /* MSURLSessionDownloadTask.m in Sources */,
609+
E5204FF3216F1D9900E64160 /* MSBatchRequestStep.m in Sources */,
531610
E5DC7405211418050040BAB6 /* MSURLSessionManager.m in Sources */,
532611
E52AD979212D27DC005FED47 /* MSURLSessionTask.m in Sources */,
612+
E5204FF0216F1D9900E64160 /* MSBatchResponseContent.m in Sources */,
533613
E5DC7408211418050040BAB6 /* MSURLSessionTaskDelegate.m in Sources */,
534614
E52AD97E212D27DC005FED47 /* MSURLSessionUploadTask.m in Sources */,
535615
E52AD978212D27DC005FED47 /* MSURLSessionDataTask.m in Sources */,
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
3+
//
4+
5+
#import <Foundation/Foundation.h>
6+
7+
#ifndef MSErrorCodes_h
8+
#define MSErrorCodes_h
9+
10+
11+
typedef NS_ENUM(NSInteger, MSErrorCode)
12+
{
13+
MSErrorCodeEmptyRequestId = -62300,
14+
MSErrorCodeNonUniqueRequestId = -62301,
15+
MSErrorCodeMaximumLimitReached = -62302,
16+
MSErrorCodeRequestIdNotAvailable = -62303
17+
};
18+
19+
extern NSString *const MSErrorStringEmptyRequestIdDescription;
20+
extern NSString *const MSErrorStringEmptyRequestIdReason;
21+
22+
extern NSString *const MSErrorStringNonUniqueRequestIdDescription;
23+
extern NSString *const MSErrorStringNonUniqueRequestIdReason;
24+
25+
extern NSString *const MSErrorStringMaximumBatchStepLimitReachedDescription;
26+
extern NSString *const MSErrorStringMaximumBatchStepLimitReachedReason;
27+
28+
extern NSString *const MSErrorStringRequestIdNotAvailableDescription;
29+
extern NSString *const MSErrorStringRequestIdNotAvailableReason;
30+
31+
#endif
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
3+
//
4+
5+
#import "MSErrorCodes.h"
6+
7+
NSString *const MSErrorStringEmptyRequestIdDescription = @"Empty id for request";
8+
NSString *const MSErrorStringEmptyRequestIdReason = @"Id for a request is empty, Please provide a unique id.";
9+
10+
NSString *const MSErrorStringNonUniqueRequestIdDescription = @"Duplicate RequestId Error";
11+
NSString *const MSErrorStringNonUniqueRequestIdReason = @"Couldn't add request with duplicate id %@, Make the id of requests unique.";
12+
13+
NSString *const MSErrorStringMaximumBatchStepLimitReachedDescription = @"Limit Exceeded Error";
14+
NSString *const MSErrorStringMaximumBatchStepLimitReachedReason = @"Maximum requests limit exceeded, Max allowed number of requests are %ld";
15+
16+
NSString *const MSErrorStringRequestIdNotAvailableDescription = @"Request id not found";
17+
NSString *const MSErrorStringRequestIdNotAvailableReason = @"Request id %@ is not present.";
18+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
3+
//
4+
5+
#import <Foundation/Foundation.h>
6+
7+
@class MSBatchRequestStep;
8+
9+
/*
10+
To make batch requests, all the individual request needs to be clubbed in one single request body. This class provides mechanism to create that content for batch requests.
11+
Maximum limit of MSBatchRequestSteps in one single MSBatchRequestContent is set to 20.
12+
*/
13+
@interface MSBatchRequestContent : NSObject
14+
15+
/*
16+
Creates and returns an instance of MSBatchRequestContent
17+
@param batchRequestStepsArray Array of batch request steps with unique ids.
18+
@param error If any error is encountered during the initalization, it will be assigned to this address.
19+
@return The MSBatchRequestContent object containng the Batch Request Steps.
20+
*/
21+
- (instancetype)initWithRequests:(NSArray<MSBatchRequestStep *> *)batchRequestStepsArray error:(NSError **)error;
22+
23+
/*
24+
Adds an MSBatchRequestStep object to MSBatchRequestContent object
25+
@param batchRequestStep The object which needs to be added.
26+
@param error If any error is encountered while adding a batch request step, it will be assigned to this address.
27+
*/
28+
- (void)addBatchRequestStep:(MSBatchRequestStep *)batchRequestStep error:(NSError **)error;
29+
30+
/*
31+
Removes an MSBatchRequestStep object from MSBatchRequestContent object
32+
@param requestId Id of the MSBatchRequestStep which should be removed.
33+
@param error If any error is encountered during the removal of a batch request step, it will be assigned to this address.
34+
*/
35+
- (void)removeBatchRequesStepWithId:(NSString *)requestId error:(NSError **)error;
36+
37+
/*
38+
Creates and returns a dictionary object which is created by clubbing all the individual batch request step into a format recognised by Microsoft Graph server.
39+
@return A dictionary object.
40+
*/
41+
- (NSMutableDictionary *)getBatchRequestContent;
42+
43+
@end
44+

0 commit comments

Comments
 (0)