Skip to content

Commit

Permalink
Removes or make internal code thats out of scope of the SDK like URLS…
Browse files Browse the repository at this point in the history
…ession helper functions and logging.
  • Loading branch information
mohammedDehairy committed Aug 2, 2021
1 parent c3b4f7a commit d395909
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 67 deletions.
12 changes: 4 additions & 8 deletions AdyenNetworking.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -112,9 +111,8 @@
F938999926B005D70065561F /* AnyAPIContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyAPIContext.swift; sourceTree = "<group>"; };
F938999A26B005D70065561F /* AnyAPIEnvironment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyAPIEnvironment.swift; sourceTree = "<group>"; };
F938999D26B0061C0065561F /* Coder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Coder.swift; sourceTree = "<group>"; };
F938999F26B0064E0065561F /* AdyenScope.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdyenScope.swift; sourceTree = "<group>"; };
F93899A126B006610065561F /* URLSessionHelpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLSessionHelpers.swift; sourceTree = "<group>"; };
F93899A326B006900065561F /* Logger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
F93899A326B006900065561F /* Logging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logging.swift; sourceTree = "<group>"; };
F93899A726B007730065561F /* HttpError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HttpError.swift; sourceTree = "<group>"; };
F93899A926B008080065561F /* URLHelpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLHelpers.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
Expand Down
4 changes: 2 additions & 2 deletions AdyenNetworking/APIClient/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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])
Expand Down
42 changes: 0 additions & 42 deletions AdyenNetworking/Helpers/AdyenScope.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion AdyenNetworking/Helpers/URLHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? []
Expand Down
10 changes: 3 additions & 7 deletions AdyenNetworking/Helpers/URLSessionHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Data, Error>) -> 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<Data, Error>) -> 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)
})
}
Expand Down
2 changes: 1 addition & 1 deletion Networking Demo App/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d395909

Please sign in to comment.