Skip to content

Sync Release 1.0.13 #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
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
4 changes: 4 additions & 0 deletions lib/parse_server_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:web_socket_channel/io.dart';
import 'package:uuid/uuid.dart';
import 'package:path_provider/path_provider.dart';
import 'package:devicelocale/devicelocale.dart';
import 'package:package_info/package_info.dart';

part 'src/base/parse_constants.dart';

Expand Down Expand Up @@ -46,6 +48,8 @@ part 'src/objects/parse_response.dart';

part 'src/objects/parse_user.dart';

part 'src/objects/parse_installation.dart';

part 'src/utils/parse_decoder.dart';

part 'src/utils/parse_encoder.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 @@ -28,6 +28,7 @@ const String keyVarAcl = 'ACL';
// Classes
const String keyClassMain = 'ParseMain';
const String keyClassUser = '_User';
const String keyClassInstallation = '_Installation';
const String keyGeoPoint = 'GeoPoint';
const String keyFile = 'File';

Expand All @@ -47,3 +48,4 @@ const String keyParamSessionToken = 'sessionToken';
// Storage
const String keyParseStoreBase = 'flutter_parse_sdk_';
const String keyParseStoreUser = "${keyParseStoreBase}user";
const String keyParseStoreInstallation = "${keyParseStoreBase}installation";
1 change: 1 addition & 0 deletions lib/src/enums/parse_enum_api_rq.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum ParseApiRQ {
login,
logout,
loginAnonymous,
loginWith,
verificationEmailRequest,
requestPasswordReset,
destroy,
Expand Down
148 changes: 148 additions & 0 deletions lib/src/objects/parse_installation.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
part of flutter_parse_sdk;

class ParseInstallation extends ParseObject {
static final String keyTimeZone = 'timeZone';
static final String keyLocaleIdentifier = 'localeIdentifier';
static final String keyDeviceToken = 'deviceToken';
static final String keyDeviceType = 'deviceType';
static final String keyInstallationId = 'installationId';
static final String keyAppName = 'appName';
static final String keyAppVersion = 'appVersion';
static final String keyAppIdentifier = 'appIdentifier';
static final String keyParseVersion = 'parseVersion';
static final List<String> readOnlyKeys = [ //TODO
keyDeviceToken, keyDeviceType, keyInstallationId,
keyAppName, keyAppVersion, keyAppIdentifier, keyParseVersion
];
static String _currentInstallationId;

//Getters/setters

Map get acl => super.get<Map>(keyVarAcl);

set acl(Map acl) => set<Map>(keyVarAcl, acl);

String get deviceToken => super.get<String>(keyDeviceToken);

set deviceToken(String deviceToken) => set<String>(keyDeviceToken, deviceToken);

String get deviceType => super.get<String>(keyDeviceType);

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

set _installationId(String installationId) => set<String>(keyInstallationId, installationId);

String get appName => super.get<String>(keyAppName);

String get appVersion => super.get<String>(keyAppVersion);

String get appIdentifier => super.get<String>(keyAppIdentifier);

String get parseVersion => super.get<String>(keyParseVersion);

/// Creates an instance of ParseInstallation
ParseInstallation(
{bool debug,
ParseHTTPClient client,
bool autoSendSessionId})
: super(keyClassInstallation) {
_debug = isDebugEnabled(objectLevelDebug: debug);
_client = client ??
ParseHTTPClient(
autoSendSessionId:
autoSendSessionId ?? ParseCoreData().autoSendSessionId,
securityContext: ParseCoreData().securityContext);
}

ParseInstallation.forQuery() : super(keyClassUser);

static Future<bool> isCurrent(ParseInstallation installation) async {
if (_currentInstallationId == null) {
_currentInstallationId = (await _getFromLocalStore()).installationId;
}
return _currentInstallationId != null && installation.installationId == _currentInstallationId;
}

/// Gets the current installation from storage
static Future<ParseInstallation> currentInstallation() async {
var installation = await _getFromLocalStore();
if (installation == null) {
installation = await _createInstallation();
}
return installation;
}

/// Updates the installation with current device data
_updateInstallation() async {
//Device type
if (Platform.isAndroid) set<String>(keyDeviceType, "android");
else if (Platform.isIOS) set<String>(keyDeviceType, "ios");
else throw Exception("Unsupported platform/operating system");

//Locale
String locale = await Devicelocale.currentLocale;
if (locale != null && locale.isNotEmpty) {
set<String>(keyLocaleIdentifier, locale);
}

//Timezone
//TODO set<String>(keyTimeZone, );

//App info
PackageInfo packageInfo = await PackageInfo.fromPlatform();
set<String>(keyAppName, packageInfo.appName);
set<String>(keyAppVersion, packageInfo.version);
set<String>(keyAppIdentifier, packageInfo.packageName);
set<String>(keyParseVersion, keySdkVersion);
}

Future<ParseResponse> create() async {
var isCurrent = await ParseInstallation.isCurrent(this);
if (isCurrent) await _updateInstallation();
ParseResponse parseResponse = await super.create();
if (parseResponse.success && isCurrent) {
saveInStorage(keyParseStoreInstallation);
}
return parseResponse;
}

/// Saves the current installation
Future<ParseResponse> save() async {
var isCurrent = await ParseInstallation.isCurrent(this);
if (isCurrent) await _updateInstallation();
ParseResponse parseResponse = await super.save();
if (parseResponse.success && isCurrent) {
saveInStorage(keyParseStoreInstallation);
}
return parseResponse;
}

/// Gets the locally stored installation
static Future<ParseInstallation> _getFromLocalStore() async {
var installationJson =
(await ParseCoreData().getStore()).getString(keyParseStoreInstallation);

if (installationJson != null) {
var installationMap = parseDecode(json.decode(installationJson));

if (installationMap != null) {
return new ParseInstallation()..fromJson(installationMap);
}
}

return null;
}

/// Creates a installation for current device
/// Assumes that this is called because there is no previous installation
/// so it creates and sets the static current installation UUID
static Future<ParseInstallation> _createInstallation() async {
if (_currentInstallationId == null) {
_currentInstallationId = Uuid().v4();
}
var installation = new ParseInstallation();
installation._installationId = _currentInstallationId;
await installation._updateInstallation();
return installation;
}
}
40 changes: 39 additions & 1 deletion lib/src/objects/parse_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ParseUser extends ParseObject implements ParseCloneable {

ParseUser.forQuery() : super(keyClassUser);

createUser(String username, String password, [String emailAddress]) {
static createUser([String username, String password, String emailAddress]) {
return ParseUser(username, password, emailAddress);
}

Expand Down Expand Up @@ -206,6 +206,44 @@ class ParseUser extends ParseObject implements ParseCloneable {
}
}

// Logs in a user using a service
static Future<ParseUser> loginWith(String provider, Object authData) async {
ParseUser user = ParseUser.createUser();
var response = await user._loginWith(provider, authData);
if (response.success) {
return user;
} else {
return Future.error(response);
}
}

Future<ParseResponse> _loginWith(String provider, Object authData) async {
try {
Uri tempUri = Uri.parse(_client.data.serverUrl);

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

final response = await _client.post(url,
headers: {
keyHeaderRevocableSession: "1",
},
body: jsonEncode({
"authData": {
provider: authData
}
}));

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

/// Sends a request to delete the sessions token from the
/// server. Will also delete the local user data unless
/// deleteLocalUserData is false.
Expand Down
4 changes: 3 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ dependencies:
http: ^0.12.0

# Utils
shared_preferences: ^0.4.3
shared_preferences: ^0.5.0
path_provider: ^0.4.1
uuid: ^1.0.3
package_info: ^0.4.0
devicelocale: ^0.1.1

dev_dependencies:
# Testing
Expand Down