Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.0
// swift-tools-version:5.1

import PackageDescription

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct Cloud: ParseCloud {
*/
let cloud = Cloud(functionJobName: "hello")

cloud.callFunction { result in
cloud.runFunction { result in
switch result {
case .success(let response):
print("Response from cloud function: \(response)")
Expand All @@ -33,6 +33,7 @@ cloud.callFunction { result in
}
}

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

//: [Next](@next)
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,5 @@ print(explain)
let hint = try query2.find(explain: false, hint: "objectId")
print(hint)

PlaygroundPage.current.finishExecution()
//: [Next](@next)
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ author2.save { result in
}
}

PlaygroundPage.current.finishExecution()
//: [Next](@next)
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,6 @@ do {
/*: Files can also be saved from files located on your device by using:
let localFile = ParseFile(name: "hello.txt", localURL: URL)
*/

PlaygroundPage.current.finishExecution()
//: [Next](@next)
2 changes: 1 addition & 1 deletion ParseSwift.playground/contents.xcplayground
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
<page name='9 - Files'/>
<page name='10 - Cloud Code'/>
</pages>
</playground>
</playground>
3 changes: 1 addition & 2 deletions ParseSwift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ Pod::Spec.new do |s|
:git => "#{s.homepage}.git",
:tag => "#{s.version}",
}
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '5.0' }
s.ios.deployment_target = "11.0"
s.osx.deployment_target = "10.13"
s.tvos.deployment_target = "11.0"
s.watchos.deployment_target = "4.0"
s.swift_versions = ['5.0']
s.swift_versions = ['5.1', '5.2', '5.3']
s.source_files = "Sources/ParseSwift/**/*.swift"
s.license = {
:type => "MIT",
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Objects/ParseInstallation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import AppKit
`ParseInstallation` installations which have a valid `deviceToken` and are saved to
the Parse cloud can be used to target push notifications.

- warning: Only use `ParseInstallation` installations on the main thread as they
- warning: Only use `ParseInstallation.current` installations on the main thread as they
require UIApplication for `badge`
*/
public protocol ParseInstallation: ParseObject {
Expand Down
36 changes: 18 additions & 18 deletions Sources/ParseSwift/Types/ParseCloud.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,30 @@ public protocol ParseCloud: ParseType, Decodable, CustomDebugStringConvertible {
extension ParseCloud {

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

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

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

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

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

internal func callJobCommand() -> API.Command<Self, AnyCodable> {
internal func startJobCommand() -> API.Command<Self, AnyCodable> {
return API.Command(method: .POST,
path: .jobs(name: functionJobName),
body: self) { (data) -> AnyCodable in
Expand Down
28 changes: 14 additions & 14 deletions Tests/ParseSwiftTests/ParseCloudTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length

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

func testCallFunctionWithArgsCommand() throws {
let cloud = Cloud2(functionJobName: "test", customKey: "parse")
let command = cloud.callFunctionCommand()
let command = cloud.runFunctionCommand()
XCTAssertNotNil(command)
XCTAssertEqual(command.path.urlComponent, "/functions/test")
XCTAssertEqual(command.method, API.Method.POST)
Expand All @@ -115,7 +115,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
}
do {
let cloud = Cloud(functionJobName: "test")
let functionResponse = try cloud.callFunction()
let functionResponse = try cloud.runFunction()
XCTAssertEqual(functionResponse, AnyCodable())
} catch {
XCTFail(error.localizedDescription)
Expand All @@ -138,7 +138,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
}
do {
let cloud = Cloud(functionJobName: "test")
let functionResponse = try cloud.callFunction()
let functionResponse = try cloud.runFunction()
guard let resultAsDictionary = functionResponse.value as? [String: String] else {
XCTFail("Should have casted result to dictionary")
return
Expand Down Expand Up @@ -166,7 +166,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
}
do {
let cloud = Cloud(functionJobName: "test")
_ = try cloud.callFunction()
_ = try cloud.runFunction()
XCTFail("Should have thrown ParseError")
} catch {
if let error = error as? ParseError {
Expand All @@ -181,7 +181,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length

let expectation1 = XCTestExpectation(description: "Logout user1")
let cloud = Cloud(functionJobName: "test")
cloud.callFunction(callbackQueue: callbackQueue) { result in
cloud.runFunction(callbackQueue: callbackQueue) { result in

switch result {

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

let expectation1 = XCTestExpectation(description: "Logout user1")
let cloud = Cloud(functionJobName: "test")
cloud.callFunction(callbackQueue: callbackQueue) { result in
cloud.runFunction(callbackQueue: callbackQueue) { result in

switch result {

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

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

func testCallJobWithArgsCommand() throws {
let cloud = Cloud2(functionJobName: "test", customKey: "parse")
let command = cloud.callJobCommand()
let command = cloud.startJobCommand()
XCTAssertNotNil(command)
XCTAssertEqual(command.path.urlComponent, "/jobs/test")
XCTAssertEqual(command.method, API.Method.POST)
Expand All @@ -304,7 +304,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
}
do {
let cloud = Cloud(functionJobName: "test")
let functionResponse = try cloud.callJob()
let functionResponse = try cloud.startJob()
XCTAssertEqual(functionResponse, AnyCodable())
} catch {
XCTFail(error.localizedDescription)
Expand All @@ -325,7 +325,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
}
do {
let cloud = Cloud(functionJobName: "test")
let functionResponse = try cloud.callJob()
let functionResponse = try cloud.startJob()
guard let resultAsDictionary = functionResponse.value as? [String: String] else {
XCTFail("Should have casted result to dictionary")
return
Expand Down Expand Up @@ -353,7 +353,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
}
do {
let cloud = Cloud(functionJobName: "test")
_ = try cloud.callJob()
_ = try cloud.startJob()
XCTFail("Should have thrown ParseError")
} catch {
if let error = error as? ParseError {
Expand All @@ -368,7 +368,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length

let expectation1 = XCTestExpectation(description: "Logout user1")
let cloud = Cloud(functionJobName: "test")
cloud.callJob(callbackQueue: callbackQueue) { result in
cloud.startJob(callbackQueue: callbackQueue) { result in

switch result {

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

let expectation1 = XCTestExpectation(description: "Logout user1")
let cloud = Cloud(functionJobName: "test")
cloud.callJob(callbackQueue: callbackQueue) { result in
cloud.startJob(callbackQueue: callbackQueue) { result in

switch result {

Expand Down