Skip to content

Merge upstream. #4

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

Merged
merged 12 commits into from
Feb 7, 2019
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.0.11
ParseFile fixed
Anonymous login
SecurityContext
CloudFunctions with objects

## 1.0.10
Add ParseConfig.
Fixed whereEqualsTo('', PARSEOBJECT) and other queries
Expand Down
8 changes: 5 additions & 3 deletions 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.10
parse_server_sdk: ^1.0.11
```
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 All @@ -33,8 +33,10 @@ Parse().initialize(
ApplicationConstants.keyApplicationId,
ApplicationConstants.keyParseServerUrl,
masterKey: ApplicationConstants.keyParseMasterKey,
debug: true,
liveQuery: true);
clientKey: ApplicationConstants.keyParseClientKey,
debug: true,
liveQuery: true,
securityContext: securityContext);
```

## Queries
Expand Down
8 changes: 4 additions & 4 deletions example/lib/diet_plan.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import 'dart:core';

import 'package:parse_server_sdk/parse.dart';
import 'package:parse_server_sdk/parse_server_sdk.dart';

class DietPlan extends ParseObject implements ParseCloneable {

DietPlan() : super(_keyTableName);
DietPlan.clone(): this();
DietPlan.clone() : this();

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

static const String _keyTableName = 'Diet_Plans';
static const String keyName = 'Name';
Expand Down
23 changes: 8 additions & 15 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +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:parse_server_sdk/parse.dart';
import 'package:parse_server_sdk/parse_server_sdk.dart';

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

Expand Down Expand Up @@ -178,20 +178,13 @@ class _MyAppState extends State<MyApp> {
}

function() async {
var user =
ParseUser("TestFlutter", "TestPassword123", "[email protected]");
await user.signUp();
var loginResponse = await user.login();
if (loginResponse.success) user = loginResponse.result;

var customClient = ParseHTTPClient();
customClient.additionalHeaders = {
keyHeaderSessionToken: ParseCoreData().sessionId
};
var function = ParseCloudFunction('hello', client: customClient);
function.execute();

user.destroy();
var function = ParseCloudFunction('hello');
var result = await function.executeObjectFunction<ParseObject>();
if (result.success) {
if (result.result is ParseObject) {
print((result.result as ParseObject).className);
}
}
}

functionWithParameters() async {
Expand Down
10 changes: 6 additions & 4 deletions lib/parse.dart → lib/parse_server_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:io';
import 'dart:typed_data';

import 'package:http/http.dart';
import 'package:http/io_client.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as path;
import 'package:shared_preferences/shared_preferences.dart';
Expand Down Expand Up @@ -57,7 +58,6 @@ part 'src/utils/parse_utils.dart';

class Parse {
ParseCoreData data;
final ParseHTTPClient client = new ParseHTTPClient();
bool _hasBeenInitialised = false;

/// To initialise Parse Server in your application
Expand All @@ -78,14 +78,16 @@ class Parse {
String liveQueryUrl,
String clientKey,
String masterKey,
String sessionId}) {
String sessionId,
SecurityContext securityContext}) {
ParseCoreData.init(appId, serverUrl,
debug: debug,
appName: appName,
liveQueryUrl: liveQueryUrl,
masterKey: masterKey,
clientKey: clientKey,
sessionId: sessionId);
sessionId: sessionId,
securityContext: securityContext);

ParseCoreData().initStorage();

Expand All @@ -100,7 +102,7 @@ class Parse {
ParseResponse parseResponse;

try {
var response = await ParseHTTPClient()
var response = await ParseHTTPClient(ParseCoreData().securityContext)
.get("${ParseCoreData().serverUrl}$keyEndPointHealth");
parseResponse =
ParseResponse.handleResponse(this, response, returnAsResult: true);
Expand Down
2 changes: 1 addition & 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.10';
const String keySdkVersion = '1.0.11';
const String keyLibraryName = 'Flutter Parse SDK';

// End Points
Expand Down
10 changes: 9 additions & 1 deletion lib/src/data/parse_core_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ class ParseCoreData {
/// This class should not be user unless switching servers during the app,
/// which is odd. Should only be user by Parse.init
static void init(appId, serverUrl,
{debug, appName, liveQueryUrl, masterKey, clientKey, sessionId}) {
{debug,
appName,
liveQueryUrl,
masterKey,
clientKey,
sessionId,
securityContext}) {
_instance = ParseCoreData._init(appId, serverUrl);

if (debug != null) _instance.debug = debug;
Expand All @@ -20,6 +26,7 @@ class ParseCoreData {
if (clientKey != null) _instance.clientKey = clientKey;
if (masterKey != null) _instance.masterKey = masterKey;
if (sessionId != null) _instance.sessionId = sessionId;
if (securityContext != null) _instance.securityContext = securityContext;
}

String appName;
Expand All @@ -29,6 +36,7 @@ class ParseCoreData {
String masterKey;
String clientKey;
String sessionId;
SecurityContext securityContext;
bool debug;
SharedPreferences storage;

Expand Down
7 changes: 5 additions & 2 deletions lib/src/network/parse_http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ part of flutter_parse_sdk;

/// Creates a custom version of HTTP Client that has Parse Data Preset
class ParseHTTPClient extends BaseClient {
final Client _client = Client();
final Client _client;
final String _userAgent = "$keyLibraryName $keySdkVersion";
ParseCoreData data = ParseCoreData();
Map<String, String> additionalHeaders;

ParseHTTPClient();
ParseHTTPClient([SecurityContext securityContext])
: _client = securityContext != null
? IOClient(HttpClient(context: securityContext))
: IOClient();

/// Overrides the call method for HTTP Client and adds custom headers
@override
Expand Down
8 changes: 5 additions & 3 deletions lib/src/objects/parse_config.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
part of flutter_parse_sdk;

class ParseConfig extends ParseObject {
var _client = ParseHTTPClient();
var _client = ParseHTTPClient(ParseCoreData().securityContext);

/// Creates an instance of ParseConfig so that you can grab all configs from the server
ParseConfig({bool debug, ParseHTTPClient client}) : super('config') {
Expand All @@ -14,7 +14,8 @@ class ParseConfig extends ParseObject {
try {
var uri = "${ParseCoreData().serverUrl}/config";
var result = await _client.get(uri);
return handleResponse(this, result, ParseApiRQ.getConfigs, _debug, className);
return handleResponse(
this, result, ParseApiRQ.getConfigs, _debug, className);
} on Exception catch (e) {
return handleException(e, ParseApiRQ.getConfigs, _debug, className);
}
Expand All @@ -26,7 +27,8 @@ class ParseConfig extends ParseObject {
var uri = "${ParseCoreData().serverUrl}/config";
var body = "{\"params\":{\"$key\": \"${parseEncode(value)}\"}}";
var result = await _client.put(uri, body: body);
return handleResponse(this, result, ParseApiRQ.addConfig, _debug, className);
return handleResponse(
this, result, ParseApiRQ.addConfig, _debug, className);
} on Exception catch (e) {
return handleException(e, ParseApiRQ.addConfig, _debug, className);
}
Expand Down
8 changes: 6 additions & 2 deletions lib/src/objects/parse_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ class ParseFile extends ParseObject {
ParseFile(this._file,
{String name, String url, bool debug, ParseHTTPClient client})
: super(keyFile) {
client == null ? _client = ParseHTTPClient() : _client = client;
client == null
? _client = ParseHTTPClient(ParseCoreData().securityContext)
: _client = client;

_debug = isDebugEnabled(objectLevelDebug: debug);
if (_file != null) {
this._fileName = path.basename(_file.path);
Expand Down Expand Up @@ -93,6 +96,7 @@ class ParseFile extends ParseObject {
var uri = _client.data.serverUrl + "$_path";
final body = await _file.readAsBytes();
final response = await _client.post(uri, headers: headers, body: body);
return handleResponse<ParseFile>(this, response, ParseApiRQ.upload, _debug, className);
return handleResponse<ParseFile>(
this, response, ParseApiRQ.upload, _debug, className);
}
}
12 changes: 9 additions & 3 deletions lib/src/objects/parse_geo_point.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
part of flutter_parse_sdk;

class ParseGeoPoint extends ParseObject {

double _latitude;
double _longitude;

/// Creates a Parse Object of type GeoPoint
ParseGeoPoint({double latitude = 0.0, double longitude = 0.0, bool debug, ParseHTTPClient client}): super (keyGeoPoint) {
ParseGeoPoint(
{double latitude = 0.0,
double longitude = 0.0,
bool debug,
ParseHTTPClient client})
: super(keyGeoPoint) {
_latitude = latitude;
_longitude = longitude;

client == null ? _client = ParseHTTPClient() : _client = client;
client == null
? _client = ParseHTTPClient(ParseCoreData().securityContext)
: _client = client;
_debug = isDebugEnabled(objectLevelDebug: debug);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/objects/parse_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ParseObject extends ParseBase implements ParseCloneable {
ParseObject(String className, {bool debug: false}) : super() {
setClassName(className);
_path = "$keyEndPointClasses$className";
setClient(ParseHTTPClient());
setClient(ParseHTTPClient(ParseCoreData().securityContext));
setDebug(isDebugEnabled(objectLevelDebug: debug));
}

Expand Down Expand Up @@ -83,7 +83,7 @@ class ParseObject extends ParseBase implements ParseCloneable {
}
}

/// Removes an element from an Arary
/// 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]);
Expand Down
10 changes: 6 additions & 4 deletions lib/src/objects/parse_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class ParseUser extends ParseObject implements ParseCloneable {
ParseUser(String username, String password, String emailAddress,
{bool debug, ParseHTTPClient client})
: super(keyClassUser) {
client == null ? _client = ParseHTTPClient() : _client = client;
client == null
? _client = ParseHTTPClient(ParseCoreData().securityContext)
: _client = client;
_debug = isDebugEnabled(objectLevelDebug: debug);

this.username = username;
Expand Down Expand Up @@ -83,7 +85,7 @@ class ParseUser extends ParseObject implements ParseCloneable {
host: tempUri.host,
path: "${tempUri.path}$keyEndPointUserName");

final response = await ParseHTTPClient()
final response = await ParseHTTPClient(ParseCoreData().securityContext)
.get(uri, headers: {keyHeaderSessionToken: token});
return _handleResponse(_getEmptyUser(), response, ParseApiRQ.currentUser,
_debug, _getEmptyUser().className);
Expand Down Expand Up @@ -273,8 +275,8 @@ class ParseUser extends ParseObject implements ParseCloneable {
var emptyUser = ParseUser(null, null, null);

try {
final response =
await ParseHTTPClient().get("${ParseCoreData().serverUrl}/$path");
final response = await ParseHTTPClient(ParseCoreData().securityContext)
.get("${ParseCoreData().serverUrl}/$path");

ParseResponse parseResponse =
ParseResponse.handleResponse<ParseUser>(emptyUser, response);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: parse_server_sdk
description: Flutter plugin for Parse Server, (https://parseplatform.org), (https://back4app.com)
version: 1.0.10
version: 1.0.11
homepage: https://github.com/phillwiggins/flutter_parse_sdk
author: PhillWiggins <[email protected]>

Expand Down
12 changes: 5 additions & 7 deletions test/parse_client_configuration_test.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'package:parse_server_sdk/parse_server_sdk.dart';
import 'package:test/test.dart';
import 'package:parse_server_sdk/parse.dart';

void main(){
test("testBuilder",() {
Parse().initialize("appId",
"serverUrl",
void main() {
test("testBuilder", () {
Parse().initialize("appId", "serverUrl",
clientKey: "clientKey",
liveQueryUrl: "liveQueryUrl",
appName: "appName",
Expand All @@ -20,6 +19,5 @@ void main(){
expect(ParseCoreData().masterKey, "masterKey");
expect(ParseCoreData().sessionId, "sessionId");
expect(ParseCoreData().debug, true);

});
}
}