|
2 | 2 |
|
3 | 3 | import 'package:equatable/equatable.dart';
|
4 | 4 |
|
| 5 | +import 'package:deriv_dependency_injector/dependency_injector.dart'; |
| 6 | +import 'package:flutter_deriv_api/api/exceptions/exceptions.dart'; |
| 7 | +import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; |
| 8 | +import 'package:flutter_deriv_api/basic_api/generated/p2p_ping_receive.dart'; |
| 9 | +import 'package:flutter_deriv_api/basic_api/generated/p2p_ping_send.dart'; |
| 10 | + |
5 | 11 | import 'package:flutter_deriv_api/helpers/helpers.dart';
|
| 12 | +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; |
6 | 13 |
|
7 | 14 | /// P2p ping response model class.
|
8 | 15 | abstract class P2pPingResponseModel {
|
@@ -44,6 +51,40 @@ class P2pPingResponse extends P2pPingResponseModel {
|
44 | 51 | return resultMap;
|
45 | 52 | }
|
46 | 53 |
|
| 54 | + static final BaseAPI _api = Injector()<BaseAPI>(); |
| 55 | + |
| 56 | + /// Requests the p2p ping request to the server. |
| 57 | + /// |
| 58 | + /// Mostly used to test the connection or to keep it alive. |
| 59 | + /// Throws a [APIBaseException] if API response contains an error. |
| 60 | + static Future<P2pPingReceive> p2pPingMethodRaw([ |
| 61 | + P2pPingRequest? request, |
| 62 | + ]) async { |
| 63 | + final P2pPingReceive response = await _api.call( |
| 64 | + request: request ?? const P2pPingRequest(), |
| 65 | + ); |
| 66 | + |
| 67 | + checkException( |
| 68 | + response: response, |
| 69 | + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => |
| 70 | + APIBaseException(baseExceptionModel: baseExceptionModel), |
| 71 | + ); |
| 72 | + |
| 73 | + return response; |
| 74 | + } |
| 75 | + |
| 76 | + /// Requests the p2p ping request to the server. |
| 77 | + /// |
| 78 | + /// Mostly used to test the connection or to keep it alive. |
| 79 | + /// Throws a [APIBaseException] if API response contains an error. |
| 80 | + static Future<P2pPingResponse> p2pPingMethod([ |
| 81 | + P2pPingRequest? request, |
| 82 | + ]) async { |
| 83 | + final P2pPingReceive response = await p2pPingMethodRaw(request); |
| 84 | + |
| 85 | + return P2pPingResponse.fromJson(response.p2pPing); |
| 86 | + } |
| 87 | + |
47 | 88 | /// Creates a copy of instance with given parameters.
|
48 | 89 | P2pPingResponse copyWith({
|
49 | 90 | P2pPingEnum? p2pPing,
|
|
0 commit comments