From d3959092923cc67e7204c1239bff4867068a4d9a Mon Sep 17 00:00:00 2001 From: mohamede Date: Mon, 2 Aug 2021 10:58:15 +0200 Subject: [PATCH] Removes or make internal code thats out of scope of the SDK like URLSession helper functions and logging. --- AdyenNetworking.xcodeproj/project.pbxproj | 12 ++---- AdyenNetworking/APIClient/APIClient.swift | 4 +- AdyenNetworking/Helpers/AdyenScope.swift | 42 ------------------- .../Helpers/{Logger.swift => Logging.swift} | 9 ++-- AdyenNetworking/Helpers/URLHelpers.swift | 2 +- .../Helpers/URLSessionHelpers.swift | 10 ++--- Networking Demo App/ViewController.swift | 2 +- 7 files changed, 14 insertions(+), 67 deletions(-) delete mode 100644 AdyenNetworking/Helpers/AdyenScope.swift rename AdyenNetworking/Helpers/{Logger.swift => Logging.swift} (61%) diff --git a/AdyenNetworking.xcodeproj/project.pbxproj b/AdyenNetworking.xcodeproj/project.pbxproj index b8d3d0f..d12cf57 100644 --- a/AdyenNetworking.xcodeproj/project.pbxproj +++ b/AdyenNetworking.xcodeproj/project.pbxproj @@ -34,9 +34,8 @@ F938999B26B005D70065561F /* AnyAPIContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = F938999926B005D70065561F /* AnyAPIContext.swift */; }; F938999C26B005D70065561F /* AnyAPIEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = F938999A26B005D70065561F /* AnyAPIEnvironment.swift */; }; F938999E26B0061C0065561F /* Coder.swift in Sources */ = {isa = PBXBuildFile; fileRef = F938999D26B0061C0065561F /* Coder.swift */; }; - F93899A026B0064E0065561F /* AdyenScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = F938999F26B0064E0065561F /* AdyenScope.swift */; }; F93899A226B006610065561F /* URLSessionHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = F93899A126B006610065561F /* URLSessionHelpers.swift */; }; - F93899A526B006900065561F /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = F93899A326B006900065561F /* Logger.swift */; }; + F93899A526B006900065561F /* Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = F93899A326B006900065561F /* Logging.swift */; }; F93899A826B007730065561F /* HttpError.swift in Sources */ = {isa = PBXBuildFile; fileRef = F93899A726B007730065561F /* HttpError.swift */; }; F93899AA26B008080065561F /* URLHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = F93899A926B008080065561F /* URLHelpers.swift */; }; /* End PBXBuildFile section */ @@ -112,9 +111,8 @@ F938999926B005D70065561F /* AnyAPIContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyAPIContext.swift; sourceTree = ""; }; F938999A26B005D70065561F /* AnyAPIEnvironment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyAPIEnvironment.swift; sourceTree = ""; }; F938999D26B0061C0065561F /* Coder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Coder.swift; sourceTree = ""; }; - F938999F26B0064E0065561F /* AdyenScope.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdyenScope.swift; sourceTree = ""; }; F93899A126B006610065561F /* URLSessionHelpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLSessionHelpers.swift; sourceTree = ""; }; - F93899A326B006900065561F /* Logger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = ""; }; + F93899A326B006900065561F /* Logging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logging.swift; sourceTree = ""; }; F93899A726B007730065561F /* HttpError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HttpError.swift; sourceTree = ""; }; F93899A926B008080065561F /* URLHelpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLHelpers.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -276,9 +274,8 @@ isa = PBXGroup; children = ( F93899A926B008080065561F /* URLHelpers.swift */, - F93899A326B006900065561F /* Logger.swift */, + F93899A326B006900065561F /* Logging.swift */, F93899A126B006610065561F /* URLSessionHelpers.swift */, - F938999F26B0064E0065561F /* AdyenScope.swift */, F938999D26B0061C0065561F /* Coder.swift */, ); path = Helpers; @@ -480,7 +477,6 @@ files = ( F938999526B0059E0065561F /* BackoffScheduler.swift in Sources */, F938999826B005B00065561F /* Request.swift in Sources */, - F93899A026B0064E0065561F /* AdyenScope.swift in Sources */, F938999026B0059E0065561F /* RetryAPIClient.swift in Sources */, F938999326B0059E0065561F /* Scheduler.swift in Sources */, F938999B26B005D70065561F /* AnyAPIContext.swift in Sources */, @@ -490,7 +486,7 @@ F93899A226B006610065561F /* URLSessionHelpers.swift in Sources */, F938999426B0059E0065561F /* RetryOnErrorAPIClient.swift in Sources */, F93899AA26B008080065561F /* URLHelpers.swift in Sources */, - F93899A526B006900065561F /* Logger.swift in Sources */, + F93899A526B006900065561F /* Logging.swift in Sources */, F93899A826B007730065561F /* HttpError.swift in Sources */, F938999E26B0061C0065561F /* Coder.swift in Sources */, F938999C26B005D70065561F /* AnyAPIEnvironment.swift in Sources */, diff --git a/AdyenNetworking/APIClient/APIClient.swift b/AdyenNetworking/APIClient/APIClient.swift index 21c1049..01a2b70 100644 --- a/AdyenNetworking/APIClient/APIClient.swift +++ b/AdyenNetworking/APIClient/APIClient.swift @@ -68,7 +68,7 @@ public final class APIClient: APIClientProtocol { requestCounter += 1 - urlSession.adyen.dataTask(with: urlRequest) { [weak self] result in + urlSession.dataTask(with: urlRequest) { [weak self] result in self?.handle(result, request, completionHandler: completionHandler) }.resume() } @@ -152,7 +152,7 @@ public final class APIClient: APIClientProtocol { } internal func printAsJSON(_ data: Data) { - guard AdyenLogging.isEnabled else { return } + guard Logging.isEnabled else { return } do { let jsonObject = try JSONSerialization.jsonObject(with: data, options: []) let jsonData = try JSONSerialization.data(withJSONObject: jsonObject, options: [.prettyPrinted]) diff --git a/AdyenNetworking/Helpers/AdyenScope.swift b/AdyenNetworking/Helpers/AdyenScope.swift deleted file mode 100644 index 588de09..0000000 --- a/AdyenNetworking/Helpers/AdyenScope.swift +++ /dev/null @@ -1,42 +0,0 @@ -// -// Copyright (c) 2021 Adyen N.V. -// -// This file is open source and available under the MIT license. See the LICENSE file for more info. -// - -import Foundation - -/// A wrapper around a base instance, to enable scoped system types extensions without conflict with the host app code. -/// :nodoc: -public struct AdyenScope { - - /// :nodoc: - public let base: Base - - /// :nodoc: - public init(base: Base) { - self.base = base - } -} - -/// Describes a type that needs scoped extension. -/// :nodoc: -public protocol AdyenCompatible { - - /// :nodoc: - associatedtype AdyenBase - - /// :nodoc: - var adyen: AdyenScope { get } -} - -/// Provides default implementation of the `adyen` property, -/// to enable any conforming type to inherit the `adyen` scope. -/// :nodoc: -public extension AdyenCompatible { - - /// :nodoc: - var adyen: AdyenScope { - AdyenScope(base: self) - } -} diff --git a/AdyenNetworking/Helpers/Logger.swift b/AdyenNetworking/Helpers/Logging.swift similarity index 61% rename from AdyenNetworking/Helpers/Logger.swift rename to AdyenNetworking/Helpers/Logging.swift index 78cc39e..156bc6c 100644 --- a/AdyenNetworking/Helpers/Logger.swift +++ b/AdyenNetworking/Helpers/Logging.swift @@ -7,16 +7,13 @@ import func Darwin.fputs /// Provides control over SDK logging. -public enum AdyenLogging { +public enum Logging { /// Indicates whether to enable printing to the console. public static var isEnabled: Bool = false } -/// :nodoc: -/// Copies the interface of `Swift.print()`, -/// and `Swift.print()` is called inside after checking first if `AdyenLogging.isEnabled` is `true`, and returns if `false`. -public func adyenPrint(_ items: Any..., separator: String = " ", terminator: String = "\n") { - guard AdyenLogging.isEnabled else { return } +internal func adyenPrint(_ items: Any..., separator: String = " ", terminator: String = "\n") { + guard Logging.isEnabled else { return } var idx = items.startIndex let endIdx = items.endIndex diff --git a/AdyenNetworking/Helpers/URLHelpers.swift b/AdyenNetworking/Helpers/URLHelpers.swift index 0caca46..c4c3e50 100644 --- a/AdyenNetworking/Helpers/URLHelpers.swift +++ b/AdyenNetworking/Helpers/URLHelpers.swift @@ -7,7 +7,7 @@ import Foundation /// :nodoc: -public extension URL { +internal extension URL { var queryParameters: [String: String] { let components = URLComponents(url: self, resolvingAgainstBaseURL: true) let queryItems = components?.queryItems ?? [] diff --git a/AdyenNetworking/Helpers/URLSessionHelpers.swift b/AdyenNetworking/Helpers/URLSessionHelpers.swift index 63e3c92..acf0ccd 100644 --- a/AdyenNetworking/Helpers/URLSessionHelpers.swift +++ b/AdyenNetworking/Helpers/URLSessionHelpers.swift @@ -7,21 +7,17 @@ import Foundation /// :nodoc: -extension URLSession: AdyenCompatible {} - -/// :nodoc: -public extension AdyenScope where Base: URLSession { - +internal extension URLSession { /// :nodoc: func dataTask(with url: URL, completion: @escaping ((Result) -> Void)) -> URLSessionDataTask { - base.dataTask(with: url, completionHandler: { data, response, error in + dataTask(with: url, completionHandler: { data, response, error in self.handle(data: data, response: response, error: error, completion: completion) }) } /// :nodoc: func dataTask(with urlRequest: URLRequest, completion: @escaping ((Result) -> Void)) -> URLSessionDataTask { - base.dataTask(with: urlRequest, completionHandler: { data, response, error in + dataTask(with: urlRequest, completionHandler: { data, response, error in self.handle(data: data, response: response, error: error, completion: completion) }) } diff --git a/Networking Demo App/ViewController.swift b/Networking Demo App/ViewController.swift index 6264be7..cbd522e 100644 --- a/Networking Demo App/ViewController.swift +++ b/Networking Demo App/ViewController.swift @@ -14,7 +14,7 @@ class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - AdyenLogging.isEnabled = true + Logging.isEnabled = true let request = GetUsersRequest() apiClient.perform(request) { result in switch result {