-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MXServiceTerms: Add this class to support MSC2140 (Terms of Service A…
…PI for Identity Servers and Integration Managers) element-hq/element-ios#2600
- Loading branch information
Showing
10 changed files
with
340 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
MatrixSDK/NotificationCenter/ServiceTerms/MXServiceTerms.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
Copyright 2019 The Matrix.org Foundation C.I.C | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import "MXHTTPOperation.h" | ||
#import "MXLoginTerms.h" | ||
#import "MXSession.h" | ||
|
||
/** | ||
Services around Matrix. | ||
*/ | ||
typedef enum : NSUInteger | ||
{ | ||
// An Identity Service | ||
MXServiceTypeIdentityService = 0, | ||
|
||
// An Integration Manager | ||
MXServiceTypeIntegrationManager | ||
} MXServiceType; | ||
|
||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface MXServiceTerms : NSObject | ||
|
||
- (instancetype)initWithBaseUrl:(NSString*)baseUrl serviceType:(MXServiceType)serviceType matrixSession:(nullable MXSession *)mxSession accessToken:(nullable NSString *)accessToken; | ||
|
||
@property (nonatomic, readonly) NSString *baseUrl; | ||
@property (nonatomic, readonly) MXServiceType serviceType; | ||
|
||
/** | ||
Get all terms of the service. | ||
@param success A block object called when the operation succeeds. | ||
@param failure A block object called when the operation fails. | ||
@return a MXHTTPOperation instance. | ||
*/ | ||
- (MXHTTPOperation*)terms:(void (^)(MXLoginTerms * _Nullable terms))success | ||
failure:(nullable void (^)(NSError * _Nonnull))failure; | ||
|
||
/** | ||
Accept terms by their urls. | ||
@param termsUrls urls of the terms documents. | ||
@param mxSession the Matrix session of the user. | ||
@param success A block object called when the operation succeeds. | ||
@param failure A block object called when the operation fails. | ||
@return a MXHTTPOperation instance. | ||
*/ | ||
- (MXHTTPOperation*)agreeToTerms:(NSArray<NSString *> *)termsUrls | ||
success:(void (^)(void))success | ||
failure:(nullable void (^)(NSError * _Nonnull))failure; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
89 changes: 89 additions & 0 deletions
89
MatrixSDK/NotificationCenter/ServiceTerms/MXServiceTerms.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
Copyright 2019 The Matrix.org Foundation C.I.C | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#import "MXServiceTerms.h" | ||
#import "MXServiceTermsRestClient.h" | ||
|
||
#import "MXRestClient.h" | ||
|
||
|
||
NSString *const kMXIntegrationManagerAPIPrefixPathV1 = @"_matrix/integrations/v1"; | ||
|
||
@interface MXServiceTerms() | ||
|
||
@property (nonatomic, strong) MXServiceTermsRestClient *restClient; | ||
@property (nonatomic, nullable) MXSession *mxSession; | ||
@property (nonatomic, nullable) NSString *accessToken; | ||
|
||
@end | ||
|
||
@implementation MXServiceTerms | ||
|
||
- (instancetype)initWithBaseUrl:(NSString*)baseUrl serviceType:(MXServiceType)serviceType matrixSession:(nullable MXSession *)mxSession accessToken:(nullable NSString *)accessToken | ||
{ | ||
self = [super init]; | ||
if (self) | ||
{ | ||
_baseUrl = [baseUrl copy]; | ||
_serviceType = serviceType; | ||
_mxSession = mxSession; | ||
_accessToken = [accessToken copy]; | ||
|
||
_restClient = [[MXServiceTermsRestClient alloc] initWithBaseUrl:self.termsBaseUrl accessToken:accessToken]; | ||
} | ||
return self; | ||
} | ||
|
||
- (MXHTTPOperation*)terms:(void (^)(MXLoginTerms * _Nullable terms))success | ||
failure:(nullable void (^)(NSError * _Nonnull))failure | ||
{ | ||
return [_restClient terms:success failure:failure]; | ||
} | ||
|
||
- (MXHTTPOperation *)agreeToTerms:(NSArray<NSString *> *)termsUrls | ||
success:(void (^)(void))success | ||
failure:(void (^)(NSError * _Nonnull))failure | ||
{ | ||
NSParameterAssert(_mxSession && _accessToken); | ||
|
||
// TODO | ||
failure([[NSError alloc] initWithDomain:@"toto" code:0 userInfo:nil]); | ||
return nil; | ||
} | ||
|
||
#pragma mark - Private methods | ||
|
||
- (NSString*)termsBaseUrl | ||
{ | ||
NSString *termsBaseUrl; | ||
switch (_serviceType) | ||
{ | ||
case MXServiceTypeIdentityService: | ||
termsBaseUrl = [NSString stringWithFormat:@"%@/%@", _baseUrl, kMXIdentityAPIPrefixPathV2]; | ||
break; | ||
|
||
case MXServiceTypeIntegrationManager: | ||
termsBaseUrl = [NSString stringWithFormat:@"%@/%@", _baseUrl, kMXIntegrationManagerAPIPrefixPathV1]; | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
|
||
return termsBaseUrl; | ||
} | ||
|
||
@end |
55 changes: 55 additions & 0 deletions
55
MatrixSDK/NotificationCenter/ServiceTerms/MXServiceTermsRestClient.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
Copyright 2019 The Matrix.org Foundation C.I.C | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import "MXHTTPOperation.h" | ||
#import "MXLoginTerms.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface MXServiceTermsRestClient : NSObject | ||
|
||
- (instancetype)initWithBaseUrl:(NSString*)baseUrl accessToken:(nullable NSString *)accessToken; | ||
|
||
/** | ||
Get all terms of the service. | ||
@param success A block object called when the operation succeeds. | ||
@param failure A block object called when the operation fails. | ||
@return a MXHTTPOperation instance. | ||
*/ | ||
- (MXHTTPOperation*)terms:(void (^)(MXLoginTerms * _Nullable terms))success | ||
failure:(nullable void (^)(NSError * _Nonnull))failure; | ||
|
||
/** | ||
Accept terms by their urls. | ||
@param termsUrls urls of the terms documents. | ||
@param success A block object called when the operation succeeds. | ||
@param failure A block object called when the operation fails. | ||
@return a MXHTTPOperation instance. | ||
*/ | ||
- (MXHTTPOperation*)agreeToTerms:(NSArray<NSString *> *)termsUrls | ||
success:(void (^)(void))success | ||
failure:(nullable void (^)(NSError * _Nonnull))failure; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
Oops, something went wrong.