forked from parse-community/Parse-SDK-Flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_function.dart
46 lines (40 loc) · 1.64 KB
/
parse_function.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
part of flutter_parse_sdk;
class ParseCloudFunction extends ParseObject {
final String functionName;
@override
String _path;
/// Creates a new cloud function object
///
/// {https://docs.parseplatform.org/cloudcode/guide/}
ParseCloudFunction(this.functionName,
{bool debug, ParseHTTPClient client, bool autoSendSessionId})
: super(functionName) {
_path = "/functions/$functionName";
_debug = isDebugEnabled(objectLevelDebug: debug);
_client = client ??
ParseHTTPClient(
autoSendSessionId:
autoSendSessionId ?? ParseCoreData().autoSendSessionId,
securityContext: ParseCoreData().securityContext);
}
/// Executes a cloud function
///
/// To add the parameters, create an object and call [set](value to set)
execute({Map parameters, Map headers}) async {
var uri = _client.data.serverUrl + "$_path";
if (parameters != null) setObjectData(parameters);
var result = await _client.post(uri, body: json.encode(getObjectData()));
return handleResponse(this, result, ParseApiRQ.execute, _debug, className);
}
/// Executes a cloud function that returns a ParseObject type
///
/// To add the parameters, create an object and call [set](value to set)
Future<ParseResponse> executeObjectFunction<T extends ParseObject>(
{Map parameters, Map headers}) async {
var uri = _client.data.serverUrl + "$_path";
if (parameters != null) setObjectData(parameters);
var result = await _client.post(uri, body: json.encode(getObjectData()));
return handleResponse<T>(
this, result, ParseApiRQ.executeObjectionFunction, _debug, className);
}
}