From ef0bf13ea37c959eae6ea5d43ae7ab16cf9205ea Mon Sep 17 00:00:00 2001 From: Phill Date: Mon, 28 Jan 2019 17:22:47 +0000 Subject: [PATCH 01/18] Version 1.0.11 - Cody tidy, added clientKey, proper encoding for extensions of ParseObject --- .idea/workspace.xml | 543 +-- lib/parse.dart | 2 + lib/src/data/parse_core_data.dart | 7 +- lib/src/network/parse_http_client.dart | 6 +- lib/src/objects/parse_base.dart | 9 +- lib/src/objects/parse_clonable.dart | 2 +- lib/src/objects/parse_error.dart | 110 +- lib/src/objects/parse_file.dart | 8 +- lib/src/objects/parse_function.dart | 3 +- lib/src/objects/parse_object.dart | 37 +- lib/src/objects/parse_response.dart | 43 +- lib/src/objects/parse_user.dart | 17 +- lib/src/utils/parse_encoder.dart | 14 +- lib/src/utils/parse_file_extensions.dart | 4928 ++++++---------------- lib/src/utils/parse_logger.dart | 10 +- 15 files changed, 1658 insertions(+), 4081 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3e9d93ecd..9b9ca9d9b 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -11,21 +11,23 @@ - - - - - - + + + + + + + + - - + + @@ -89,142 +91,50 @@ + - + - - + + - - + + - - + + - - + + - + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -271,14 +181,13 @@ @@ -358,26 +268,34 @@ - + + - + + + + + + + + @@ -410,12 +328,12 @@ - + - + @@ -431,124 +349,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -821,10 +628,9 @@ - - + - + @@ -834,7 +640,7 @@ - + @@ -844,8 +650,8 @@ - - + + @@ -923,7 +729,8 @@ - @@ -933,20 +740,6 @@ 173 + + - - - - - - - - - + + + - - - - @@ -99,27 +91,29 @@ - - + + - - + + - + + - + + @@ -134,7 +128,105 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -155,7 +247,6 @@ encode( Json() saV - save Json contains limit @@ -168,6 +259,7 @@ save( keys List< + save part @@ -188,7 +280,6 @@ @@ -265,6 +357,12 @@ + + + + + + @@ -328,7 +426,7 @@ - + @@ -615,7 +713,21 @@ @@ -628,9 +740,9 @@ - + - + @@ -640,8 +752,8 @@ - - + + @@ -650,7 +762,7 @@ - + @@ -730,7 +842,9 @@ - @@ -740,6 +854,46 @@ 173 - - @@ -934,13 +1086,6 @@ - - - - - - - @@ -955,164 +1100,181 @@ - + - - - - - + + - + - - - - - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + + + + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + + + + + - - + + - + - - + + - + - - + + - + - - + + + + + + + + + + + + + + + + + + + diff --git a/example/lib/main.dart b/example/lib/main.dart index 836505145..c110da309 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_plugin_example/application_constants.dart'; import 'package:flutter_plugin_example/diet_plan.dart'; +import 'package:flutter_plugin_example/subscription.dart'; import 'package:parse_server_sdk/parse.dart'; void main() => runApp(new MyApp()); @@ -49,15 +50,16 @@ class _MyAppState extends State { } runTestQueries() { - createItem(); - getAllItems(); - getAllItemsByName(); - getSingleItem(); - getConfigs(); - query(); - function(); - functionWithParameters(); - initUser(); + //createItem(); + //getAllItems(); + //getAllItemsByName(); + //getSingleItem(); + //getConfigs(); + //query(); + //function(); + //functionWithParameters(); + //initUser(); + test(); } void createItem() async { @@ -178,12 +180,12 @@ class _MyAppState extends State { } function() { - var function = ParseCloudFunction('testFunction'); + var function = ParseCloudFunction('hello'); function.execute(); } functionWithParameters() async { - var function = ParseCloudFunction('testFunction'); + var function = ParseCloudFunction('hello'); var params = {'plan': 'paid'}; function.execute(parameters: params); } @@ -202,4 +204,15 @@ class _MyAppState extends State { print("We have our configs."); } } + + Future test() async { + var operator = ParseObject('operator'); + operator.set('objectId', "npTxjstsAe"); + + var query = QueryBuilder(SubscriptionParse()) + ..whereEqualTo('operator', operator); + + var result = await query.query(); + var response = result; + } } diff --git a/example/lib/subscription.dart b/example/lib/subscription.dart new file mode 100644 index 000000000..7d2a7b411 --- /dev/null +++ b/example/lib/subscription.dart @@ -0,0 +1,31 @@ +import 'package:parse_server_sdk/parse.dart'; + +class SubscriptionParse extends ParseObject implements ParseCloneable { + SubscriptionParse() : super(_keyTableName); + SubscriptionParse.clone() : this(); + + @override + clone(Map map) => SubscriptionParse.clone()..fromJson(map); + + static const String _keyTableName = 'Subscription'; + static const String _keyObjectID = 'objectId'; + static const String _keyOperator = 'operator'; + static const String _keyName = 'name'; + static const String _keyDescription = 'description'; + static const String _keyLogo = 'logo'; + + String get name => get(_keyName); + set name(String name) => set(_keyName, name); + + String get description => get(_keyDescription); + set description(String name) => set(_keyDescription, description); + + String get logo => get(_keyLogo); + set logo(String logo) => set(_keyLogo, logo); + + String get objectId => get(_keyObjectID); + set objectId(String objectId) => set(_keyObjectID, objectId); + + String get operatorID => get(_keyOperator).toString(); + set operatorID(String operator) => set(_keyOperator, operator); +} \ No newline at end of file diff --git a/lib/src/network/parse_query.dart b/lib/src/network/parse_query.dart index 512613585..1f8155aad 100644 --- a/lib/src/network/parse_query.dart +++ b/lib/src/network/parse_query.dart @@ -230,7 +230,7 @@ class QueryBuilder { MapEntry _buildQueryWithColumnValueAndOperator( MapEntry columnAndValue, String queryOperator) { var key = columnAndValue.key; - var value = convertValueToCorrectType(columnAndValue.value); + var value = parseEncode(columnAndValue.value); if (queryOperator == _NO_OPERATOR_NEEDED) { return MapEntry(_NO_OPERATOR_NEEDED, "\"${columnAndValue.key}\": $value"); diff --git a/lib/src/objects/parse_config.dart b/lib/src/objects/parse_config.dart index 037424603..32bc39f52 100644 --- a/lib/src/objects/parse_config.dart +++ b/lib/src/objects/parse_config.dart @@ -24,7 +24,7 @@ class ParseConfig extends ParseObject { Future addConfig(String key, dynamic value) async { try { var uri = "${ParseCoreData().serverUrl}/config"; - var body = "{\"params\":{\"$key\": ${convertValueToCorrectType(value)}}}"; + var body = "{\"params\":{\"$key\": ${parseEncode(value)}}}"; var result = await _client.put(uri, body: body); return handleResponse(result, ParseApiRQ.addConfig); } on Exception catch (e) { diff --git a/lib/src/objects/parse_object.dart b/lib/src/objects/parse_object.dart index ff937fbb8..2d190e27f 100644 --- a/lib/src/objects/parse_object.dart +++ b/lib/src/objects/parse_object.dart @@ -68,7 +68,7 @@ class ParseObject extends ParseBase implements ParseCloneable { /// Saves the current object online Future save() async { - if (getObjectData() == null) { + if (getObjectData()[keyVarObjectId] == null) { return create(); } else { try { diff --git a/lib/src/utils/parse_encoder.dart b/lib/src/utils/parse_encoder.dart index 3d853630b..b0a7ba857 100644 --- a/lib/src/utils/parse_encoder.dart +++ b/lib/src/utils/parse_encoder.dart @@ -18,6 +18,10 @@ dynamic parseEncode(dynamic value) { }).toList(); } + if (value is String) { + return "\"$value\""; + } + if (value is ParseObject) { return _encodeObject(value); } @@ -52,14 +56,3 @@ String _encodeObject(ParseObject object) { String _encodeDate(DateTime date) { return "{\"__type\": \"Date\", \"iso\": \"${date.toIso8601String()}\"}"; } - -/// Converts the object to the correct value for JSON, -/// -/// Strings are wrapped with "" but ints and others are not -convertValueToCorrectType(dynamic value) { - if (value is String) { - return "\"$value\""; - } else { - return parseEncode(value); - } -} From f771cd65407aa5935d4af6c00692903869a3e4b6 Mon Sep 17 00:00:00 2001 From: Phill Date: Tue, 29 Jan 2019 19:34:39 +0000 Subject: [PATCH 05/18] Version 1.0.10 - Fixed ParseUser.getCurrentFromServer(), also made static. --- .idea/workspace.xml | 423 ++++++++++++---------------- example/lib/main.dart | 20 +- lib/src/network/parse_query.dart | 3 +- lib/src/objects/parse_config.dart | 10 +- lib/src/objects/parse_file.dart | 2 +- lib/src/objects/parse_function.dart | 2 +- lib/src/objects/parse_object.dart | 79 ++---- lib/src/objects/parse_response.dart | 46 +++ lib/src/objects/parse_user.dart | 80 ++++-- lib/src/utils/parse_encoder.dart | 4 - lib/src/utils/parse_utils.dart | 11 + 11 files changed, 314 insertions(+), 366 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ecd3051c7..4da4bab41 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -11,15 +11,18 @@ - - + + + + + @@ -84,35 +87,36 @@ + - + - - + + - - + + - + - + @@ -132,8 +136,8 @@ - - + + @@ -142,86 +146,10 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -230,7 +158,6 @@ - bad client send getObjectData()[key] @@ -260,6 +187,7 @@ keys List< save + _buildQuer part @@ -270,6 +198,7 @@ + - @@ -345,6 +275,8 @@ + + @@ -374,13 +306,6 @@ - - - - - - - @@ -388,13 +313,6 @@ - - - - - - - @@ -420,8 +338,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1546881355795 - - - 1546884752230 - - - 1546887791210 - - - 1546888097714 - - - 1546888309324 - - - 1546894981978 - - - 1546895042011 - - - 1547051168221 - - - 1547051408891 - - - 1547051451156 - - - 1547121632281 - - - 1547127880224 - - - 1547128670936 - - - 1547394980625 - - - 1547834571185 - - - 1547834610762 - - - 1547834711831 - - - 1547842562998 - - - 1547895940859 - - - 1547896458167 - - - 1547973997864 - - - 1547974045562 - - - 1548094104132 - - - 1548094233253 - - - 1548094716747 - - - 1548348889225 - - - 1548349115898 - - - 1548355057025 - - - 1548696167570 - - - 1548698510580 - - - 1548706749533 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - file://$PROJECT_DIR$/example/lib/main.dart - 149 - - - file://$PROJECT_DIR$/example/lib/main.dart - 151 - - - file://$PROJECT_DIR$/example/lib/main.dart - 152 - - - file://$PROJECT_DIR$/example/lib/main.dart - 153 - - - file://$PROJECT_DIR$/example/lib/main.dart - 156 - - - file://$PROJECT_DIR$/example/lib/main.dart - 146 - - - file://$PROJECT_DIR$/example/lib/main.dart - 147 - - - file://$PROJECT_DIR$/example/lib/main.dart - 155 - - - - - - - - - - - - - json.decode(apiResponse.body) - Dart - EXPRESSION - - - json.decode(apiResponse.body); - Dart - EXPRESSION - - - Map<String, dynamic> responseData = json.decode(apiResponse.body); - Dart - EXPRESSION - - - getObjectData() - Dart - EXPRESSION - - - await ParseCoreData().getStore().getString(key) - Dart - EXPRESSION - - - await ParseCoreData().getStore().setString(key, toJson()) - Dart - EXPRESSION - - - ParseCoreData().getStore().setString(key, toJson()) - Dart - EXPRESSION - - - ParseCoreData().getStore().setString(key, toJson()); - Dart - EXPRESSION - - - emailAddress - Dart - EXPRESSION - - - resultsList.first.objectId - Dart - EXPRESSION - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - No facets are configured - - - - - - - - - - - - - - - 1.8 - - - - - - - - flutter_parse_sdk - - - - - - - - 1.8 - - - - - - - - Dart SDK - - - - - - - - \ No newline at end of file From 6263f775fc583e1d18da8bac221a951119e758ea Mon Sep 17 00:00:00 2001 From: Pablo Cegarra Date: Sun, 3 Feb 2019 13:19:40 +0100 Subject: [PATCH 14/18] add .idea to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ef9050e70..b75bc42af 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ pubspec.lock .example/lib/application_constants.dart build/ +.idea From d747937b2d2961dbc4adf8ccb6dce1952c839f31 Mon Sep 17 00:00:00 2001 From: Pablo Cegarra Date: Sun, 3 Feb 2019 15:47:27 +0100 Subject: [PATCH 15/18] testing parse builder configuration --- pubspec.yaml | 11 +++++++++- test/parse_client_configuration_test.dart | 25 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/parse_client_configuration_test.dart diff --git a/pubspec.yaml b/pubspec.yaml index c25a51adb..dce62388c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,4 +17,13 @@ dependencies: # Utils shared_preferences: ^0.4.3 - path_provider: ^0.4.1 \ No newline at end of file + path_provider: ^0.4.1 + + + + +dev_dependencies: + # Testing + test: ^1.5.1 + flutter_test: + sdk: flutter diff --git a/test/parse_client_configuration_test.dart b/test/parse_client_configuration_test.dart new file mode 100644 index 000000000..ae47e0f62 --- /dev/null +++ b/test/parse_client_configuration_test.dart @@ -0,0 +1,25 @@ +import 'package:test/test.dart'; +import 'package:parse_server_sdk/parse.dart'; + +void main(){ + test("testBuilder",() { + Parse().initialize("appId", + "serverUrl", + clientKey: "clientKey", + liveQueryUrl: "liveQueryUrl", + appName: "appName", + masterKey: "masterKey", + sessionId: "sessionId", + debug: true); + + expect(ParseCoreData().applicationId, "appId"); + expect(ParseCoreData().serverUrl, "serverUrl"); + expect(ParseCoreData().clientKey, "clientKey"); + expect(ParseCoreData().liveQueryURL, "liveQueryUrl"); + expect(ParseCoreData().appName, "appName"); + expect(ParseCoreData().masterKey, "masterKey"); + expect(ParseCoreData().sessionId, "sessionId"); + expect(ParseCoreData().debug, true); + + }); +} \ No newline at end of file From e3889e2edd12a0a0b2db312797a70dc5ac81b92c Mon Sep 17 00:00:00 2001 From: Phill Date: Tue, 5 Feb 2019 18:55:27 +0000 Subject: [PATCH 16/18] Merge branches 'develop' and 'master' of https://github.com/phillwiggins/flutter_parse_sdk # Conflicts: # .idea/libraries/Dart_Packages.xml # lib/src/objects/parse_file.dart # lib/src/objects/parse_user.dart # pubspec.yaml --- example/lib/main.dart | 24 ++++---------- example/lib/subscription.dart | 31 ------------------ lib/src/objects/parse_file.dart | 53 +++++++++++++++++++++++++++++-- lib/src/objects/parse_object.dart | 3 +- pubspec.yaml | 6 ++-- 5 files changed, 61 insertions(+), 56 deletions(-) delete mode 100644 example/lib/subscription.dart diff --git a/example/lib/main.dart b/example/lib/main.dart index 43027d2e9..0d6c866bf 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_plugin_example/application_constants.dart'; import 'package:flutter_plugin_example/diet_plan.dart'; -import 'package:flutter_plugin_example/subscription.dart'; import 'package:parse_server_sdk/parse.dart'; void main() => runApp(new MyApp()); @@ -59,7 +58,6 @@ class _MyAppState extends State { initUser(); function(); functionWithParameters(); - test(); } void createItem() async { @@ -139,7 +137,8 @@ class _MyAppState extends State { initUser() async { // All return type ParseUser except all - var user = ParseUser("TestFlutter", "TestPassword123", "TestFlutterSDK@gmail.com"); + var user = + ParseUser("TestFlutter", "TestPassword123", "TestFlutterSDK@gmail.com"); var response = await user.signUp(); if (response.success) user = response.result; @@ -179,14 +178,16 @@ class _MyAppState extends State { } function() async { - - var user = ParseUser("TestFlutter", "TestPassword123", "TestFlutterSDK@gmail.com"); + var user = + ParseUser("TestFlutter", "TestPassword123", "TestFlutterSDK@gmail.com"); await user.signUp(); var loginResponse = await user.login(); if (loginResponse.success) user = loginResponse.result; var customClient = ParseHTTPClient(); - customClient.additionalHeaders = { keyHeaderSessionToken: ParseCoreData().sessionId }; + customClient.additionalHeaders = { + keyHeaderSessionToken: ParseCoreData().sessionId + }; var function = ParseCloudFunction('hello', client: customClient); function.execute(); @@ -213,15 +214,4 @@ class _MyAppState extends State { print("We have our configs."); } } - - Future test() async { - var operator = ParseObject('operator'); - operator.set('objectId', "npTxjstsAe"); - - var query = QueryBuilder(SubscriptionParse()) - ..whereEqualTo('operator', operator); - - var result = await query.query(); - var response = result; - } } diff --git a/example/lib/subscription.dart b/example/lib/subscription.dart deleted file mode 100644 index 7d2a7b411..000000000 --- a/example/lib/subscription.dart +++ /dev/null @@ -1,31 +0,0 @@ -import 'package:parse_server_sdk/parse.dart'; - -class SubscriptionParse extends ParseObject implements ParseCloneable { - SubscriptionParse() : super(_keyTableName); - SubscriptionParse.clone() : this(); - - @override - clone(Map map) => SubscriptionParse.clone()..fromJson(map); - - static const String _keyTableName = 'Subscription'; - static const String _keyObjectID = 'objectId'; - static const String _keyOperator = 'operator'; - static const String _keyName = 'name'; - static const String _keyDescription = 'description'; - static const String _keyLogo = 'logo'; - - String get name => get(_keyName); - set name(String name) => set(_keyName, name); - - String get description => get(_keyDescription); - set description(String name) => set(_keyDescription, description); - - String get logo => get(_keyLogo); - set logo(String logo) => set(_keyLogo, logo); - - String get objectId => get(_keyObjectID); - set objectId(String objectId) => set(_keyObjectID, objectId); - - String get operatorID => get(_keyOperator).toString(); - set operatorID(String operator) => set(_keyOperator, operator); -} \ No newline at end of file diff --git a/lib/src/objects/parse_file.dart b/lib/src/objects/parse_file.dart index ee7db528d..0e6082701 100644 --- a/lib/src/objects/parse_file.dart +++ b/lib/src/objects/parse_file.dart @@ -12,6 +12,12 @@ class ParseFile extends ParseObject { String get url => _fileUrl; + File get file => _file; + + set url(String url) => _fileUrl = url; + + set name(String name) => _fileName = name; + bool get saved => url != null; @override @@ -24,12 +30,53 @@ class ParseFile extends ParseObject { /// Creates a new file /// /// {https://docs.parseplatform.org/rest/guide/#files/} - ParseFile(this._file, {bool debug, ParseHTTPClient client}) : super(keyFile) { + ParseFile(this._file, + {String name, String url, bool debug, ParseHTTPClient client}) + : super(keyFile) { client == null ? _client = ParseHTTPClient() : _client = client; _debug = isDebugEnabled(objectLevelDebug: debug); + if (_file != null) { + this._fileName = path.basename(_file.path); + this._path = 'files/$_fileName'; + } else { + this._fileName = name; + this._fileUrl = url; + } + } + + Future loadStorage() async { + Directory tempPath = await getTemporaryDirectory(); + + if (_fileName == null) { + _file = null; + return this; + } + + File possibleFile = new File("${tempPath.path}/$_fileName"); + bool exists = await possibleFile.exists(); + + if (exists) { + _file = possibleFile; + } else { + _file = null; + } + + return this; + } + + Future download() async { + if (_fileUrl == null) { + return this; + } + + Directory tempPath = await getTemporaryDirectory(); + this._file = new File("${tempPath.path}/$_fileName"); + await _file.create(); + + var response = await _client.get(_fileUrl); + _file.writeAsBytes(response.bodyBytes); - this._fileName = path.basename(_file.path); - this._path = 'files/$_fileName'; + return this; } /// Uploads a file to Parse Server diff --git a/lib/src/objects/parse_object.dart b/lib/src/objects/parse_object.dart index b9d2bed30..b5d1256e3 100644 --- a/lib/src/objects/parse_object.dart +++ b/lib/src/objects/parse_object.dart @@ -1,7 +1,8 @@ part of flutter_parse_sdk; class ParseObject extends ParseBase implements ParseCloneable { - ParseObject.clone(String className) : this('className'); + + ParseObject.clone(String className) : this(className); @override clone(Map map) => ParseObject.clone(className)..fromJson(map); diff --git a/pubspec.yaml b/pubspec.yaml index dce62388c..7ed5bd270 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,12 +18,10 @@ dependencies: # Utils shared_preferences: ^0.4.3 path_provider: ^0.4.1 - - - + uuid: ^1.0.3 dev_dependencies: # Testing test: ^1.5.1 flutter_test: - sdk: flutter + sdk: flutter \ No newline at end of file From c8deb7b749fdb503282057fe67d8e4d8a9115d4c Mon Sep 17 00:00:00 2001 From: Phill Date: Tue, 5 Feb 2019 19:19:32 +0000 Subject: [PATCH 17/18] Merge branches 'develop' and 'master' of https://github.com/phillwiggins/flutter_parse_sdk # Conflicts: # .idea/libraries/Dart_Packages.xml # lib/src/objects/parse_file.dart # lib/src/objects/parse_user.dart # pubspec.yaml --- example/lib/main.dart | 14 ++++++------- lib/src/objects/parse_user.dart | 36 +++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 0d6c866bf..cee1b4c99 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -138,13 +138,19 @@ class _MyAppState extends State { initUser() async { // All return type ParseUser except all var user = - ParseUser("TestFlutter", "TestPassword123", "TestFlutterSDK@gmail.com"); + ParseUser("TestFlutter", "TestPassword123", "phill.wiggins@gmail.com"); var response = await user.signUp(); if (response.success) user = response.result; response = await user.login(); if (response.success) user = response.result; + response = await user.requestPasswordReset(); + if (response.success) user = response.result; + + response = await user.verificationEmailRequest(); + if (response.success) user = response.result; + user = null; // Best practice for starting the app. This will check for a valid user user = await ParseUser.currentUser(); @@ -154,12 +160,6 @@ class _MyAppState extends State { response = await ParseUser.getCurrentUserFromServer(); if (response.success) user = response.result; - response = await user.requestPasswordReset(); - if (response.success) user = response.result; - - response = await user.verificationEmailRequest(); - if (response.success) user = response.result; - response = await user.save(); if (response.success) user = response.result; diff --git a/lib/src/objects/parse_user.dart b/lib/src/objects/parse_user.dart index 8f80c509f..c216f2ff7 100644 --- a/lib/src/objects/parse_user.dart +++ b/lib/src/objects/parse_user.dart @@ -152,7 +152,7 @@ class ParseUser extends ParseObject implements ParseCloneable { keyVarPassword: password }); - final response = await _client.post(url, headers: { + final response = await _client.get(url, headers: { keyHeaderRevocableSession: "1", }); @@ -163,6 +163,36 @@ class ParseUser extends ParseObject implements ParseCloneable { } } + // Logs in a user anonymously + Future loginAnonymous() async { + try { + Uri tempUri = Uri.parse(_client.data.serverUrl); + + Uri url = Uri( + scheme: tempUri.scheme, + host: tempUri.host, + path: "${tempUri.path}$keyEndPointUsers", + ); + + var uuid = new Uuid(); + + final response = await _client.post(url, + headers: { + keyHeaderRevocableSession: "1", + }, + body: jsonEncode({ + "authData": { + "anonymous": {"id": uuid.v4()} + } + })); + + return _handleResponse( + this, response, ParseApiRQ.loginAnonymous, _debug, className); + } on Exception catch (e) { + return _handleException(e, ParseApiRQ.loginAnonymous, _debug, className); + } + } + /// Removes the current user from the session data logout() { _client.data.sessionId = null; @@ -210,7 +240,9 @@ class ParseUser extends ParseObject implements ParseCloneable { var uri = _client.data.serverUrl + "$path/$objectId"; var body = json.encode(toJson(forApiRQ: true), toEncodable: dateTimeEncoder); - final response = await _client.put(uri, body: body); + final response = await _client.put(uri, + headers: {keyHeaderSessionToken: _client.data.sessionId}, + body: body); return _handleResponse( this, response, ParseApiRQ.save, _debug, className); } on Exception catch (e) { From da7bd4cfd7d8beb5daecb0155011bdee8133a83b Mon Sep 17 00:00:00 2001 From: Phill Date: Wed, 6 Feb 2019 19:08:06 +0000 Subject: [PATCH 18/18] Added support for cloud functions that return ParseObjects --- lib/src/enums/parse_enum_api_rq.dart | 1 + lib/src/objects/parse_function.dart | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/src/enums/parse_enum_api_rq.dart b/lib/src/enums/parse_enum_api_rq.dart index 6166516ff..0d9d93db5 100644 --- a/lib/src/enums/parse_enum_api_rq.dart +++ b/lib/src/enums/parse_enum_api_rq.dart @@ -18,6 +18,7 @@ enum ParseApiRQ { destroy, all, execute, + executeObjectionFunction, upload, add, addAll, diff --git a/lib/src/objects/parse_function.dart b/lib/src/objects/parse_function.dart index ba9cf17ca..6c0e7e632 100644 --- a/lib/src/objects/parse_function.dart +++ b/lib/src/objects/parse_function.dart @@ -26,4 +26,16 @@ class ParseCloudFunction extends ParseObject { 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 executeObjectFunction( + {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.executeObjectionFunction, _debug, className); + } }