dart format
This commit is contained in:
@@ -9,7 +9,8 @@ import 'authenticate_response.dart';
|
||||
class Authenticate extends WebuntisApi {
|
||||
AuthenticateParams param;
|
||||
|
||||
Authenticate(this.param) : super('authenticate', param, authenticatedResponse: false);
|
||||
Authenticate(this.param)
|
||||
: super('authenticate', param, authenticatedResponse: false);
|
||||
|
||||
@override
|
||||
Future<AuthenticateResponse> run() async {
|
||||
@@ -17,7 +18,11 @@ class Authenticate extends WebuntisApi {
|
||||
try {
|
||||
final rawAnswer = await query(this);
|
||||
final decoded = jsonDecode(rawAnswer) as Map<String, dynamic>;
|
||||
final response = finalize(AuthenticateResponse.fromJson(decoded['result'] as Map<String, dynamic>));
|
||||
final response = finalize(
|
||||
AuthenticateResponse.fromJson(
|
||||
decoded['result'] as Map<String, dynamic>,
|
||||
),
|
||||
);
|
||||
_lastResponse = response;
|
||||
if (!awaitedResponse.isCompleted) awaitedResponse.complete();
|
||||
return response;
|
||||
@@ -40,23 +45,22 @@ class Authenticate extends WebuntisApi {
|
||||
|
||||
static Future<void> createSession() async {
|
||||
_lastResponse = await Authenticate(
|
||||
AuthenticateParams(
|
||||
user: AccountData().getUsername(),
|
||||
password: AccountData().getPassword(),
|
||||
)
|
||||
AuthenticateParams(
|
||||
user: AccountData().getUsername(),
|
||||
password: AccountData().getPassword(),
|
||||
),
|
||||
).run();
|
||||
}
|
||||
|
||||
static Future<AuthenticateResponse> getSession() async {
|
||||
if(awaitingResponse) {
|
||||
if (awaitingResponse) {
|
||||
await awaitedResponse.future;
|
||||
}
|
||||
|
||||
if(_lastResponse == null) {
|
||||
if (_lastResponse == null) {
|
||||
awaitingResponse = true;
|
||||
await createSession();
|
||||
}
|
||||
return _lastResponse!;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@ part 'authenticate_params.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class AuthenticateParams extends ApiParams {
|
||||
|
||||
String user;
|
||||
String password;
|
||||
|
||||
AuthenticateParams({required this.user, required this.password});
|
||||
factory AuthenticateParams.fromJson(Map<String, dynamic> json) => _$AuthenticateParamsFromJson(json);
|
||||
factory AuthenticateParams.fromJson(Map<String, dynamic> json) =>
|
||||
_$AuthenticateParamsFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$AuthenticateParamsToJson(this);
|
||||
}
|
||||
|
||||
@@ -6,14 +6,19 @@ part 'authenticate_response.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class AuthenticateResponse extends ApiResponse {
|
||||
|
||||
String sessionId;
|
||||
int personType;
|
||||
int personId;
|
||||
int klasseId;
|
||||
|
||||
AuthenticateResponse(this.sessionId, this.personType, this.personId, this.klasseId);
|
||||
AuthenticateResponse(
|
||||
this.sessionId,
|
||||
this.personType,
|
||||
this.personId,
|
||||
this.klasseId,
|
||||
);
|
||||
|
||||
factory AuthenticateResponse.fromJson(Map<String, dynamic> json) => _$AuthenticateResponseFromJson(json);
|
||||
factory AuthenticateResponse.fromJson(Map<String, dynamic> json) =>
|
||||
_$AuthenticateResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$AuthenticateResponseToJson(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user