Skip to content

Commit a31c47a

Browse files
committed
Version 1.0.3 - Added pin, unpin, logger
1 parent 47176b4 commit a31c47a

14 files changed

+243
-94
lines changed

example/lib/main.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class _MyAppState extends State<MyApp> {
7070
print(ApplicationConstants.APP_NAME + ": " + (plan as DietPlan).name);
7171
}
7272
} else {
73-
print(ApplicationConstants.APP_NAME + ": " + response.exception.message);
73+
print(ApplicationConstants.APP_NAME + ": " + response.error.message);
7474
}
7575
}
7676

@@ -80,7 +80,7 @@ class _MyAppState extends State<MyApp> {
8080
if (response.success) {
8181
print(ApplicationConstants.APP_NAME + ": " + (response.result as DietPlan).toString());
8282
} else {
83-
print(ApplicationConstants.APP_NAME + ": " + response.exception.message);
83+
print(ApplicationConstants.APP_NAME + ": " + response.error.message);
8484
}
8585
}
8686

@@ -94,7 +94,7 @@ class _MyAppState extends State<MyApp> {
9494
if (response.success) {
9595
print("Result: ${((response.result as List<dynamic>).first as DietPlan).toString()}");
9696
} else {
97-
print("Result: ${response.exception.message}");
97+
print("Result: ${response.error.message}");
9898
}
9999
}
100100

lib/parse.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import 'package:web_socket_channel/io.dart';
1111

1212
part 'src/base/parse_constants.dart';
1313
part 'src/data/parse_core_data.dart';
14-
part 'src/enums/parse_enum_function_call.dart';
15-
part 'src/enums/parse_enum_object_call.dart';
16-
part 'src/enums/parse_enum_user_call.dart';
14+
part 'src/enums/parse_enum_api_rq.dart';
1715
part 'src/network/parse_http_client.dart';
1816
part 'src/network/parse_livequery.dart';
1917
part 'src/network/parse_query.dart';
@@ -29,6 +27,7 @@ part 'src/utils/parse_utils_objects.dart';
2927
part 'src/utils/parse_utils.dart';
3028
part 'src/utils/parse_encoder.dart';
3129
part 'src/utils/parse_decoder.dart';
30+
part 'src/utils/parse_logger.dart';
3231

3332
class Parse {
3433
ParseCoreData data;

lib/src/enums/parse_enum_api_rq.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
part of flutter_parse_sdk;
2+
3+
/// Used to define the API calls made in ParseObject logs
4+
enum ParseApiRQ {
5+
get,
6+
getAll,
7+
create,
8+
save,
9+
query,
10+
delete,
11+
currentUser,
12+
signUp,
13+
login,
14+
verificationEmailRequest,
15+
requestPasswordReset,
16+
destroy,
17+
all,
18+
execute
19+
}

lib/src/enums/parse_enum_function_call.dart

Lines changed: 0 additions & 4 deletions
This file was deleted.

lib/src/enums/parse_enum_object_call.dart

Lines changed: 0 additions & 4 deletions
This file was deleted.

lib/src/enums/parse_enum_user_call.dart

Lines changed: 0 additions & 13 deletions
This file was deleted.

lib/src/objects/parse_base.dart

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ abstract class ParseBase {
1010

1111
/// Returns [DateTime] createdAt
1212
DateTime get createdAt => stringToDateTime(_objectData['createdAt']);
13-
set createdAt(DateTime createdAt) => _objectData['createdAt'] = dateTimeToString(createdAt);
13+
set createdAt(DateTime createdAt) =>
14+
_objectData['createdAt'] = dateTimeToString(createdAt);
1415

1516
/// Returns [DateTime] updatedAt
1617
DateTime get updatedAt => stringToDateTime(_objectData['updatedAt']);
17-
set updatedAt(DateTime updatedAt) => _objectData['updatedAt'] = dateTimeToString(updatedAt);
18+
set updatedAt(DateTime updatedAt) =>
19+
_objectData['updatedAt'] = dateTimeToString(updatedAt);
1820

1921
/// Converts object to [String] in JSON format
2022
@protected
@@ -45,7 +47,7 @@ abstract class ParseBase {
4547
}
4648

4749
/// Create a new variable for this object, [bool] forceUpdate is always true,
48-
/// if unsure as to wether an item is needed or not, set to false
50+
/// if unsure as to whether an item is needed or not, set to false
4951
set(String key, dynamic value, {bool forceUpdate: true}) {
5052
if (value != null) {
5153
if (getObjectData().containsKey(key)) {
@@ -64,4 +66,45 @@ abstract class ParseBase {
6466
return defaultValue;
6567
}
6668
}
69+
70+
/// Saves item to simple key pair value storage
71+
///
72+
/// Replicates Android SDK pin process and saves object to storage
73+
pin() async {
74+
if (objectId != null) {
75+
await ParseCoreData().getStore().setString(objectId, toJson());
76+
return true;
77+
} else {
78+
return false;
79+
}
80+
}
81+
82+
/// Saves item to simple key pair value storage
83+
///
84+
/// Replicates Android SDK pin process and saves object to storage
85+
unpin() async {
86+
if (objectId != null) {
87+
var itemToSave = await ParseCoreData().getStore().setString(objectId, null);
88+
return true;
89+
} else {
90+
return false;
91+
}
92+
}
93+
94+
/// Saves item to simple key pair value storage
95+
///
96+
/// Replicates Android SDK pin process and saves object to storage
97+
fromPin() async {
98+
if (objectId != null) {
99+
var itemFromStore = await ParseCoreData().getStore().getString(objectId);
100+
101+
if (itemFromStore != null) {
102+
Map<String, dynamic> itemFromStoreMap = JsonDecoder().convert(
103+
itemFromStore);
104+
fromJson(itemFromStoreMap);
105+
return this;
106+
}
107+
}
108+
return null;
109+
}
67110
}

lib/src/objects/parse_exception.dart

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,76 @@
11
part of flutter_parse_sdk;
22

33
/// ParseException is used in [ParseResult] to inform the user of the exception
4-
class ParseException {
4+
class ParseError {
55

6-
int code;
7-
String message;
6+
Map<int, String> exceptions = {
7+
-1 :'UnknownError',
88

9-
ParseException();
9+
// SDK errors / Errors
10+
1: 'No Results',
11+
12+
// Parse specific / Exceptions
13+
100: 'ConnectionFailed',
14+
101: 'ObjectNotFound',
15+
102: 'InvalidQuery',
16+
103: 'InvalidClassName',
17+
104: 'MissingObjectId',
18+
105: 'InvalidKeyName',
19+
106: 'InvalidPointer',
20+
107: 'InvalidJson',
21+
108: 'CommandUnavailable',
22+
109: 'NotInitialized',
23+
111: 'IncorrectType',
24+
112: 'InvalidChannelName',
25+
115: 'PushMisconfigured',
26+
116: 'ObjectTooLarge',
27+
119: 'OperationForbidden',
28+
120: 'CacheMiss',
29+
121: 'InvalidNestedKey',
30+
122: 'InvalidFileName',
31+
123: 'InvalidAcl',
32+
124: 'Timeout',
33+
125: 'InvalidEmailAddress',
34+
135: 'MissingRequiredFieldError',
35+
137: 'DuplicateValue',
36+
139: 'InvalidRoleName',
37+
140: 'ExceededQuota',
38+
141: 'ScriptError',
39+
142: 'ValidationError',
40+
153: 'FileDeleteError',
41+
155: 'RequestLimitExceeded',
42+
160: 'InvalidEventName',
43+
200: 'UsernameMissing',
44+
201: 'PasswordMissing',
45+
202: 'UsernameTaken',
46+
203: 'EmailTaken',
47+
204: 'EmailMissing',
48+
205: 'EmailNotFound',
49+
206: 'SessionMissing',
50+
207: 'MustCreateUserThroughSignup',
51+
208: 'AccountAlreadyLinked',
52+
209: 'InvalidSessionToken',
53+
250: 'LinkedIdMissing',
54+
251: 'InvalidLinkedSession',
55+
252: 'UnsupportedService'};
56+
57+
final int code;
58+
String type;
59+
final String message;
60+
61+
ParseError({this.code = -1, this.message = "Unkown error", bool debug: false}){
62+
type = exceptions[code];
63+
if (debug) print(toString());
64+
}
65+
66+
@override
67+
String toString() {
68+
var exceptionString = ' \n';
69+
exceptionString += "----";
70+
exceptionString +="\nParseException (Type: $type) :";
71+
exceptionString +="\nCode: $code";
72+
exceptionString +="\nMessage: $message";
73+
exceptionString += "----";
74+
return exceptionString;
75+
}
1076
}

lib/src/objects/parse_function.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ class ParseCloudFunction extends ParseBase {
2222
execute() async {
2323
var uri = _client.data.serverUrl + "$_path";
2424
var result = await _client.post(uri, body: JsonEncoder().convert(getObjectData()));
25-
return _handleResult(result, ParseApiFunction.execute);
25+
return _handleResult(result, ParseApiRQ.execute);
2626
}
2727

2828
/// Handles an API response
29-
ParseResponse _handleResult(Response response, ParseApiFunction type) {
29+
ParseResponse _handleResult(Response response, ParseApiRQ type) {
3030
ParseResponse parseResponse = ParseResponse.handleResponse(this, response);
3131
Map<String, dynamic> responseData = JsonDecoder().convert(response.body);
3232

lib/src/objects/parse_geo_point.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
part of flutter_parse_sdk;
22

3-
class ParseGeoPoint extends ParseBase {
4-
final String className = 'GeoPoint';
3+
class ParseGeoPoint extends ParseObject {
54

65
double _latitude;
76
double _longitude;
87

98
/// Creates a Parse Object of type GeoPoint
10-
ParseGeoPoint({double latitude = 0.0, double longitude = 0.0}):
11-
assert(latitude >= -90.0 || latitude <= 90.0),
12-
assert(longitude >= -180.0 || longitude <= 180.0) {
9+
ParseGeoPoint({double latitude = 0.0, double longitude = 0.0}): super ('GeoPoint') {
1310
_latitude = latitude;
1411
_longitude = longitude;
1512
}

0 commit comments

Comments
 (0)