Skip to content

Commit 6e47d3d

Browse files
authored
Merge pull request #89 from phillwiggins/master
Rebasing
2 parents 82e554e + 4d26dae commit 6e47d3d

24 files changed

+242
-178
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 1.0.12
2+
Fixed logout
3+
4+
## 1.0.11
5+
ParseFile fixed
6+
Anonymous login
7+
SecurityContext
8+
CloudFunctions with objects
9+
110
## 1.0.10
211
Add ParseConfig.
312
Fixed whereEqualsTo('', PARSEOBJECT) and other queries

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Want to get involved? Join our Slack channel and help out! (http://flutter-parse
1313
To install, either add to your pubspec.yaml
1414
```
1515
dependencies:
16-
parse_server_sdk: ^1.0.10
16+
parse_server_sdk: ^1.0.12
1717
```
1818
or clone this repository and add to your project. As this is an early development with multiple contributors, it is probably best to download/clone and keep updating as an when a new feature is added.
1919

@@ -33,8 +33,11 @@ Parse().initialize(
3333
ApplicationConstants.keyApplicationId,
3434
ApplicationConstants.keyParseServerUrl,
3535
masterKey: ApplicationConstants.keyParseMasterKey,
36-
debug: true,
37-
liveQuery: true);
36+
clientKey: ApplicationConstants.keyParseClientKey,
37+
debug: true,
38+
liveQuery: true,
39+
autoSendSessionId: true,
40+
securityContext: securityContext);
3841
```
3942

4043
## Queries

example/lib/diet_plan.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import 'dart:core';
22

3-
import 'package:parse_server_sdk/parse.dart';
3+
import 'package:parse_server_sdk/parse_server_sdk.dart';
44

55
class DietPlan extends ParseObject implements ParseCloneable {
6-
76
DietPlan() : super(_keyTableName);
8-
DietPlan.clone(): this();
7+
DietPlan.clone() : this();
98

109
/// Looks strangely hacky but due to Flutter not using reflection, we have to
1110
/// mimic a clone
12-
@override clone(Map map) => DietPlan.clone()..fromJson(map);
11+
@override
12+
clone(Map map) => DietPlan.clone()..fromJson(map);
1313

1414
static const String _keyTableName = 'Diet_Plans';
1515
static const String keyName = 'Name';

example/lib/main.dart

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_plugin_example/application_constants.dart';
33
import 'package:flutter_plugin_example/diet_plan.dart';
4-
import 'package:parse_server_sdk/parse.dart';
4+
import 'package:parse_server_sdk/parse_server_sdk.dart';
55

66
void main() => runApp(new MyApp());
77

@@ -155,9 +155,14 @@ class _MyAppState extends State<MyApp> {
155155
// Best practice for starting the app. This will check for a valid user
156156
user = await ParseUser.currentUser();
157157
await user.logout();
158-
user = await ParseUser.currentUser();
159158

160-
response = await ParseUser.getCurrentUserFromServer();
159+
user =
160+
ParseUser("TestFlutter", "TestPassword123", "phill.wiggins@gmail.com");
161+
response = await user.login();
162+
if (response.success) user = response.result;
163+
164+
response = await ParseUser.getCurrentUserFromServer(
165+
token: user.get(keyHeaderSessionToken));
161166
if (response.success) user = response.result;
162167

163168
response = await user.save();
@@ -178,20 +183,13 @@ class _MyAppState extends State<MyApp> {
178183
}
179184

180185
function() async {
181-
var user =
182-
ParseUser("TestFlutter", "TestPassword123", "TestFlutterSDK@gmail.com");
183-
await user.signUp();
184-
var loginResponse = await user.login();
185-
if (loginResponse.success) user = loginResponse.result;
186-
187-
var customClient = ParseHTTPClient();
188-
customClient.additionalHeaders = {
189-
keyHeaderSessionToken: ParseCoreData().sessionId
190-
};
191-
var function = ParseCloudFunction('hello', client: customClient);
192-
function.execute();
193-
194-
user.destroy();
186+
var function = ParseCloudFunction('hello');
187+
var result = await function.executeObjectFunction<ParseObject>();
188+
if (result.success) {
189+
if (result.result is ParseObject) {
190+
print((result.result as ParseObject).className);
191+
}
192+
}
195193
}
196194

197195
functionWithParameters() async {

lib/parse.dart renamed to lib/parse_server_sdk.dart

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ part 'src/enums/parse_enum_api_rq.dart';
2222

2323
part 'src/network/parse_http_client.dart';
2424

25-
part 'src/network/parse_livequery.dart';
25+
part 'src/network/parse_live_query.dart';
2626

2727
part 'src/network/parse_query.dart';
2828

2929
part 'src/objects/parse_base.dart';
3030

31-
part 'src/objects/parse_clonable.dart';
31+
part 'src/objects/parse_cloneable.dart';
3232

3333
part 'src/objects/parse_config.dart';
3434

@@ -58,11 +58,11 @@ part 'src/utils/parse_utils.dart';
5858

5959
class Parse {
6060
ParseCoreData data;
61-
bool _hasBeenInitialised = false;
61+
bool _hasBeenInitialized = false;
6262

63-
/// To initialise Parse Server in your application
63+
/// To initialize Parse Server in your application
6464
///
65-
/// This should be initialised in MyApp() creation
65+
/// This should be initialized in MyApp() creation
6666
///
6767
/// ```
6868
/// Parse().initialize(
@@ -79,6 +79,7 @@ class Parse {
7979
String clientKey,
8080
String masterKey,
8181
String sessionId,
82+
bool autoSendSessionId,
8283
SecurityContext securityContext}) {
8384
ParseCoreData.init(appId, serverUrl,
8485
debug: debug,
@@ -87,30 +88,37 @@ class Parse {
8788
masterKey: masterKey,
8889
clientKey: clientKey,
8990
sessionId: sessionId,
91+
autoSendSessionId: autoSendSessionId,
9092
securityContext: securityContext);
9193

92-
ParseCoreData().initStorage();
93-
94-
_hasBeenInitialised = true;
94+
_hasBeenInitialized = true;
9595

9696
return Parse();
9797
}
9898

99-
bool hasParseBeenInitialised() => _hasBeenInitialised;
99+
bool hasParseBeenInitialized() => _hasBeenInitialized;
100100

101-
Future<ParseResponse> healthCheck() async {
101+
Future<ParseResponse> healthCheck(
102+
{bool debug, ParseHTTPClient client, bool autoSendSessionId}) async {
102103
ParseResponse parseResponse;
103104

105+
bool _debug = isDebugEnabled(objectLevelDebug: debug);
106+
ParseHTTPClient _client = client ??
107+
ParseHTTPClient(
108+
autoSendSessionId:
109+
autoSendSessionId ?? ParseCoreData().autoSendSessionId,
110+
securityContext: ParseCoreData().securityContext);
111+
104112
try {
105-
var response = await ParseHTTPClient(ParseCoreData().securityContext)
106-
.get("${ParseCoreData().serverUrl}$keyEndPointHealth");
113+
var response =
114+
await _client.get("${ParseCoreData().serverUrl}$keyEndPointHealth");
107115
parseResponse =
108116
ParseResponse.handleResponse(this, response, returnAsResult: true);
109117
} on Exception catch (e) {
110118
parseResponse = ParseResponse.handleException(e);
111119
}
112120

113-
if (ParseCoreData().debug) {
121+
if (_debug) {
114122
logger(ParseCoreData().appName, keyClassMain,
115123
ParseApiRQ.healthCheck.toString(), parseResponse);
116124
}

lib/src/base/parse_constants.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
part of flutter_parse_sdk;
22

33
// Library
4-
const String keySdkVersion = '1.0.10';
4+
const String keySdkVersion = '1.0.12';
55
const String keyLibraryName = 'Flutter Parse SDK';
66

77
// End Points
88
const String keyEndPointUserName = '/users/me';
99
const String keyEndPointLogin = '/login';
10+
const String keyEndPointLogout = '/logout';
1011
const String keyEndPointUsers = '/users';
1112
const String keyEndPointVerificationEmail = '/verificationEmailRequest';
1213
const String keyEndPointRequestPasswordReset = '/requestPasswordReset';
@@ -21,6 +22,7 @@ const String keyVarUpdatedAt = 'updatedAt';
2122
const String keyVarUsername = 'username';
2223
const String keyVarEmail = 'email';
2324
const String keyVarPassword = 'password';
25+
const String keyVarSessionToken = 'sessionToken';
2426
const String keyVarAcl = 'ACL';
2527

2628
// Classes

lib/src/data/parse_core_data.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ParseCoreData {
1717
masterKey,
1818
clientKey,
1919
sessionId,
20+
autoSendSessionId,
2021
securityContext}) {
2122
_instance = ParseCoreData._init(appId, serverUrl);
2223

@@ -26,6 +27,8 @@ class ParseCoreData {
2627
if (clientKey != null) _instance.clientKey = clientKey;
2728
if (masterKey != null) _instance.masterKey = masterKey;
2829
if (sessionId != null) _instance.sessionId = sessionId;
30+
if (autoSendSessionId != null)
31+
_instance.autoSendSessionId = autoSendSessionId;
2932
if (securityContext != null) _instance.securityContext = securityContext;
3033
}
3134

@@ -36,6 +39,7 @@ class ParseCoreData {
3639
String masterKey;
3740
String clientKey;
3841
String sessionId;
42+
bool autoSendSessionId;
3943
SecurityContext securityContext;
4044
bool debug;
4145
SharedPreferences storage;
@@ -52,12 +56,8 @@ class ParseCoreData {
5256
this.sessionId = sessionId;
5357
}
5458

55-
void initStorage() async {
56-
storage = await SharedPreferences.getInstance();
57-
}
58-
5959
Future<SharedPreferences> getStore() async {
60-
return storage != null ? storage : await SharedPreferences.getInstance();
60+
return storage ?? (storage = await SharedPreferences.getInstance());
6161
}
6262

6363
@override

lib/src/enums/parse_enum_api_rq.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ enum ParseApiRQ {
1212
currentUser,
1313
signUp,
1414
login,
15+
logout,
1516
loginAnonymous,
1617
verificationEmailRequest,
1718
requestPasswordReset,

lib/src/network/parse_http_client.dart

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ part of flutter_parse_sdk;
33
/// Creates a custom version of HTTP Client that has Parse Data Preset
44
class ParseHTTPClient extends BaseClient {
55
final Client _client;
6+
final bool _autoSendSessionId;
67
final String _userAgent = "$keyLibraryName $keySdkVersion";
78
ParseCoreData data = ParseCoreData();
89
Map<String, String> additionalHeaders;
910

10-
ParseHTTPClient([SecurityContext securityContext])
11-
: _client = securityContext != null
11+
ParseHTTPClient(
12+
{bool autoSendSessionId = false, SecurityContext securityContext})
13+
: _autoSendSessionId = autoSendSessionId,
14+
_client = securityContext != null
1215
? IOClient(HttpClient(context: securityContext))
1316
: IOClient();
1417

@@ -17,13 +20,19 @@ class ParseHTTPClient extends BaseClient {
1720
Future<StreamedResponse> send(BaseRequest request) {
1821
request.headers[keyHeaderUserAgent] = _userAgent;
1922
request.headers[keyHeaderApplicationId] = data.applicationId;
23+
if ((_autoSendSessionId == true) &&
24+
(data.sessionId != null) &&
25+
(request.headers[keyHeaderSessionToken] == null))
26+
request.headers[keyHeaderSessionToken] = data.sessionId;
2027

21-
if (data.clientKey != null) request.headers[keyHeaderClientKey] = data.clientKey;
22-
if (data.masterKey != null) request.headers[keyHeaderMasterKey] = data.masterKey;
28+
if (data.clientKey != null)
29+
request.headers[keyHeaderClientKey] = data.clientKey;
30+
if (data.masterKey != null)
31+
request.headers[keyHeaderMasterKey] = data.masterKey;
2332

2433
/// If developer wants to add custom headers, extend this class and add headers needed.
25-
if (additionalHeaders != null && additionalHeaders.length > 0){
26-
additionalHeaders.forEach((k,v) => request.headers[k] = v);
34+
if (additionalHeaders != null && additionalHeaders.length > 0) {
35+
additionalHeaders.forEach((k, v) => request.headers[k] = v);
2736
}
2837

2938
return _client.send(request);

lib/src/network/parse_query.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ class QueryBuilder<T extends ParseObject> {
2727
limiters['where'] = where;
2828
}
2929

30-
/// Orders the results ascedingly.
30+
/// Sorts the results in ascending order.
3131
///
3232
/// [String] order will be the column of the table that the results are
3333
/// ordered by
3434
void orderByAscending(String order) {
3535
limiters["order"] = order;
3636
}
3737

38-
/// Orders the results descendingly.
38+
/// Sorts the results descending order.
3939
///
4040
/// [String] order will be the column of the table that the results are
4141
/// ordered by
@@ -48,12 +48,12 @@ class QueryBuilder<T extends ParseObject> {
4848
/// [String] keys will only return the columns of a result you want the data for,
4949
/// this is useful for large objects
5050
void keysToReturn(List<String> keys) {
51-
limiters["keys"] = concatArray(keys);
51+
limiters["keys"] = concatenateArray(keys);
5252
}
5353

5454
/// Includes other ParseObjects stored as a Pointer
5555
void includeObject(List<String> objectTypes) {
56-
limiters["include"] = concatArray(objectTypes);
56+
limiters["include"] = concatenateArray(objectTypes);
5757
}
5858

5959
/// Returns an object where the [String] column starts with [value]
@@ -131,7 +131,7 @@ class QueryBuilder<T extends ParseObject> {
131131
MapEntry(column, value), "\$nin"));
132132
}
133133

134-
/// Returns an object where the [String] column for the object has data correctley entered/saved
134+
/// Returns an object where the [String] column for the object has data correctly entered/saved
135135
void whereValueExists(String column, bool value) {
136136
queries.add(_buildQueryWithColumnValueAndOperator(
137137
MapEntry(column, value), "\$exists"));
@@ -211,7 +211,7 @@ class QueryBuilder<T extends ParseObject> {
211211
return queryBuilder;
212212
}
213213

214-
String concatArray(List<String> queries) {
214+
String concatenateArray(List<String> queries) {
215215
String queryBuilder = "";
216216

217217
for (var item in queries) {
@@ -252,17 +252,17 @@ class QueryBuilder<T extends ParseObject> {
252252
/// This joins queries that should be joined together... e.g. age > 10 &&
253253
/// age < 20, this would be similar to age > 10 < 20
254254
List _checkForMultipleColumnInstances(List<MapEntry> queries) {
255-
List<MapEntry> sanitisedQueries = List();
255+
List<MapEntry> sanitizedQueries = List();
256256
List<String> keysAlreadyCompacted = List();
257257

258258
// Run through each query
259259
for (var query in queries) {
260-
// Add queries that don't need sanitising
260+
// Add queries that don't need sanitizing
261261
if (query.key == _NO_OPERATOR_NEEDED || query.key == _SINGLE_QUERY) {
262-
sanitisedQueries.add(MapEntry(_NO_OPERATOR_NEEDED, query.value));
262+
sanitizedQueries.add(MapEntry(_NO_OPERATOR_NEEDED, query.value));
263263
}
264264

265-
// Check if query with same column name has been sanitised
265+
// Check if query with same column name has been sanitized
266266
if (!keysAlreadyCompacted.contains(query.key) &&
267267
query.key != _NO_OPERATOR_NEEDED &&
268268
query.key != _SINGLE_QUERY) {
@@ -290,11 +290,11 @@ class QueryBuilder<T extends ParseObject> {
290290
}
291291
}
292292

293-
sanitisedQueries.add(MapEntry(query.key, queryStart += "{$queryEnd}"));
293+
sanitizedQueries.add(MapEntry(query.key, queryStart += "{$queryEnd}"));
294294
}
295295
}
296296

297-
return sanitisedQueries;
297+
return sanitizedQueries;
298298
}
299299

300300
/// Adds the limiters to the query, i.e. skip=10, limit=10

0 commit comments

Comments
 (0)