-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ApiReply | extended message, keepAlive mode, debug mode
- Loading branch information
1 parent
874f106
commit 9a44904
Showing
6 changed files
with
79 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
// import 'package:logging/logging.dart'; | ||
|
||
class ApiError { | ||
// final _log = Logger('ApiError'); | ||
final Map<String, dynamic>? _errors; | ||
/// | ||
ApiError({ | ||
required Map<String, dynamic>? errors, | ||
}) : | ||
_errors = errors; | ||
/// | ||
String get message => _errors?['message'] ?? ''; | ||
/// | ||
String get details => _errors?['details'] ?? ''; | ||
/// | ||
bool get isEmpty { | ||
return message.isEmpty && details.isEmpty; | ||
} | ||
/// | ||
bool get isNotEmpty { | ||
return !isEmpty; | ||
} | ||
/// | ||
@override | ||
String toString() { | ||
return '''$ApiError { | ||
\t\tmessage: $message; | ||
\t\tdetails: $details; | ||
\t}'''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,62 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:dart_api_client/src/reply/api_error.dart'; | ||
import 'package:logging/logging.dart'; | ||
|
||
class ApiReply { | ||
final _log = Logger('ApiReply'); | ||
late String _authToken; | ||
late String _id; | ||
late Map<String, String> _sql; | ||
late List<Map<String, dynamic>> _data; | ||
late List<String> _errors; | ||
late final String _authToken; | ||
late final String _id; | ||
late final Map<String, dynamic> _query; | ||
late final List<Map<String, dynamic>> _data; | ||
late final ApiError _error; | ||
/// | ||
ApiReply({ | ||
required String authToken, | ||
required String id, | ||
required Map<String, String> sql, | ||
required Map<String, dynamic> query, | ||
required List<Map<String, dynamic>> data, | ||
required List<String> errors, | ||
required ApiError errors, | ||
}) : | ||
_authToken = authToken, | ||
_id = id, | ||
_sql = sql, | ||
_query = query, | ||
_data = data, | ||
_errors = errors; | ||
_error = errors; | ||
/// | ||
ApiReply.fromJson(String jsonString) { | ||
// _log.fine('.fromJson | jsonString: $jsonString'); | ||
final jsonMap = json.decode(jsonString); | ||
_log.fine('.fromJson | jsonMap: $jsonMap'); | ||
_authToken = jsonMap['auth_token']; | ||
_id = jsonMap['id']; | ||
_sql = jsonMap['sql'] ?? {}; | ||
_query = jsonMap['query'] ?? {}; | ||
_data = (jsonMap['data'] as List<dynamic>).map((e) { | ||
return (e as Map<dynamic, dynamic>).map((key, value) => MapEntry(key.toString(), value)); | ||
// final key = (e as MapEntry).key; | ||
// final value = (e as MapEntry).value; | ||
// return MapEntry<String, dynamic>(key.toString(), value); | ||
}).toList(); | ||
_errors = (jsonMap['errors'] as List<dynamic>).map((e) => '$e').toList(); | ||
_error = ApiError(errors: jsonMap['error']); | ||
} | ||
/// | ||
String get authToken => _authToken; | ||
/// | ||
String get id => _id; | ||
/// | ||
Map<String, String> get sql => _sql; | ||
Map<String, dynamic> get sql => _query; | ||
/// | ||
List<Map<String, dynamic>> get data => _data; | ||
/// | ||
List<String> get errors => _errors; | ||
ApiError get error => _error; | ||
/// | ||
bool get hasError => _error.isNotEmpty; | ||
/// | ||
@override | ||
String toString() { | ||
return '''$ApiReply { | ||
\t\tauthToken: $_authToken; | ||
\t\tid: $_id; | ||
\t\tsql: $_sql; | ||
\t\tquery: $_query; | ||
\t\tdata: $_data; | ||
\t\terrors: $_errors; | ||
\t\terror: $_error; | ||
\t}'''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters