From 566f68ef230e4285eb9e19a3d1045947d5a74eef Mon Sep 17 00:00:00 2001 From: Corey Baker Date: Mon, 1 May 2023 14:53:07 -0400 Subject: [PATCH] refactor to configureParse --- README.md | 6 +++--- Sources/ParseCareKit/PCKUtility.swift | 18 +++++++++--------- Tests/ParseCareKitTests/UtilityTests.swift | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index bb332ebaf..77d977c23 100644 --- a/README.md +++ b/README.md @@ -41,16 +41,16 @@ A sample app, [CareKitSample-ParseCareKit](https://github.com/netreconlab/CareKi ### ParseCareKit.plist with server connection information -ParseCareKit comes with a helper method, [PCKUtility.setupServer()](https://github.com/netreconlab/ParseCareKit/blob/4912bf7677511d148b52d03146c31cc428a83454/ParseCareKit/PCKUtility.swift#L14) that easily helps apps connect to your parse-server. To leverage the helper method, copy the [ParseCareKit.plist](https://github.com/netreconlab/CareKitSample-ParseCareKit/blob/main/OCKSample/Supporting%20Files/ParseCareKit.plist) file your "Supporting Files" folder in your Xcode project. Be sure to change `ApplicationID` and `Server` to the correct values for your server. Simply add the following inside `didFinishLaunchingWithOptions` in `AppDelegate.swift`: +ParseCareKit comes with a helper method, [PCKUtility.configureParse()](https://github.com/netreconlab/ParseCareKit/blob/4912bf7677511d148b52d03146c31cc428a83454/ParseCareKit/PCKUtility.swift#L14) that easily helps apps connect to your parse-server. To leverage the helper method, copy the [ParseCareKit.plist](https://github.com/netreconlab/CareKitSample-ParseCareKit/blob/main/OCKSample/Supporting%20Files/ParseCareKit.plist) file your "Supporting Files" folder in your Xcode project. Be sure to change `ApplicationID` and `Server` to the correct values for your server. Simply add the following inside `didFinishLaunchingWithOptions` in `AppDelegate.swift`: ```swift func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { //Pulls from ParseCareKit.plist to connect to server -PCKUtility.setupServer() +PCKUtility.configureParse() //If you need certificate pinning: -PCKUtility.setupServer { (challenge, completionHandler) in +PCKUtility.configureParse { (challenge, completionHandler) in //Return how you want to handle the challenge. See docs for more information. completionHandler(.performDefaultHandling, nil) } diff --git a/Sources/ParseCareKit/PCKUtility.swift b/Sources/ParseCareKit/PCKUtility.swift index ff565d051..bffcbf9e5 100644 --- a/Sources/ParseCareKit/PCKUtility.swift +++ b/Sources/ParseCareKit/PCKUtility.swift @@ -19,7 +19,7 @@ public class PCKUtility { var propertyListFormat = PropertyListSerialization.PropertyListFormat.xml guard let path = Bundle.main.path(forResource: fileName, ofType: "plist"), let xml = FileManager.default.contents(atPath: path) else { - fatalError("Error in ParseCareKit.setupServer(). Cannot find ParseCareKit.plist in this project") + fatalError("Error in ParseCareKit.configureParse(). Cannot find ParseCareKit.plist in this project") } return try PropertyListSerialization.propertyList(from: xml, @@ -29,7 +29,7 @@ public class PCKUtility { } /** - Setup a connection to Parse Server based on a ParseCareKit.plist file. + Configure the client to connect to a Parse Server based on a ParseCareKit.plist file. The key/values supported in the file are a dictionary named `ParseClientConfiguration`: - Server - (String) The server URL to connect to Parse Server. @@ -45,10 +45,10 @@ public class PCKUtility { completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void`. See Apple's [documentation](https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1411595-urlsession) for more for details. */ - public class func setupServer(fileName: String = "ParseCareKit", - authentication: ((URLAuthenticationChallenge, - (URLSession.AuthChallengeDisposition, - URLCredential?) -> Void) -> Void)? = nil) async throws { + public class func configureParse(fileName: String = "ParseCareKit", + authentication: ((URLAuthenticationChallenge, + (URLSession.AuthChallengeDisposition, + URLCredential?) -> Void) -> Void)? = nil) async throws { var plistConfiguration: [String: AnyObject] var clientKey: String? var liveQueryURL: URL? @@ -57,13 +57,13 @@ public class PCKUtility { do { plistConfiguration = try Self.getPlistConfiguration(fileName: fileName) } catch { - fatalError("Error in ParseCareKit.setupServer(). Could not serialize plist. \(error)") + fatalError("Error in ParseCareKit.configureParse(). Could not serialize plist. \(error)") } guard let appID = plistConfiguration["ApplicationID"] as? String, let server = plistConfiguration["Server"] as? String, let serverURL = URL(string: server) else { - fatalError("Error in ParseCareKit.setupServer(). Missing keys in \(plistConfiguration)") + fatalError("Error in ParseCareKit.configureParse(). Missing keys in \(plistConfiguration)") } if let client = plistConfiguration["ClientKey"] as? String { @@ -109,7 +109,7 @@ public class PCKUtility { do { plistConfiguration = try Self.getPlistConfiguration(fileName: fileName) } catch { - fatalError("Error in ParseCareKit.setupServer(). Could not serialize plist. \(error)") + fatalError("Error in ParseCareKit.configureParse(). Could not serialize plist. \(error)") } if let keychainAccessGroup = plistConfiguration["AccessGroup"] as? String { diff --git a/Tests/ParseCareKitTests/UtilityTests.swift b/Tests/ParseCareKitTests/UtilityTests.swift index 9a04accc6..4482e3b4b 100644 --- a/Tests/ParseCareKitTests/UtilityTests.swift +++ b/Tests/ParseCareKitTests/UtilityTests.swift @@ -21,8 +21,8 @@ class UtilityTests: XCTestCase { PCKUtility.removeCache() } - func testSetupServer() async throws { - try await PCKUtility.setupServer { (_, completionHandler) in + func testConfigureParse() async throws { + try await PCKUtility.configureParse { (_, completionHandler) in completionHandler(.performDefaultHandling, nil) } XCTAssertEqual(ParseSwift.configuration.applicationId, "3B5FD9DA-C278-4582-90DC-101C08E7FC98")