diff --git a/.circleci/config.yml b/.circleci/config.yml index 4ee6b8e..fbefdcb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,13 +2,13 @@ version: 2 jobs: build-and-test: macos: - xcode: "10.0.0" + xcode: "10.2.0" shell: /bin/bash --login -o pipefail steps: - checkout - run: xcodebuild -project Demo.xcodeproj -scheme "macOSTests" -sdk macosx test | xcpretty - - run: xcodebuild -project Demo.xcodeproj -scheme "iOSTests" -sdk iphonesimulator -destination 'platform=iOS Simulator,OS=12.0,name=iPhone X' test | xcpretty - - run: xcodebuild -project Demo.xcodeproj -scheme "tvOSTests" -destination 'platform=tvOS Simulator,name=Apple TV,OS=12.0' test | xcpretty + - run: xcodebuild -project Demo.xcodeproj -scheme "iOSTests" -sdk iphonesimulator -destination 'platform=iOS Simulator,OS=12.2,name=iPhone X' test | xcpretty + - run: xcodebuild -project Demo.xcodeproj -scheme "tvOSTests" -destination 'platform=tvOS Simulator,name=Apple TV,OS=12.2' test | xcpretty workflows: version: 2 diff --git a/Demo.xcodeproj/project.pbxproj b/Demo.xcodeproj/project.pbxproj index 3a56fc0..f77cc3f 100755 --- a/Demo.xcodeproj/project.pbxproj +++ b/Demo.xcodeproj/project.pbxproj @@ -619,61 +619,61 @@ attributes = { CLASSPREFIX = ""; LastSwiftUpdateCheck = 0800; - LastUpgradeCheck = 0940; + LastUpgradeCheck = 1020; ORGANIZATIONNAME = ""; TargetAttributes = { 1413F4541CE795DC00482096 = { CreatedOnToolsVersion = 7.3.1; DevelopmentTeamName = "Elvis Nunez (Personal Team)"; - LastSwiftMigration = 1000; + LastSwiftMigration = 1020; ProvisioningStyle = Manual; }; 14638CF91CC6459A002B9433 = { CreatedOnToolsVersion = 7.3; DevelopmentTeam = C6K65RDJHL; DevelopmentTeamName = "Elvis Nunez (Personal Team)"; - LastSwiftMigration = 1000; + LastSwiftMigration = 1020; }; 14638D111CC646F9002B9433 = { CreatedOnToolsVersion = 7.3; DevelopmentTeam = C6K65RDJHL; DevelopmentTeamName = "Elvis Nunez (Personal Team)"; - LastSwiftMigration = 0800; + LastSwiftMigration = 1020; }; 14638D271CC64747002B9433 = { CreatedOnToolsVersion = 7.3; DevelopmentTeam = C6K65RDJHL; DevelopmentTeamName = "Elvis Nunez (Personal Team)"; - LastSwiftMigration = 0800; + LastSwiftMigration = 1020; }; 14638D3D1CC647E4002B9433 = { CreatedOnToolsVersion = 7.3; DevelopmentTeam = C6K65RDJHL; DevelopmentTeamName = "Elvis Nunez (Personal Team)"; - LastSwiftMigration = 0800; + LastSwiftMigration = 1020; ProvisioningStyle = Automatic; }; 146D72AB1AB782920058798C = { CreatedOnToolsVersion = 6.2; DevelopmentTeamName = "Elvis Nunez (Personal Team)"; - LastSwiftMigration = 0900; + LastSwiftMigration = 1020; ProvisioningStyle = Manual; }; 44B5D3881D19B9E5004378B9 = { DevelopmentTeamName = "Elvis Nunez (Personal Team)"; - LastSwiftMigration = 0800; + LastSwiftMigration = 1020; ProvisioningStyle = Manual; }; 44DFD38C1D9A2D5A0014E9F2 = { CreatedOnToolsVersion = 8.0; - LastSwiftMigration = 0900; + LastSwiftMigration = 1020; ProvisioningStyle = Automatic; }; }; }; buildConfigurationList = 146D728E1AB782920058798C /* Build configuration list for PBXProject "Demo" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, @@ -1019,7 +1019,7 @@ SDKROOT = macosx; SWIFT_OBJC_BRIDGING_HEADER = "Tests/Resources/Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -1041,7 +1041,7 @@ SDKROOT = macosx; SWIFT_OBJC_BRIDGING_HEADER = "Tests/Resources/Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -1066,7 +1066,7 @@ PRODUCT_NAME = Networking; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -1094,7 +1094,7 @@ PRODUCT_NAME = Networking; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -1122,7 +1122,7 @@ SDKROOT = watchos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 4; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -1151,7 +1151,7 @@ SDKROOT = watchos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 4; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -1179,7 +1179,7 @@ SDKROOT = appletvos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; @@ -1207,7 +1207,7 @@ SDKROOT = appletvos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; @@ -1238,7 +1238,7 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -1267,7 +1267,7 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -1277,6 +1277,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -1331,6 +1332,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -1390,8 +1392,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Tests/Resources/Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -1407,8 +1408,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Tests/Resources/Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -1429,7 +1429,7 @@ SDKROOT = appletvos; SWIFT_OBJC_BRIDGING_HEADER = "Tests/Resources/Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -1446,7 +1446,7 @@ SDKROOT = appletvos; SWIFT_OBJC_BRIDGING_HEADER = "Tests/Resources/Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -1458,6 +1458,8 @@ CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_STYLE = Automatic; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = iOSDemo/Info.plist; @@ -1465,10 +1467,10 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.3lvis.networking.iOSDemo; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -1480,6 +1482,8 @@ CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_STYLE = Automatic; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = iOSDemo/Info.plist; @@ -1487,9 +1491,9 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.3lvis.networking.iOSDemo; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/Demo.xcodeproj/xcshareddata/xcschemes/Networking-iOS.xcscheme b/Demo.xcodeproj/xcshareddata/xcschemes/Networking-iOS.xcscheme index 0921818..3f34ca8 100644 --- a/Demo.xcodeproj/xcshareddata/xcschemes/Networking-iOS.xcscheme +++ b/Demo.xcodeproj/xcshareddata/xcschemes/Networking-iOS.xcscheme @@ -1,6 +1,6 @@ String { + func urlEncodedString() throws -> String { let pairs = try reduce([]) { current, keyValuePair -> [String] in if let encodedValue = "\(keyValuePair.value)".addingPercentEncoding(withAllowedCharacters: .urlQueryParametersAllowed) { diff --git a/Sources/JSON.swift b/Sources/JSON.swift index 243afd8..98822a4 100644 --- a/Sources/JSON.swift +++ b/Sources/JSON.swift @@ -63,7 +63,7 @@ public extension FileManager { /// - bundle: The Bundle where the file is located, by default is the main bundle. /// - Returns: A JSON object, it can be either a Dictionary or an Array. /// - Throws: An error if it wasn't able to process the file. - public static func json(from fileName: String, bundle: Bundle = Bundle.main) throws -> Any? { + static func json(from fileName: String, bundle: Bundle = Bundle.main) throws -> Any? { var json: Any? guard let url = URL(string: fileName), let filePath = bundle.path(forResource: url.deletingPathExtension().absoluteString, ofType: url.pathExtension) else { throw ParsingError.notFound } diff --git a/Sources/Networking+HTTPRequests.swift b/Sources/Networking+HTTPRequests.swift index 23fc62a..6a759ee 100644 --- a/Sources/Networking+HTTPRequests.swift +++ b/Sources/Networking+HTTPRequests.swift @@ -10,7 +10,7 @@ public extension Networking { /// - completion: The result of the operation, it's an enum with two cases: success and failure. /// - Returns: The request identifier. @discardableResult - public func get(_ path: String, parameters: Any? = nil, cachingLevel: CachingLevel = .none, completion: @escaping (_ result: JSONResult) -> Void) -> String { + func get(_ path: String, parameters: Any? = nil, cachingLevel: CachingLevel = .none, completion: @escaping (_ result: JSONResult) -> Void) -> String { let parameterType: ParameterType = parameters != nil ? .formURLEncoded : .none return handleJSONRequest(.get, path: path, cacheName: nil, parameterType: parameterType, parameters: parameters, responseType: .json, cachingLevel: cachingLevel, completion: completion) @@ -22,7 +22,7 @@ public extension Networking { /// - path: The path for the faked GET request. /// - response: An `Any` that will be returned when a GET request is made to the specified path. /// - statusCode: By default it's 200, if you provide any status code that is between 200 and 299 the response object will be returned, otherwise we will return an error containig the provided status code. - public func fakeGET(_ path: String, response: Any?, statusCode: Int = 200) { + func fakeGET(_ path: String, response: Any?, statusCode: Int = 200) { registerFake(requestType: .get, path: path, response: response, responseType: .json, statusCode: statusCode) } @@ -32,14 +32,14 @@ public extension Networking { /// - path: The path for the faked GET request. /// - fileName: The name of the file, whose contents will be registered as a reponse. /// - bundle: The Bundle where the file is located. - public func fakeGET(_ path: String, fileName: String, bundle: Bundle = Bundle.main) { + func fakeGET(_ path: String, fileName: String, bundle: Bundle = Bundle.main) { registerFake(requestType: .get, path: path, fileName: fileName, bundle: bundle) } /// Cancels the GET request for the specified path. This causes the request to complete with error code URLError.cancelled. /// /// - Parameter path: The path for the cancelled GET request - public func cancelGET(_ path: String) { + func cancelGET(_ path: String) { let url = try! composedURL(with: path) cancelRequest(.data, requestType: .get, url: url) } @@ -56,7 +56,7 @@ public extension Networking { /// - completion: The result of the operation, it's an enum with two cases: success and failure. /// - Returns: The request identifier. @discardableResult - public func patch(_ path: String, parameterType: ParameterType = .json, parameters: Any? = nil, completion: @escaping (_ result: JSONResult) -> Void) -> String { + func patch(_ path: String, parameterType: ParameterType = .json, parameters: Any? = nil, completion: @escaping (_ result: JSONResult) -> Void) -> String { return handleJSONRequest(.patch, path: path, cacheName: nil, parameterType: parameterType, parameters: parameters, responseType: .json, cachingLevel: .none, completion: completion) } @@ -66,7 +66,7 @@ public extension Networking { /// - path: The path for the faked PATCH request. /// - response: An `Any` that will be returned when a PATCH request is made to the specified path. /// - statusCode: By default it's 200, if you provide any status code that is between 200 and 299 the response object will be returned, otherwise we will return an error containig the provided status code. - public func fakePATCH(_ path: String, response: Any?, statusCode: Int = 200) { + func fakePATCH(_ path: String, response: Any?, statusCode: Int = 200) { registerFake(requestType: .patch, path: path, response: response, responseType: .json, statusCode: statusCode) } @@ -76,14 +76,14 @@ public extension Networking { /// - path: The path for the faked PATCH request. /// - fileName: The name of the file, whose contents will be registered as a reponse. /// - bundle: The Bundle where the file is located. - public func fakePATCH(_ path: String, fileName: String, bundle: Bundle = Bundle.main) { + func fakePATCH(_ path: String, fileName: String, bundle: Bundle = Bundle.main) { registerFake(requestType: .patch, path: path, fileName: fileName, bundle: bundle) } /// Cancels the PATCH request for the specified path. This causes the request to complete with error code URLError.cancelled. /// /// - Parameter path: The path for the cancelled PATCH request. - public func cancelPATCH(_ path: String) { + func cancelPATCH(_ path: String) { let url = try! composedURL(with: path) cancelRequest(.data, requestType: .patch, url: url) } @@ -100,7 +100,7 @@ public extension Networking { /// - completion: The result of the operation, it's an enum with two cases: success and failure. /// - Returns: The request identifier. @discardableResult - public func put(_ path: String, parameterType: ParameterType = .json, parameters: Any? = nil, completion: @escaping (_ result: JSONResult) -> Void) -> String { + func put(_ path: String, parameterType: ParameterType = .json, parameters: Any? = nil, completion: @escaping (_ result: JSONResult) -> Void) -> String { return handleJSONRequest(.put, path: path, cacheName: nil, parameterType: parameterType, parameters: parameters, responseType: .json, cachingLevel: .none, completion: completion) } @@ -110,7 +110,7 @@ public extension Networking { /// - path: The path for the faked PUT request. /// - response: An `Any` that will be returned when a PUT request is made to the specified path. /// - statusCode: By default it's 200, if you provide any status code that is between 200 and 299 the response object will be returned, otherwise we will return an error containig the provided status code. - public func fakePUT(_ path: String, response: Any?, statusCode: Int = 200) { + func fakePUT(_ path: String, response: Any?, statusCode: Int = 200) { registerFake(requestType: .put, path: path, response: response, responseType: .json, statusCode: statusCode) } @@ -120,14 +120,14 @@ public extension Networking { /// - path: The path for the faked PUT request. /// - fileName: The name of the file, whose contents will be registered as a reponse. /// - bundle: The Bundle where the file is located. - public func fakePUT(_ path: String, fileName: String, bundle: Bundle = Bundle.main) { + func fakePUT(_ path: String, fileName: String, bundle: Bundle = Bundle.main) { registerFake(requestType: .put, path: path, fileName: fileName, bundle: bundle) } /// Cancels the PUT request for the specified path. This causes the request to complete with error code URLError.cancelled. /// /// - Parameter path: The path for the cancelled PUT request. - public func cancelPUT(_ path: String) { + func cancelPUT(_ path: String) { let url = try! composedURL(with: path) cancelRequest(.data, requestType: .put, url: url) } @@ -144,7 +144,7 @@ public extension Networking { /// - completion: The result of the operation, it's an enum with two cases: success and failure. /// - Returns: The request identifier. @discardableResult - public func post(_ path: String, parameterType: ParameterType = .json, parameters: Any? = nil, completion: @escaping (_ result: JSONResult) -> Void) -> String { + func post(_ path: String, parameterType: ParameterType = .json, parameters: Any? = nil, completion: @escaping (_ result: JSONResult) -> Void) -> String { return handleJSONRequest(.post, path: path, cacheName: nil, parameterType: parameterType, parameters: parameters, responseType: .json, cachingLevel: .none, completion: completion) } @@ -157,7 +157,7 @@ public extension Networking { /// - completion: A closure that gets called when the POST request is completed, it contains a `JSON` object and an `NSError`. /// - Returns: The request identifier. @discardableResult - public func post(_ path: String, parameters: Any? = nil, parts: [FormDataPart], completion: @escaping (_ result: JSONResult) -> Void) -> String { + func post(_ path: String, parameters: Any? = nil, parts: [FormDataPart], completion: @escaping (_ result: JSONResult) -> Void) -> String { return handleJSONRequest(.post, path: path, cacheName: nil, parameterType: .multipartFormData, parameters: parameters, parts: parts, responseType: .json, cachingLevel: .none, completion: completion) } @@ -167,7 +167,7 @@ public extension Networking { /// - path: The path for the faked POST request. /// - response: An `Any` that will be returned when a POST request is made to the specified path. /// - statusCode: By default it's 200, if you provide any status code that is between 200 and 299 the response object will be returned, otherwise we will return an error containig the provided status code. - public func fakePOST(_ path: String, response: Any?, statusCode: Int = 200) { + func fakePOST(_ path: String, response: Any?, statusCode: Int = 200) { registerFake(requestType: .post, path: path, response: response, responseType: .json, statusCode: statusCode) } @@ -177,14 +177,14 @@ public extension Networking { /// - path: The path for the faked POST request. /// - fileName: The name of the file, whose contents will be registered as a reponse. /// - bundle: The Bundle where the file is located. - public func fakePOST(_ path: String, fileName: String, bundle: Bundle = Bundle.main) { + func fakePOST(_ path: String, fileName: String, bundle: Bundle = Bundle.main) { registerFake(requestType: .post, path: path, fileName: fileName, bundle: bundle) } /// Cancels the POST request for the specified path. This causes the request to complete with error code URLError.cancelled. /// /// - Parameter path: The path for the cancelled POST request. - public func cancelPOST(_ path: String) { + func cancelPOST(_ path: String) { let url = try! composedURL(with: path) cancelRequest(.data, requestType: .post, url: url) } @@ -200,7 +200,7 @@ public extension Networking { /// - completion: The result of the operation, it's an enum with two cases: success and failure. /// - Returns: The request identifier. @discardableResult - public func delete(_ path: String, parameters: Any? = nil, completion: @escaping (_ result: JSONResult) -> Void) -> String { + func delete(_ path: String, parameters: Any? = nil, completion: @escaping (_ result: JSONResult) -> Void) -> String { let parameterType: ParameterType = parameters != nil ? .formURLEncoded : .none return handleJSONRequest(.delete, path: path, cacheName: nil, parameterType: parameterType, parameters: parameters, responseType: .json, cachingLevel: .none, completion: completion) } @@ -211,7 +211,7 @@ public extension Networking { /// - path: The path for the faked DELETE request. /// - response: An `Any` that will be returned when a DELETE request is made to the specified path. /// - statusCode: By default it's 200, if you provide any status code that is between 200 and 299 the response object will be returned, otherwise we will return an error containig the provided status code. - public func fakeDELETE(_ path: String, response: Any?, statusCode: Int = 200) { + func fakeDELETE(_ path: String, response: Any?, statusCode: Int = 200) { registerFake(requestType: .delete, path: path, response: response, responseType: .json, statusCode: statusCode) } @@ -221,14 +221,14 @@ public extension Networking { /// - path: The path for the faked DELETE request. /// - fileName: The name of the file, whose contents will be registered as a reponse. /// - bundle: The Bundle where the file is located. - public func fakeDELETE(_ path: String, fileName: String, bundle: Bundle = Bundle.main) { + func fakeDELETE(_ path: String, fileName: String, bundle: Bundle = Bundle.main) { registerFake(requestType: .delete, path: path, fileName: fileName, bundle: bundle) } /// Cancels the DELETE request for the specified path. This causes the request to complete with error code URLError.cancelled. /// /// - Parameter path: The path for the cancelled DELETE request. - public func cancelDELETE(_ path: String) { + func cancelDELETE(_ path: String) { let url = try! composedURL(with: path) cancelRequest(.data, requestType: .delete, url: url) } @@ -242,7 +242,7 @@ public extension Networking { /// - path: The path where the image is located. /// - cacheName: The cache name used to identify the downloaded image, by default the path is used. /// - Returns: The cached image. - public func imageFromCache(_ path: String, cacheName: String? = nil) -> Image? { + func imageFromCache(_ path: String, cacheName: String? = nil) -> Image? { let object = objectFromCache(for: path, cacheName: cacheName, cachingLevel: .memoryAndFile, responseType: .image) return object as? Image @@ -257,14 +257,14 @@ public extension Networking { /// - completion: The result of the operation, it's an enum with two cases: success and failure. /// - Returns: The request identifier. @discardableResult - public func downloadImage(_ path: String, cacheName: String? = nil, cachingLevel: CachingLevel = .memoryAndFile, completion: @escaping (_ result: ImageResult) -> Void) -> String { + func downloadImage(_ path: String, cacheName: String? = nil, cachingLevel: CachingLevel = .memoryAndFile, completion: @escaping (_ result: ImageResult) -> Void) -> String { return handleImageRequest(.get, path: path, cacheName: cacheName, cachingLevel: cachingLevel, responseType: .image, completion: completion) } /// Cancels the image download request for the specified path. This causes the request to complete with error code URLError.cancelled. /// /// - Parameter path: The path for the cancelled image download request. - public func cancelImageDownload(_ path: String) { + func cancelImageDownload(_ path: String) { let url = try! composedURL(with: path) cancelRequest(.data, requestType: .get, url: url) } @@ -275,7 +275,7 @@ public extension Networking { /// - path: The path for the faked image download request. /// - image: An image that will be returned when there's a request to the registered path. /// - statusCode: The status code to be used when faking the request. - public func fakeImageDownload(_ path: String, image: Image?, statusCode: Int = 200) { + func fakeImageDownload(_ path: String, image: Image?, statusCode: Int = 200) { registerFake(requestType: .get, path: path, response: image, responseType: .image, statusCode: statusCode) } @@ -287,7 +287,7 @@ public extension Networking { /// - cachingLevel: Enum to control the caching level: .memory, .memoryAndFile, .none /// - completion: A closure that gets called when the download request is completed, it contains a `data` object and an `NSError`. @discardableResult - public func downloadData(_ path: String, cacheName: String? = nil, cachingLevel: CachingLevel = .memoryAndFile, completion: @escaping (_ result: DataResult) -> Void) -> String { + func downloadData(_ path: String, cacheName: String? = nil, cachingLevel: CachingLevel = .memoryAndFile, completion: @escaping (_ result: DataResult) -> Void) -> String { return handleDataRequest(.get, path: path, cacheName: cacheName, cachingLevel: cachingLevel, responseType: .data, completion: completion) } @@ -297,7 +297,7 @@ public extension Networking { /// - path: The path where the image is located. /// - cacheName: The cache name used to identify the downloaded data, by default the path is used. /// - Returns: The cached data. - public func dataFromCache(_ path: String, cacheName: String? = nil) -> Data? { + func dataFromCache(_ path: String, cacheName: String? = nil) -> Data? { let object = objectFromCache(for: path, cacheName: cacheName, cachingLevel: .memoryAndFile, responseType: .data) return object as? Data diff --git a/Tests/DELETETests.swift b/Tests/DELETETests.swift index 60bc16f..ca44cb4 100644 --- a/Tests/DELETETests.swift +++ b/Tests/DELETETests.swift @@ -21,7 +21,7 @@ class DELETETests: XCTestCase { case let .success(response): let json = response.dictionaryBody guard let url = json["url"] as? String else { XCTFail(); return } - XCTAssertEqual(url, "http://httpbin.org/delete") + XCTAssertEqual(url, "https://httpbin.org/delete") guard let headers = json["headers"] as? [String: String] else { XCTFail(); return } let contentType = headers["Content-Type"] @@ -39,7 +39,7 @@ class DELETETests: XCTestCase { case let .success(response): let json = response.dictionaryBody guard let url = json["url"] as? String else { XCTFail(); return } - XCTAssertEqual(url, "http://httpbin.org/delete") + XCTAssertEqual(url, "https://httpbin.org/delete") let headers = response.headers guard let connection = headers["Connection"] as? String else { XCTFail(); return } @@ -113,7 +113,7 @@ class DELETETests: XCTestCase { switch result { case let .success(response): let json = response.dictionaryBody - XCTAssertEqual(json["url"] as? String, "http://httpbin.org/delete?userId=25") + XCTAssertEqual(json["url"] as? String, "https://httpbin.org/delete?userId=25") case .failure: XCTFail() } diff --git a/Tests/GETTests.swift b/Tests/GETTests.swift index 78e3edb..93429bb 100644 --- a/Tests/GETTests.swift +++ b/Tests/GETTests.swift @@ -33,7 +33,7 @@ class GETTests: XCTestCase { let json = response.dictionaryBody guard let url = json["url"] as? String else { XCTFail(); return } - XCTAssertEqual(url, "http://httpbin.org/get") + XCTAssertEqual(url, "https://httpbin.org/get") guard let headers = json["headers"] as? [String: String] else { XCTFail(); return } let contentType = headers["Content-Type"] @@ -52,7 +52,7 @@ class GETTests: XCTestCase { let json = response.dictionaryBody guard let url = json["url"] as? String else { XCTFail(); return } - XCTAssertEqual(url, "http://httpbin.org/get") + XCTAssertEqual(url, "https://httpbin.org/get") guard let headers = json["headers"] as? [String: String] else { XCTFail(); return } let contentType = headers["Content-Type"] @@ -70,7 +70,7 @@ class GETTests: XCTestCase { case let .success(response): let json = response.dictionaryBody guard let url = json["url"] as? String else { XCTFail(); return } - XCTAssertEqual(url, "http://httpbin.org/get") + XCTAssertEqual(url, "https://httpbin.org/get") let headers = response.headers guard let connection = headers["Connection"] as? String else { XCTFail(); return } @@ -182,7 +182,7 @@ class GETTests: XCTestCase { switch result { case let .success(response): let json = response.dictionaryBody - XCTAssertEqual(json["url"] as? String, "http://httpbin.org/get?count=25") + XCTAssertEqual(json["url"] as? String, "https://httpbin.org/get?count=25") case .failure: XCTFail() } @@ -195,7 +195,7 @@ class GETTests: XCTestCase { switch result { case let .success(response): let json = response.dictionaryBody - XCTAssertEqual(json["url"] as? String, "http://httpbin.org/get?accountId=123&userId=5") + XCTAssertEqual(json["url"] as? String, "https://httpbin.org/get?accountId=123&userId=5") case .failure: XCTFail() } @@ -208,7 +208,7 @@ class GETTests: XCTestCase { switch result { case let .success(response): let json = response.dictionaryBody - XCTAssertEqual(json["url"] as? String, "http://httpbin.org/get?name=Elvis Nuñez") + XCTAssertEqual(json["url"] as? String, "https://httpbin.org/get?name=Elvis Nuñez") case .failure: XCTFail() } diff --git a/Tests/JSONTests.swift b/Tests/JSONTests.swift index 1bffd99..1b93bea 100644 --- a/Tests/JSONTests.swift +++ b/Tests/JSONTests.swift @@ -64,13 +64,16 @@ class JSONTests: XCTestCase { func testArrayJSONFromFileNamed() { let result = try! FileManager.json(from: "simple_array.json", bundle: Bundle(for: JSONTests.self)) as? [[String: Any]] ?? [[String: Any]]() - let compared = [["id": 1, "name": "Hi"]] + var compared = [["id": 1, "name": "Hi"]] + XCTAssertEqual(compared.count, result.count) // This should work but Swift is not able to compile it. // XCTAssertEqual(compared, result) - XCTAssertEqual(Array(compared[0].keys), Array(result[0].keys)) + let comparedKeys = Array(compared[0].keys).sorted() + let resultKeys = Array(result[0].keys).sorted() + XCTAssertEqual(comparedKeys, resultKeys) XCTAssertEqual(compared[0]["id"] as? Int, result[0]["id"] as? Int) XCTAssertEqual(compared[0]["name"] as? String, result[0]["name"] as? String) } @@ -79,7 +82,7 @@ class JSONTests: XCTestCase { let result = try! FileManager.json(from: "simple_dictionary.json", bundle: Bundle(for: JSONTests.self)) as? [String: Any] ?? [String: Any]() let compared = ["id": 1, "name": "Hi"] as [String: Any] XCTAssertEqual(compared.count, result.count) - XCTAssertEqual(Array(compared.keys), Array(result.keys)) + XCTAssertEqual(Array(compared.keys).sorted(), Array(result.keys).sorted()) } func testFromFileNamedWithNotFoundFile() { @@ -115,7 +118,7 @@ class JSONTests: XCTestCase { do { let JSON = try data?.toJSON() as? [String: Any] let url = JSON?["url"] as! String - XCTAssertEqual(url, "http://httpbin.org/get") + XCTAssertEqual(url, "https://httpbin.org/get") } catch { // Handle error } diff --git a/Tests/NetworkingTests.swift b/Tests/NetworkingTests.swift index c513aa0..483c93e 100644 --- a/Tests/NetworkingTests.swift +++ b/Tests/NetworkingTests.swift @@ -290,7 +290,7 @@ class NetworkingTests: XCTestCase { let image = Image.find(named: "sample.jpg", inBundle: Bundle(for: NetworkingTests.self)) let data = image.jpgData() let filename = cachesURL.appendingPathComponent("sample.jpg") - try? data?.write(to: filename) + ((try? data?.write(to: filename)) as ()??) XCTAssertTrue(FileManager.default.exists(at: cachesURL)) XCTAssertTrue(FileManager.default.exists(at: folderURL)) diff --git a/Tests/PATCHTests.swift b/Tests/PATCHTests.swift index 1a0d346..626dac2 100644 --- a/Tests/PATCHTests.swift +++ b/Tests/PATCHTests.swift @@ -39,7 +39,7 @@ class PATCHTests: XCTestCase { case let .success(response): let json = response.dictionaryBody guard let url = json["url"] as? String else { XCTFail(); return } - XCTAssertEqual(url, "http://httpbin.org/patch") + XCTAssertEqual(url, "https://httpbin.org/patch") let headers = response.headers guard let connection = headers["Connection"] as? String else { XCTFail(); return } diff --git a/Tests/POSTTests.swift b/Tests/POSTTests.swift index 8904564..c271ea5 100644 --- a/Tests/POSTTests.swift +++ b/Tests/POSTTests.swift @@ -63,7 +63,7 @@ class POSTTests: XCTestCase { case let .success(response): let json = response.dictionaryBody guard let url = json["url"] as? String else { XCTFail(); return } - XCTAssertEqual(url, "http://httpbin.org/post") + XCTAssertEqual(url, "https://httpbin.org/post") let headers = response.headers guard let connection = headers["Connection"] as? String else { XCTFail(); return } @@ -81,7 +81,7 @@ class POSTTests: XCTestCase { switch result { case let .success(response): let JSONResponse = response.dictionaryBody - XCTAssertEqual("http://httpbin.org/post", JSONResponse["url"] as? String) + XCTAssertEqual("https://httpbin.org/post", JSONResponse["url"] as? String) case .failure: XCTFail() } @@ -130,7 +130,7 @@ class POSTTests: XCTestCase { switch result { case let .success(response): let json = response.dictionaryBody - XCTAssertEqual(json["url"] as? String, "http://httpbin.org/post") + XCTAssertEqual(json["url"] as? String, "https://httpbin.org/post") guard let headers = json["headers"] as? [String: Any] else { XCTFail(); return } XCTAssertEqual(headers["Content-Type"] as? String, "multipart/form-data; boundary=\(networking.boundary)") @@ -159,7 +159,7 @@ class POSTTests: XCTestCase { switch result { case let .success(response): let json = response.dictionaryBody - XCTAssertEqual(json["url"] as? String, "http://httpbin.org/post") + XCTAssertEqual(json["url"] as? String, "https://httpbin.org/post") guard let headers = json["headers"] as? [String: Any] else { XCTFail(); return } XCTAssertEqual(headers["Content-Type"] as? String, "multipart/form-data; boundary=\(networking.boundary)") diff --git a/Tests/PUTTests.swift b/Tests/PUTTests.swift index 0f9df3a..d754c50 100644 --- a/Tests/PUTTests.swift +++ b/Tests/PUTTests.swift @@ -39,7 +39,7 @@ class PUTTests: XCTestCase { case let .success(response): let json = response.dictionaryBody guard let url = json["url"] as? String else { XCTFail(); return } - XCTAssertEqual(url, "http://httpbin.org/put") + XCTAssertEqual(url, "https://httpbin.org/put") let headers = response.headers guard let connection = headers["Connection"] as? String else { XCTFail(); return }