forked from parse-community/Parse-SDK-Flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_function.dart
67 lines (62 loc) · 2.19 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
part of '../../parse_server_sdk.dart';
class ParseCloudFunction extends ParseObject {
/// Creates a new cloud function object
///
/// {https://docs.parseplatform.org/cloudcode/guide/}
ParseCloudFunction(
this.functionName, {
bool? debug,
ParseClient? client,
bool? autoSendSessionId,
}) : super(
functionName,
client: client,
autoSendSessionId: autoSendSessionId,
debug: debug,
) {
_path = '/functions/$functionName';
}
final String functionName;
@override
// ignore: overridden_fields
late String _path;
/// Executes a cloud function
///
/// To add the parameters, create an object and call [set](value to set)
Future<ParseResponse> execute(
{Map<String, dynamic>? parameters, Map<String, String>? headers}) async {
final String uri = '${ParseCoreData().serverUrl}$_path';
if (parameters != null) {
_setObjectData(parameters);
}
try {
final ParseNetworkResponse result = await _client.post(uri,
options: ParseNetworkOptions(headers: headers),
data: json.encode(_getObjectData()));
return handleResponse<ParseCloudFunction>(
this, result, ParseApiRQ.execute, _debug, parseClassName);
} on Exception catch (e) {
return handleException(e, ParseApiRQ.execute, _debug, parseClassName);
}
}
/// 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<String, dynamic>? parameters, Map<String, String>? headers}) async {
final String uri = '${ParseCoreData().serverUrl}$_path';
if (parameters != null) {
_setObjectData(parameters);
}
try {
final ParseNetworkResponse result = await _client.post(uri,
options: ParseNetworkOptions(headers: headers),
data: json.encode(_getObjectData()));
return handleResponse<T>(this, result,
ParseApiRQ.executeObjectionFunction, _debug, parseClassName);
} on Exception catch (e) {
return handleException(
e, ParseApiRQ.executeObjectionFunction, _debug, parseClassName);
}
}
}