26 lines
749 B
Dart
26 lines
749 B
Dart
import 'package:dio/dio.dart';
|
|
|
|
import '../../errors/marianumconnect_error.dart';
|
|
import '../../marianumconnect_api.dart';
|
|
import '../../marianumconnect_endpoint.dart';
|
|
import 'get_ticker_response.dart';
|
|
|
|
/// Fetches the current "Aktuelles" ticker post from
|
|
/// `GET /api/mobile/v1/ticker`. Bearer token is attached by the shared dio.
|
|
class GetTicker {
|
|
final Dio _dio;
|
|
|
|
GetTicker({Dio? dio}) : _dio = dio ?? MarianumConnectApi.dio();
|
|
|
|
Future<TickerResponse> run() async {
|
|
try {
|
|
final response = await _dio.get<Map<String, dynamic>>(
|
|
MarianumConnectEndpoint.resolve('ticker'),
|
|
);
|
|
return TickerResponse.fromJson(response.data!);
|
|
} on DioException catch (e) {
|
|
throw mapMarianumConnectError(e);
|
|
}
|
|
}
|
|
}
|