Skip to content

Commit 2f77fd6

Browse files
authored
Switch CloudCode to similar syntax as JS SDK. Update podspec (#46)
* Switch CloudCode to similar syntax as JS SDK. Update podspec * fix playground file * Updates playgrounds * add back playgrounds file
1 parent f124d0a commit 2f77fd6

File tree

10 files changed

+43
-39
lines changed

10 files changed

+43
-39
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.0
1+
// swift-tools-version:5.1
22

33
import PackageDescription
44

ParseSwift.playground/Pages/10 - Cloud Code.xcplaygroundpage/Contents.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct Cloud: ParseCloud {
2424
*/
2525
let cloud = Cloud(functionJobName: "hello")
2626

27-
cloud.callFunction { result in
27+
cloud.runFunction { result in
2828
switch result {
2929
case .success(let response):
3030
print("Response from cloud function: \(response)")
@@ -33,6 +33,7 @@ cloud.callFunction { result in
3333
}
3434
}
3535

36-
//: Jobs can be run the same way by using the method `callJob()`
36+
//: Jobs can be run the same way by using the method `startJob()`
37+
PlaygroundPage.current.finishExecution()
3738

3839
//: [Next](@next)

ParseSwift.playground/Pages/7 - GeoPoint.xcplaygroundpage/Contents.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,5 @@ print(explain)
177177
let hint = try query2.find(explain: false, hint: "objectId")
178178
print(hint)
179179

180+
PlaygroundPage.current.finishExecution()
180181
//: [Next](@next)

ParseSwift.playground/Pages/8 - Pointers.xcplaygroundpage/Contents.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,5 @@ author2.save { result in
8484
}
8585
}
8686

87+
PlaygroundPage.current.finishExecution()
8788
//: [Next](@next)

ParseSwift.playground/Pages/9 - Files.xcplaygroundpage/Contents.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,6 @@ do {
151151
/*: Files can also be saved from files located on your device by using:
152152
let localFile = ParseFile(name: "hello.txt", localURL: URL)
153153
*/
154+
155+
PlaygroundPage.current.finishExecution()
154156
//: [Next](@next)

ParseSwift.playground/contents.xcplayground

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
<page name='9 - Files'/>
1313
<page name='10 - Cloud Code'/>
1414
</pages>
15-
</playground>
15+
</playground>

ParseSwift.podspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ Pod::Spec.new do |s|
1010
:git => "#{s.homepage}.git",
1111
:tag => "#{s.version}",
1212
}
13-
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '5.0' }
1413
s.ios.deployment_target = "11.0"
1514
s.osx.deployment_target = "10.13"
1615
s.tvos.deployment_target = "11.0"
1716
s.watchos.deployment_target = "4.0"
18-
s.swift_versions = ['5.0']
17+
s.swift_versions = ['5.1', '5.2', '5.3']
1918
s.source_files = "Sources/ParseSwift/**/*.swift"
2019
s.license = {
2120
:type => "MIT",

Sources/ParseSwift/Objects/ParseInstallation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import AppKit
3131
`ParseInstallation` installations which have a valid `deviceToken` and are saved to
3232
the Parse cloud can be used to target push notifications.
3333

34-
- warning: Only use `ParseInstallation` installations on the main thread as they
34+
- warning: Only use `ParseInstallation.current` installations on the main thread as they
3535
require UIApplication for `badge`
3636
*/
3737
public protocol ParseInstallation: ParseObject {

Sources/ParseSwift/Types/ParseCloud.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,30 @@ public protocol ParseCloud: ParseType, Decodable, CustomDebugStringConvertible {
2525
extension ParseCloud {
2626

2727
/**
28-
Calls *synchronously* a Cloud Code function and returns a result of it's execution.
28+
Calls a Cloud Code function *synchronously* and returns a result of it's execution.
2929
- parameter options: A set of header options sent to the server. Defaults to an empty set.
3030
- returns: Returns a JSON response of `AnyCodable` type.
3131
*/
32-
public func callFunction(options: API.Options = []) throws -> AnyCodable {
33-
try callFunctionCommand().execute(options: options)
32+
public func runFunction(options: API.Options = []) throws -> AnyCodable {
33+
try runFunctionCommand().execute(options: options)
3434
}
3535

3636
/**
37-
Calls *asynchronously* a Cloud Code function and returns a result of it's execution.
37+
Calls a Cloud Code function *asynchronously* and returns a result of it's execution.
3838
- parameter options: A set of header options sent to the server. Defaults to an empty set.
3939
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
4040
- parameter completion: A block that will be called when logging out, completes or fails.
4141
It should have the following argument signature: `(Result<AnyCodable, ParseError>)`.
4242
*/
43-
public func callFunction(options: API.Options = [],
44-
callbackQueue: DispatchQueue = .main,
45-
completion: @escaping (Result<AnyCodable, ParseError>) -> Void) {
46-
callFunctionCommand()
43+
public func runFunction(options: API.Options = [],
44+
callbackQueue: DispatchQueue = .main,
45+
completion: @escaping (Result<AnyCodable, ParseError>) -> Void) {
46+
runFunctionCommand()
4747
.executeAsync(options: options,
4848
callbackQueue: callbackQueue, completion: completion)
4949
}
5050

51-
internal func callFunctionCommand() -> API.Command<Self, AnyCodable> {
51+
internal func runFunctionCommand() -> API.Command<Self, AnyCodable> {
5252

5353
return API.Command(method: .POST,
5454
path: .functions(name: functionJobName),
@@ -68,30 +68,30 @@ extension ParseCloud {
6868
// MARK: Jobs
6969
extension ParseCloud {
7070
/**
71-
Calls *synchronously* a Cloud Code job and returns a result of it's execution.
71+
Starts a Cloud Code job *synchronously* and returns a result with the jobStatusId of the job.
7272
- parameter options: A set of header options sent to the server. Defaults to an empty set.
7373
- returns: Returns a JSON response of `AnyCodable` type.
7474
*/
75-
public func callJob(options: API.Options = []) throws -> AnyCodable {
76-
try callJobCommand().execute(options: options)
75+
public func startJob(options: API.Options = []) throws -> AnyCodable {
76+
try startJobCommand().execute(options: options)
7777
}
7878

7979
/**
80-
Calls *asynchronously* a Cloud Code job and returns a result of it's execution.
80+
Starts a Cloud Code job *asynchronously* and returns a result with the jobStatusId of the job.
8181
- parameter options: A set of header options sent to the server. Defaults to an empty set.
8282
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
8383
- parameter completion: A block that will be called when logging out, completes or fails.
8484
It should have the following argument signature: `(Result<AnyCodable, ParseError>)`.
8585
*/
86-
public func callJob(options: API.Options = [],
87-
callbackQueue: DispatchQueue = .main,
88-
completion: @escaping (Result<AnyCodable, ParseError>) -> Void) {
89-
callJobCommand()
86+
public func startJob(options: API.Options = [],
87+
callbackQueue: DispatchQueue = .main,
88+
completion: @escaping (Result<AnyCodable, ParseError>) -> Void) {
89+
startJobCommand()
9090
.executeAsync(options: options,
9191
callbackQueue: callbackQueue, completion: completion)
9292
}
9393

94-
internal func callJobCommand() -> API.Command<Self, AnyCodable> {
94+
internal func startJobCommand() -> API.Command<Self, AnyCodable> {
9595
return API.Command(method: .POST,
9696
path: .jobs(name: functionJobName),
9797
body: self) { (data) -> AnyCodable in

Tests/ParseSwiftTests/ParseCloudTests.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
8383

8484
func testCallFunctionCommand() throws {
8585
let cloud = Cloud(functionJobName: "test")
86-
let command = cloud.callFunctionCommand()
86+
let command = cloud.runFunctionCommand()
8787
XCTAssertNotNil(command)
8888
XCTAssertEqual(command.path.urlComponent, "/functions/test")
8989
XCTAssertEqual(command.method, API.Method.POST)
@@ -93,7 +93,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
9393

9494
func testCallFunctionWithArgsCommand() throws {
9595
let cloud = Cloud2(functionJobName: "test", customKey: "parse")
96-
let command = cloud.callFunctionCommand()
96+
let command = cloud.runFunctionCommand()
9797
XCTAssertNotNil(command)
9898
XCTAssertEqual(command.path.urlComponent, "/functions/test")
9999
XCTAssertEqual(command.method, API.Method.POST)
@@ -115,7 +115,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
115115
}
116116
do {
117117
let cloud = Cloud(functionJobName: "test")
118-
let functionResponse = try cloud.callFunction()
118+
let functionResponse = try cloud.runFunction()
119119
XCTAssertEqual(functionResponse, AnyCodable())
120120
} catch {
121121
XCTFail(error.localizedDescription)
@@ -138,7 +138,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
138138
}
139139
do {
140140
let cloud = Cloud(functionJobName: "test")
141-
let functionResponse = try cloud.callFunction()
141+
let functionResponse = try cloud.runFunction()
142142
guard let resultAsDictionary = functionResponse.value as? [String: String] else {
143143
XCTFail("Should have casted result to dictionary")
144144
return
@@ -166,7 +166,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
166166
}
167167
do {
168168
let cloud = Cloud(functionJobName: "test")
169-
_ = try cloud.callFunction()
169+
_ = try cloud.runFunction()
170170
XCTFail("Should have thrown ParseError")
171171
} catch {
172172
if let error = error as? ParseError {
@@ -181,7 +181,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
181181

182182
let expectation1 = XCTestExpectation(description: "Logout user1")
183183
let cloud = Cloud(functionJobName: "test")
184-
cloud.callFunction(callbackQueue: callbackQueue) { result in
184+
cloud.runFunction(callbackQueue: callbackQueue) { result in
185185

186186
switch result {
187187

@@ -239,7 +239,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
239239

240240
let expectation1 = XCTestExpectation(description: "Logout user1")
241241
let cloud = Cloud(functionJobName: "test")
242-
cloud.callFunction(callbackQueue: callbackQueue) { result in
242+
cloud.runFunction(callbackQueue: callbackQueue) { result in
243243

244244
switch result {
245245

@@ -272,7 +272,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
272272

273273
func testCallJobCommand() throws {
274274
let cloud = Cloud(functionJobName: "test")
275-
let command = cloud.callJobCommand()
275+
let command = cloud.startJobCommand()
276276
XCTAssertNotNil(command)
277277
XCTAssertEqual(command.path.urlComponent, "/jobs/test")
278278
XCTAssertEqual(command.method, API.Method.POST)
@@ -282,7 +282,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
282282

283283
func testCallJobWithArgsCommand() throws {
284284
let cloud = Cloud2(functionJobName: "test", customKey: "parse")
285-
let command = cloud.callJobCommand()
285+
let command = cloud.startJobCommand()
286286
XCTAssertNotNil(command)
287287
XCTAssertEqual(command.path.urlComponent, "/jobs/test")
288288
XCTAssertEqual(command.method, API.Method.POST)
@@ -304,7 +304,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
304304
}
305305
do {
306306
let cloud = Cloud(functionJobName: "test")
307-
let functionResponse = try cloud.callJob()
307+
let functionResponse = try cloud.startJob()
308308
XCTAssertEqual(functionResponse, AnyCodable())
309309
} catch {
310310
XCTFail(error.localizedDescription)
@@ -325,7 +325,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
325325
}
326326
do {
327327
let cloud = Cloud(functionJobName: "test")
328-
let functionResponse = try cloud.callJob()
328+
let functionResponse = try cloud.startJob()
329329
guard let resultAsDictionary = functionResponse.value as? [String: String] else {
330330
XCTFail("Should have casted result to dictionary")
331331
return
@@ -353,7 +353,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
353353
}
354354
do {
355355
let cloud = Cloud(functionJobName: "test")
356-
_ = try cloud.callJob()
356+
_ = try cloud.startJob()
357357
XCTFail("Should have thrown ParseError")
358358
} catch {
359359
if let error = error as? ParseError {
@@ -368,7 +368,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
368368

369369
let expectation1 = XCTestExpectation(description: "Logout user1")
370370
let cloud = Cloud(functionJobName: "test")
371-
cloud.callJob(callbackQueue: callbackQueue) { result in
371+
cloud.startJob(callbackQueue: callbackQueue) { result in
372372

373373
switch result {
374374

@@ -426,7 +426,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
426426

427427
let expectation1 = XCTestExpectation(description: "Logout user1")
428428
let cloud = Cloud(functionJobName: "test")
429-
cloud.callJob(callbackQueue: callbackQueue) { result in
429+
cloud.startJob(callbackQueue: callbackQueue) { result in
430430

431431
switch result {
432432

0 commit comments

Comments
 (0)