From 861009ae1ceca291c31d72d9b9d8de086920ff67 Mon Sep 17 00:00:00 2001 From: bassam-deriv Date: Wed, 20 Mar 2024 15:36:04 +0400 Subject: [PATCH] refactor(deriv_passkeys): moved fetch and fetchRaw calls to extended response classes --- .../passkeys_list_response_extended.dart | 36 ++++++++++++++++++ .../passkeys_list_response_result.dart | 26 ------------- ...ys_register_options_response_extended.dart | 38 +++++++++++++++++++ ...keys_register_options_response_result.dart | 27 ------------- .../passkeys_register_response_extended.dart | 36 ++++++++++++++++++ .../passkeys_register_response_result.dart | 26 ------------- .../passkeys_rename_response_extended.dart | 36 ++++++++++++++++++ .../passkeys_rename_response_result.dart | 26 ------------- .../passkeys_revoke_response_extended.dart | 36 ++++++++++++++++++ .../passkeys_revoke_response_result.dart | 26 ------------- 10 files changed, 182 insertions(+), 131 deletions(-) create mode 100644 lib/api/response/passkeys_list_response_extended.dart create mode 100644 lib/api/response/passkeys_register_options_response_extended.dart create mode 100644 lib/api/response/passkeys_register_response_extended.dart create mode 100644 lib/api/response/passkeys_rename_response_extended.dart create mode 100644 lib/api/response/passkeys_revoke_response_extended.dart diff --git a/lib/api/response/passkeys_list_response_extended.dart b/lib/api/response/passkeys_list_response_extended.dart new file mode 100644 index 0000000000..3208ea3ab4 --- /dev/null +++ b/lib/api/response/passkeys_list_response_extended.dart @@ -0,0 +1,36 @@ +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; +import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; +import 'package:flutter_deriv_api/api/response/passkeys_list_response_result.dart'; +import 'package:flutter_deriv_api/basic_api/generated/api.dart'; +import 'package:flutter_deriv_api/helpers/helpers.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; + +/// Extended functionality for [PasskeysListResponse] class. +class PasskeysListResponseExtended extends PasskeysListResponse { + static final BaseAPI _api = Injector()(); + + /// List all passkeys. + static Future fetch( + PasskeysListRequest request, + ) async { + final PasskeysListReceive response = await fetchRaw(request); + + return PasskeysListResponse.fromJson(response.toJson()); + } + + /// Fetches raw passkeys list response. + static Future fetchRaw( + PasskeysListRequest request, + ) async { + final PasskeysListReceive response = await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return response; + } +} diff --git a/lib/api/response/passkeys_list_response_result.dart b/lib/api/response/passkeys_list_response_result.dart index c396f86a7e..d6ba1afb53 100644 --- a/lib/api/response/passkeys_list_response_result.dart +++ b/lib/api/response/passkeys_list_response_result.dart @@ -57,32 +57,6 @@ class PasskeysListResponse extends PasskeysListResponseModel { return resultMap; } - static final BaseAPI _api = Injector()(); - - /// List all passkeys. - static Future fetch( - PasskeysListRequest request, - ) async { - final PasskeysListReceive response = await fetchRaw(request); - - return PasskeysListResponse.fromJson(response.toJson()); - } - - /// Fetches raw passkeys list response. - static Future fetchRaw( - PasskeysListRequest request, - ) async { - final PasskeysListReceive response = await _api.call(request: request); - - checkException( - response: response, - exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => - BaseAPIException(baseExceptionModel: baseExceptionModel), - ); - - return response; - } - /// Creates a copy of instance with given parameters. PasskeysListResponse copyWith({ List? passkeysList, diff --git a/lib/api/response/passkeys_register_options_response_extended.dart b/lib/api/response/passkeys_register_options_response_extended.dart new file mode 100644 index 0000000000..5affaa9efd --- /dev/null +++ b/lib/api/response/passkeys_register_options_response_extended.dart @@ -0,0 +1,38 @@ +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; +import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; +import 'package:flutter_deriv_api/api/response/passkeys_register_options_response_result.dart'; +import 'package:flutter_deriv_api/basic_api/generated/api.dart'; +import 'package:flutter_deriv_api/helpers/helpers.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; + +/// Extended functionality for [PasskeysRegisterOptionsResponse] class. +class PasskeysRegisterOptionsResponseExtended + extends PasskeysRegisterOptionsResponse { + static final BaseAPI _api = Injector()(); + + /// List all register passkeys options. + static Future fetch( + PasskeysRegisterOptionsRequest request, + ) async { + final PasskeysRegisterOptionsReceive response = await fetchRaw(request); + + return PasskeysRegisterOptionsResponse.fromJson(response.toJson()); + } + + /// Fetches raw register passkeys options response. + static Future fetchRaw( + PasskeysRegisterOptionsRequest request, + ) async { + final PasskeysRegisterOptionsReceive response = + await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return response; + } +} diff --git a/lib/api/response/passkeys_register_options_response_result.dart b/lib/api/response/passkeys_register_options_response_result.dart index 7bef9942c7..83b1e10b31 100644 --- a/lib/api/response/passkeys_register_options_response_result.dart +++ b/lib/api/response/passkeys_register_options_response_result.dart @@ -51,33 +51,6 @@ class PasskeysRegisterOptionsResponse return resultMap; } - static final BaseAPI _api = Injector()(); - - /// List all register passkeys options. - static Future fetch( - PasskeysRegisterOptionsRequest request, - ) async { - final PasskeysRegisterOptionsReceive response = await fetchRaw(request); - - return PasskeysRegisterOptionsResponse.fromJson(response.toJson()); - } - - /// Fetches raw register passkeys options response. - static Future fetchRaw( - PasskeysRegisterOptionsRequest request, - ) async { - final PasskeysRegisterOptionsReceive response = - await _api.call(request: request); - - checkException( - response: response, - exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => - BaseAPIException(baseExceptionModel: baseExceptionModel), - ); - - return response; - } - /// Creates a copy of instance with given parameters. PasskeysRegisterOptionsResponse copyWith({ PasskeysRegisterOptions? passkeysRegisterOptions, diff --git a/lib/api/response/passkeys_register_response_extended.dart b/lib/api/response/passkeys_register_response_extended.dart new file mode 100644 index 0000000000..d5ef3927a1 --- /dev/null +++ b/lib/api/response/passkeys_register_response_extended.dart @@ -0,0 +1,36 @@ +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; +import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; +import 'package:flutter_deriv_api/api/response/passkeys_register_response_result.dart'; +import 'package:flutter_deriv_api/basic_api/generated/api.dart'; +import 'package:flutter_deriv_api/helpers/helpers.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; + +/// Extended functionality for [PasskeysRegisterResponse] class. +class PasskeysRegisterResponseExtended extends PasskeysRegisterResponse { + static final BaseAPI _api = Injector()(); + + /// register a new passkey. + static Future fetch( + PasskeysRegisterRequest request, + ) async { + final PasskeysRegisterReceive response = await fetchRaw(request); + + return PasskeysRegisterResponse.fromJson(response.toJson()); + } + + /// Fetches raw passkeys register response. + static Future fetchRaw( + PasskeysRegisterRequest request, + ) async { + final PasskeysRegisterReceive response = await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return response; + } +} diff --git a/lib/api/response/passkeys_register_response_result.dart b/lib/api/response/passkeys_register_response_result.dart index d7df0d7f1f..133daa46f4 100644 --- a/lib/api/response/passkeys_register_response_result.dart +++ b/lib/api/response/passkeys_register_response_result.dart @@ -49,32 +49,6 @@ class PasskeysRegisterResponse extends PasskeysRegisterResponseModel { return resultMap; } - static final BaseAPI _api = Injector()(); - - /// register a new passkey. - static Future fetch( - PasskeysRegisterRequest request, - ) async { - final PasskeysRegisterReceive response = await fetchRaw(request); - - return PasskeysRegisterResponse.fromJson(response.toJson()); - } - - /// Fetches raw passkeys register response. - static Future fetchRaw( - PasskeysRegisterRequest request, - ) async { - final PasskeysRegisterReceive response = await _api.call(request: request); - - checkException( - response: response, - exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => - BaseAPIException(baseExceptionModel: baseExceptionModel), - ); - - return response; - } - /// Creates a copy of instance with given parameters. PasskeysRegisterResponse copyWith({ PasskeysRegister? passkeysRegister, diff --git a/lib/api/response/passkeys_rename_response_extended.dart b/lib/api/response/passkeys_rename_response_extended.dart new file mode 100644 index 0000000000..2ce3be5369 --- /dev/null +++ b/lib/api/response/passkeys_rename_response_extended.dart @@ -0,0 +1,36 @@ +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; +import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; +import 'package:flutter_deriv_api/api/response/passkeys_rename_response_result.dart'; +import 'package:flutter_deriv_api/basic_api/generated/api.dart'; +import 'package:flutter_deriv_api/helpers/helpers.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; + +/// Extended functionality for [PasskeysRenameResponse] class. +class PasskeysRenameResponseExtended extends PasskeysRenameResponse { + static final BaseAPI _api = Injector()(); + + /// rename a passkey. + static Future fetch( + PasskeysRenameRequest request, + ) async { + final PasskeysRenameReceive response = await fetchRaw(request); + + return PasskeysRenameResponse.fromJson(response.toJson()); + } + + /// Fetches raw passkeys rename response. + static Future fetchRaw( + PasskeysRenameRequest request, + ) async { + final PasskeysRenameReceive response = await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return response; + } +} diff --git a/lib/api/response/passkeys_rename_response_result.dart b/lib/api/response/passkeys_rename_response_result.dart index 940c57266c..40c099eee2 100644 --- a/lib/api/response/passkeys_rename_response_result.dart +++ b/lib/api/response/passkeys_rename_response_result.dart @@ -45,32 +45,6 @@ class PasskeysRenameResponse extends PasskeysRenameResponseModel { return resultMap; } - static final BaseAPI _api = Injector()(); - - /// rename a passkey. - static Future fetch( - PasskeysRenameRequest request, - ) async { - final PasskeysRenameReceive response = await fetchRaw(request); - - return PasskeysRenameResponse.fromJson(response.toJson()); - } - - /// Fetches raw passkeys rename response. - static Future fetchRaw( - PasskeysRenameRequest request, - ) async { - final PasskeysRenameReceive response = await _api.call(request: request); - - checkException( - response: response, - exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => - BaseAPIException(baseExceptionModel: baseExceptionModel), - ); - - return response; - } - /// Creates a copy of instance with given parameters. PasskeysRenameResponse copyWith({ int? passkeysRename, diff --git a/lib/api/response/passkeys_revoke_response_extended.dart b/lib/api/response/passkeys_revoke_response_extended.dart new file mode 100644 index 0000000000..aa6d97074d --- /dev/null +++ b/lib/api/response/passkeys_revoke_response_extended.dart @@ -0,0 +1,36 @@ +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; +import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; +import 'package:flutter_deriv_api/api/response/passkeys_revoke_response_result.dart'; +import 'package:flutter_deriv_api/basic_api/generated/api.dart'; +import 'package:flutter_deriv_api/helpers/helpers.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; + +/// Extended functionality for [PasskeysRevokeReceive] class. +class PasskeysRevokeReceiveExtended extends PasskeysRevokeReceive { + static final BaseAPI _api = Injector()(); + + /// revoke a passkey. + static Future fetch( + PasskeysRevokeRequest request, + ) async { + final PasskeysRevokeReceive response = await fetchRaw(request); + + return PasskeysRevokeResponse.fromJson(response.toJson()); + } + + /// Fetches raw passkeys revoke response. + static Future fetchRaw( + PasskeysRevokeRequest request, + ) async { + final PasskeysRevokeReceive response = await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return response; + } +} diff --git a/lib/api/response/passkeys_revoke_response_result.dart b/lib/api/response/passkeys_revoke_response_result.dart index edc2576ada..d4c1398866 100644 --- a/lib/api/response/passkeys_revoke_response_result.dart +++ b/lib/api/response/passkeys_revoke_response_result.dart @@ -45,32 +45,6 @@ class PasskeysRevokeResponse extends PasskeysRevokeResponseModel { return resultMap; } - static final BaseAPI _api = Injector()(); - - /// revoke a passkey. - static Future fetch( - PasskeysRevokeRequest request, - ) async { - final PasskeysRevokeReceive response = await fetchRaw(request); - - return PasskeysRevokeResponse.fromJson(response.toJson()); - } - - /// Fetches raw passkeys revoke response. - static Future fetchRaw( - PasskeysRevokeRequest request, - ) async { - final PasskeysRevokeReceive response = await _api.call(request: request); - - checkException( - response: response, - exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => - BaseAPIException(baseExceptionModel: baseExceptionModel), - ); - - return response; - } - /// Creates a copy of instance with given parameters. PasskeysRevokeResponse copyWith({ int? passkeysRevoke,