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
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ The features available are:-
* NotEqualTo
* StartsWith
* EndsWith
* Exists
* Near
* WithinMiles
* WithinKilometers
* WithinRadians
* WithinGeoBox
* Regex
* Order
* Limit
Expand Down Expand Up @@ -120,6 +126,8 @@ The features available are:-
* Complex queries as shown above
* Pin
* Plenty more
* Counters
* Array Operators

## Custom Objects
You can create your own ParseObjects or convert your existing objects into Parse Objects by doing the following:
Expand Down Expand Up @@ -166,6 +174,29 @@ and to retrieve it
var dietPlan = DietPlan().fromPin('OBJECT ID OF OBJECT');
```

## Increment Counter values in objects

Retrieve it, call

```
var response = await dietPlan.increment("count", 1);

```

## Array Operator in objects

Retrieve it, call

```
var response = await dietPlan.add("listKeywords", ["a", "a","d"]);

var response = await dietPlan.addUnique("listKeywords", ["a", "a","d"]);

var response = await dietPlan.remove("listKeywords", ["a"]);

```


## Users

You can create and control users just as normal using this SDK.
Expand Down Expand Up @@ -195,6 +226,7 @@ Other user features are:-
* Get all users
* Save
* Destroy user
* Queries

## Config

Expand All @@ -212,23 +244,27 @@ ParseConfig().addConfig('TestConfig', 'testing');

Main:
* Users
* Installation
* Objects
* Queries
* LiveQueries
* GeoPoints
* Files
* Persistent storage
* Debug Mode - Logging API calls
* Manage Session ID's tokens

User:
* Create
* Login
* Logout
* CurrentUser
* RequestPasswordReset
* VerificationEmailRequest
* AllUsers
* Save
* Destroy
* Queries

Objects:
* Create new object
Expand Down
2 changes: 2 additions & 0 deletions lib/parse_server_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ part 'src/objects/parse_response.dart';

part 'src/objects/parse_user.dart';

part 'src/objects/parse_session.dart';

part 'src/objects/parse_installation.dart';

part 'src/utils/parse_decoder.dart';
Expand Down
2 changes: 2 additions & 0 deletions lib/src/base/parse_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const String keyEndPointUserName = '/users/me';
const String keyEndPointLogin = '/login';
const String keyEndPointLogout = '/logout';
const String keyEndPointUsers = '/users';
const String keyEndPointSessions = '/sessions';
const String keyEndPointVerificationEmail = '/verificationEmailRequest';
const String keyEndPointRequestPasswordReset = '/requestPasswordReset';
const String keyEndPointClasses = '/classes/';
Expand All @@ -28,6 +29,7 @@ const String keyVarAcl = 'ACL';
// Classes
const String keyClassMain = 'ParseMain';
const String keyClassUser = '_User';
const String keyClassSession = '_Session';
const String keyClassInstallation = '_Installation';
const String keyGeoPoint = 'GeoPoint';
const String keyFile = 'File';
Expand Down
26 changes: 17 additions & 9 deletions lib/src/objects/parse_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ParseObject extends ParseBase implements ParseCloneable {
/// Removes an element from an Array
Future<ParseResponse> remove(String key, dynamic values) async {
if (key != null) {
return await _sortArrays(ParseApiRQ.remove, "Remove", key, [values]);
return await _sortArrays(ParseApiRQ.remove, "Remove", key, values);
} else {
return null;
}
Expand Down Expand Up @@ -130,11 +130,15 @@ class ParseObject extends ParseBase implements ParseCloneable {
Future<ParseResponse> _sortArrays(ParseApiRQ apiRQType, String arrayAction,
String key, List<dynamic> values) async {
try {
var uri = "${ParseCoreData().serverUrl}$_path";
var body =
"{\"$key\":{\"__op\": \"$arrayAction\", \"objects\": ${parseEncode(values)}";
var result = await _client.put(uri, body: body);
return handleResponse(this, result, apiRQType, _debug, className);
if (objectId != null) {
var uri = "${ParseCoreData().serverUrl}$_path/$objectId";
var body =
"{\"$key\":{\"__op\":\"$arrayAction\",\"objects\":${json.encode(parseEncode(values))}}}";
var result = await _client.put(uri, body: body);
return handleResponse(this, result, apiRQType, _debug, className);
} else {
return null;
}
} on Exception catch (e) {
return handleException(e, apiRQType, _debug, className);
}
Expand All @@ -160,12 +164,16 @@ class ParseObject extends ParseBase implements ParseCloneable {

/// Can be used to add arrays to a given type
Future<ParseResponse> _increment(
ParseApiRQ apiRQType, String arrayAction, String key, num amount) async {
ParseApiRQ apiRQType, String countAction, String key, num amount) async {
try {
var uri = "${ParseCoreData().serverUrl}$_path";
var body = "{\"$key\":{\"__op\": \"$arrayAction\", \"amount\": $amount}";
if (objectId != null) {
var uri = "${ParseCoreData().serverUrl}$_path/$objectId";
var body = "{\"$key\":{\"__op\":\"$countAction\",\"amount\":$amount}}";
var result = await _client.put(uri, body: body);
return handleResponse(this, result, apiRQType, _debug, className);
} else {
return null;
}
} on Exception catch (e) {
return handleException(e, apiRQType, _debug, className);
}
Expand Down
82 changes: 82 additions & 0 deletions lib/src/objects/parse_session.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
part of flutter_parse_sdk;

class ParseSession extends ParseObject implements ParseCloneable {
@override
clone(Map map) {
print(map);
return this.fromJson(map);
}

static final String keyVarUser = 'user';
static final String keyVarCreatedWith = 'createdWith';
static final String keyVarRestricted = 'restricted';
static final String keyVarExpiresAt = 'expiresAt';
static final String keyVarInstallationId = 'installationId';

String get sessionToken => super.get<String>(keyVarSessionToken);

ParseObject get user => super.get<ParseObject>(keyVarUser);

Map<String, dynamic> get createdWith =>
super.get<Map<String, dynamic>>(keyVarCreatedWith);

bool get restricted => super.get<bool>(keyVarRestricted);

DateTime get expiresAt => super.get<DateTime>(keyVarExpiresAt);

String get installationId => super.get<String>(keyVarInstallationId);

ParseSession({String sessionToken, bool debug, ParseHTTPClient client})
: super(keyClassSession) {
_debug = isDebugEnabled(objectLevelDebug: debug);
_client = client ??
ParseHTTPClient(
autoSendSessionId: true,
securityContext: ParseCoreData().securityContext);
}

Future<ParseResponse> getCurrentSessionFromServer() async {
try {
Uri tempUri = Uri.parse(_client.data.serverUrl);

Uri url = Uri(
scheme: tempUri.scheme,
host: tempUri.host,
path: "${tempUri.path}$keyEndPointSessions/me");

final response = await _client.get(url);

return _handleResponse(
this, response, ParseApiRQ.logout, _debug, className);
} on Exception catch (e) {
return _handleException(e, ParseApiRQ.logout, _debug, className);
}
}

/// Handles an API response and logs data if [bool] debug is enabled
static ParseResponse _handleException(
Exception exception, ParseApiRQ type, bool debug, String className) {
ParseResponse parseResponse = ParseResponse.handleException(exception);

if (debug) {
logger(
ParseCoreData().appName, className, type.toString(), parseResponse);
}

return parseResponse;
}

/// Handles all the response data for this class
static ParseResponse _handleResponse(ParseSession session, Response response,
ParseApiRQ type, bool debug, String className) {
ParseResponse parseResponse =
ParseResponse.handleResponse<ParseSession>(session, response);

if (debug) {
logger(
ParseCoreData().appName, className, type.toString(), parseResponse);
}

return parseResponse;
}
}