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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.0.15
Fixed 'full' bool issue

## 1.0.14
Corrected delete & path issue
Added Geo queries
Added ability to add login oAuth data

## 1.0.13
Added full bool to convert objects to JSON correctly

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Want to get involved? Join our Slack channel and help out! (http://flutter-parse
To install, either add to your pubspec.yaml
```
dependencies:
parse_server_sdk: ^1.0.13
parse_server_sdk: ^1.0.15
```
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.

Expand Down
13 changes: 7 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_plugin_example/application_constants.dart';
import 'package:flutter_plugin_example/diet_plan.dart';
import 'package:flutter_stetho/flutter_stetho.dart';
import 'package:parse_server_sdk/parse_server_sdk.dart';

void main() => runApp(new MyApp());
void main() {
Stetho.initialize();
runApp(new MyApp());
}

class MyApp extends StatefulWidget {
@override
Expand Down Expand Up @@ -109,10 +113,10 @@ class _MyAppState extends State<MyApp> {
if (randomInt is int) print('Saving generic value worked!');

// Shows example of pinning an item
dietPlan.pin();
await dietPlan.pin();

// shows example of retrieving a pin
var newDietPlanFromPin = DietPlan().fromPin('R5EonpUDWy');
var newDietPlanFromPin = await DietPlan().fromPin('R5EonpUDWy');
if (newDietPlanFromPin != null) print('Retreiving from pin worked!');
} else {
print(ApplicationConstants.keyAppName + ": " + apiResponse.error.message);
Expand Down Expand Up @@ -149,9 +153,6 @@ class _MyAppState extends State<MyApp> {
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();
await user.logout();
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
flutter_stetho: ^0.2.2

dev_dependencies:

parse_server_sdk:
path: ../

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
4 changes: 3 additions & 1 deletion lib/src/base/parse_constants.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
part of flutter_parse_sdk;

// Library
const String keySdkVersion = '1.0.13';
const String keySdkVersion = '1.0.15';
const String keyLibraryName = 'Flutter Parse SDK';

// End Points
Expand All @@ -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
51 changes: 51 additions & 0 deletions lib/src/network/parse_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,57 @@ class QueryBuilder<T extends ParseObject> {
if (orderByScore) orderByDescending('score');
}

/// Returns an objects with key point values near the point given
void whereNear(String column, ParseGeoPoint point) {
var latitude = point.latitude;
var longitude = point.longitude;
queries.add(MapEntry(_SINGLE_QUERY,
'\"$column\":{\"\$nearSphere\":{\"__type\":\"GeoPoint\",\"latitude\":$latitude,\"longitude\":$longitude}}'));
}

/// Returns an object with key point values near the point given and within the maximum distance given.
void whereWithinMiles(
String column, ParseGeoPoint point, double maxDistance) {
var latitude = point.latitude;
var longitude = point.longitude;

queries.add(MapEntry(_SINGLE_QUERY,
'\"$column\":{\"\$nearSphere\":{\"__type\":\"GeoPoint\",\"latitude\":$latitude,\"longitude\":$longitude},\"\$maxDistanceInMiles\":$maxDistance}'));
}

/// Returns an object with key point values near the point given and within the maximum distance given.
void whereWithinKilometers(
String column, ParseGeoPoint point, double maxDistance) {
var latitude = point.latitude;
var longitude = point.longitude;

queries.add(MapEntry(_SINGLE_QUERY,
'\"$column\":{\"\$nearSphere\":{\"__type\":\"GeoPoint\",\"latitude\":$latitude,\"longitude\":$longitude},\"\$maxDistanceInKilometers\":$maxDistance}'));
}

/// Returns an object with key point values near the point given and within the maximum distance given.
void whereWithinRadians(
String column, ParseGeoPoint point, double maxDistance) {
var latitude = point.latitude;
var longitude = point.longitude;

queries.add(MapEntry(_SINGLE_QUERY,
'\"$column\":{\"\$nearSphere\":{\"__type\":\"GeoPoint\",\"latitude\":$latitude,\"longitude\":$longitude},\"\$maxDistanceInRadians\":$maxDistance}'));
}

/// Returns an object with key point values contained within a given rectangular geographic bounding box.
void whereWithinGeoBox(
String column, ParseGeoPoint southwest, ParseGeoPoint northeast) {
var latitudeS = southwest.latitude;
var longitudeS = southwest.longitude;

var latitudeN = northeast.latitude;
var longitudeN = northeast.longitude;

queries.add(MapEntry(_SINGLE_QUERY,
'\"$column\":{\"\$within\":{\"\$box\": [{\"__type\": \"GeoPoint\",\"latitude\":$latitudeS,\"longitude\":$longitudeS},{\"__type\": \"GeoPoint\",\"latitude\":$latitudeN,\"longitude\":$longitudeN}]}}'));
}

/// Finishes the query and calls the server
///
/// Make sure to call this after defining your queries
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;
}
}
5 changes: 3 additions & 2 deletions lib/src/objects/parse_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,10 @@ class ParseObject extends ParseBase implements ParseCloneable {
}

/// Deletes the current object locally and online
Future<ParseResponse> delete(String path, String objectId) async {
Future<ParseResponse> delete(String objectId, {String path}) async {
try {
var uri = "${ParseCoreData().serverUrl}$_path/$objectId";
path ??= _path;
var uri = "${ParseCoreData().serverUrl}$path/$objectId";
var result = await _client.delete(uri);
return handleResponse(this, result, ParseApiRQ.delete, _debug, className);
} on Exception catch (e) {
Expand Down
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
Loading