From 6cb5befe7e26fde88ec383385f5aa171ddc4099d Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Tue, 11 Jun 2024 09:45:51 -0400 Subject: [PATCH] [v8] Remove Promises API and dependency specifications --- GoogleUtilities.podspec | 1 - .../NSURLSession+GULPromises.h | 37 ------- .../GULURLSessionDataResponse.m | 30 ----- .../NSURLSession+GULPromises.m | 46 -------- .../NSURLSession+GULPromisesTests.m | 104 ------------------ Package.swift | 1 - 6 files changed, 219 deletions(-) delete mode 100644 GoogleUtilities/Environment/Public/GoogleUtilities/NSURLSession+GULPromises.h delete mode 100644 GoogleUtilities/Environment/URLSessionPromiseWrapper/GULURLSessionDataResponse.m delete mode 100644 GoogleUtilities/Environment/URLSessionPromiseWrapper/NSURLSession+GULPromises.m delete mode 100644 GoogleUtilities/Tests/Unit/Environment/NSURLSession+GULPromisesTests.m diff --git a/GoogleUtilities.podspec b/GoogleUtilities.podspec index 31387bca..7cf96549 100644 --- a/GoogleUtilities.podspec +++ b/GoogleUtilities.podspec @@ -47,7 +47,6 @@ other Google CocoaPods. They're not intended for direct public usage. 'third_party/IsAppEncrypted/**/*.[mh]' ] es.public_header_files = 'GoogleUtilities/Environment/Public/GoogleUtilities/*.h' - es.dependency 'PromisesObjC', '>= 1.2', '< 3.0' es.dependency 'GoogleUtilities/Privacy' es.frameworks = [ 'Security' diff --git a/GoogleUtilities/Environment/Public/GoogleUtilities/NSURLSession+GULPromises.h b/GoogleUtilities/Environment/Public/GoogleUtilities/NSURLSession+GULPromises.h deleted file mode 100644 index 7bed005e..00000000 --- a/GoogleUtilities/Environment/Public/GoogleUtilities/NSURLSession+GULPromises.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * 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 - -@class FBLPromise; -@class GULURLSessionDataResponse; - -NS_ASSUME_NONNULL_BEGIN - -/** Promise based API for `NSURLSession`. */ -@interface NSURLSession (GULPromises) - -/** Creates a promise wrapping `-[NSURLSession dataTaskWithRequest:completionHandler:]` method. - * @param URLRequest The request to create a data task with. - * @return A promise that is fulfilled when an HTTP response is received (with any response code), - * or is rejected with the error passed to the task completion. - */ -- (FBLPromise *)gul_dataTaskPromiseWithRequest: - (NSURLRequest *)URLRequest; - -@end - -NS_ASSUME_NONNULL_END diff --git a/GoogleUtilities/Environment/URLSessionPromiseWrapper/GULURLSessionDataResponse.m b/GoogleUtilities/Environment/URLSessionPromiseWrapper/GULURLSessionDataResponse.m deleted file mode 100644 index 559875a7..00000000 --- a/GoogleUtilities/Environment/URLSessionPromiseWrapper/GULURLSessionDataResponse.m +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * 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 "GoogleUtilities/Environment/Public/GoogleUtilities/GULURLSessionDataResponse.h" - -@implementation GULURLSessionDataResponse - -- (instancetype)initWithResponse:(NSHTTPURLResponse *)response HTTPBody:(NSData *)body { - self = [super init]; - if (self) { - _HTTPResponse = response; - _HTTPBody = body; - } - return self; -} - -@end diff --git a/GoogleUtilities/Environment/URLSessionPromiseWrapper/NSURLSession+GULPromises.m b/GoogleUtilities/Environment/URLSessionPromiseWrapper/NSURLSession+GULPromises.m deleted file mode 100644 index 6c70310f..00000000 --- a/GoogleUtilities/Environment/URLSessionPromiseWrapper/NSURLSession+GULPromises.m +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * 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 "GoogleUtilities/Environment/Public/GoogleUtilities/NSURLSession+GULPromises.h" - -#if __has_include() -#import -#else -#import "FBLPromises.h" -#endif - -#import "GoogleUtilities/Environment/Public/GoogleUtilities/GULURLSessionDataResponse.h" - -@implementation NSURLSession (GULPromises) - -- (FBLPromise *)gul_dataTaskPromiseWithRequest: - (NSURLRequest *)URLRequest { - return [FBLPromise async:^(FBLPromiseFulfillBlock fulfill, FBLPromiseRejectBlock reject) { - [[self dataTaskWithRequest:URLRequest - completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response, - NSError *_Nullable error) { - if (error) { - reject(error); - } else { - fulfill([[GULURLSessionDataResponse alloc] - initWithResponse:(NSHTTPURLResponse *)response - HTTPBody:data]); - } - }] resume]; - }]; -} - -@end diff --git a/GoogleUtilities/Tests/Unit/Environment/NSURLSession+GULPromisesTests.m b/GoogleUtilities/Tests/Unit/Environment/NSURLSession+GULPromisesTests.m deleted file mode 100644 index 5a4994bc..00000000 --- a/GoogleUtilities/Tests/Unit/Environment/NSURLSession+GULPromisesTests.m +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * 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 - -#import -#import "FBLPromise+Testing.h" -#import "GoogleUtilities/Tests/Unit/Shared/URLSession/FIRURLSessionOCMockStub.h" - -#import "GoogleUtilities/Environment/Public/GoogleUtilities/GULURLSessionDataResponse.h" -#import "GoogleUtilities/Environment/Public/GoogleUtilities/NSURLSession+GULPromises.h" - -#if !TARGET_OS_MACCATALYST - -@interface NSURLSession_GULPromisesTests : XCTestCase -@property(nonatomic) NSURLSession *URLSession; -@property(nonatomic) id URLSessionMock; -@end - -@implementation NSURLSession_GULPromisesTests - -- (void)setUp { - self.URLSession = [NSURLSession - sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]]; - self.URLSessionMock = OCMPartialMock(self.URLSession); -} - -- (void)tearDown { - [self.URLSessionMock stopMocking]; - self.URLSessionMock = nil; - self.URLSession = nil; -} - -- (void)testDataTaskPromiseWithRequestSuccess { - NSURL *url = [NSURL URLWithString:@"https://localhost"]; - NSURLRequest *request = [NSURLRequest requestWithURL:url]; - - NSHTTPURLResponse *expectedResponse = [[NSHTTPURLResponse alloc] initWithURL:url - statusCode:200 - HTTPVersion:@"1.1" - headerFields:nil]; - NSData *expectedBody = [@"body" dataUsingEncoding:NSUTF8StringEncoding]; - - [FIRURLSessionOCMockStub - stubURLSessionDataTaskWithResponse:expectedResponse - body:expectedBody - error:nil - URLSessionMock:self.URLSessionMock - requestValidationBlock:^BOOL(NSURLRequest *_Nonnull sentRequest) { - return [sentRequest isEqual:request]; - }]; - - __auto_type taskPromise = [self.URLSessionMock gul_dataTaskPromiseWithRequest:request]; - - XCTAssert(FBLWaitForPromisesWithTimeout(1.0)); - - XCTAssertTrue(taskPromise.isFulfilled); - XCTAssertNil(taskPromise.error); - XCTAssertEqualObjects(taskPromise.value.HTTPResponse, expectedResponse); - XCTAssertEqualObjects(taskPromise.value.HTTPBody, expectedBody); -} - -- (void)testDataTaskPromiseWithRequestError { - NSURL *url = [NSURL URLWithString:@"https://localhost"]; - NSURLRequest *request = [NSURLRequest requestWithURL:url]; - - NSError *expectedError = [NSError errorWithDomain:@"testDataTaskPromiseWithRequestError" - code:-1 - userInfo:nil]; - - [FIRURLSessionOCMockStub - stubURLSessionDataTaskWithResponse:nil - body:nil - error:expectedError - URLSessionMock:self.URLSessionMock - requestValidationBlock:^BOOL(NSURLRequest *_Nonnull sentRequest) { - return [sentRequest isEqual:request]; - }]; - - __auto_type taskPromise = [self.URLSessionMock gul_dataTaskPromiseWithRequest:request]; - - XCTAssert(FBLWaitForPromisesWithTimeout(0.5)); - - XCTAssertTrue(taskPromise.isRejected); - XCTAssertEqualObjects(taskPromise.error, expectedError); - XCTAssertNil(taskPromise.value); -} - -@end - -#endif // !TARGET_OS_MACCATALYST diff --git a/Package.swift b/Package.swift index 85868c39..729a15ff 100644 --- a/Package.swift +++ b/Package.swift @@ -88,7 +88,6 @@ let package = Package( .target( name: "GoogleUtilities-Environment", dependencies: [ - .product(name: "FBLPromises", package: "Promises"), "third-party-IsAppEncrypted", ], path: "GoogleUtilities/Environment",