Skip to content

Commit

Permalink
refactor(deriv_passkeys): moved fetch and fetchRaw calls to extended …
Browse files Browse the repository at this point in the history
…response classes
  • Loading branch information
bassam-deriv committed Mar 20, 2024
1 parent 367d63a commit 861009a
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 131 deletions.
36 changes: 36 additions & 0 deletions lib/api/response/passkeys_list_response_extended.dart
Original file line number Diff line number Diff line change
@@ -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()<BaseAPI>();

/// List all passkeys.
static Future<PasskeysListResponse> fetch(
PasskeysListRequest request,
) async {
final PasskeysListReceive response = await fetchRaw(request);

return PasskeysListResponse.fromJson(response.toJson());
}

/// Fetches raw passkeys list response.
static Future<PasskeysListReceive> fetchRaw(
PasskeysListRequest request,
) async {
final PasskeysListReceive response = await _api.call(request: request);

checkException(
response: response,
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
BaseAPIException(baseExceptionModel: baseExceptionModel),
);

return response;
}
}
26 changes: 0 additions & 26 deletions lib/api/response/passkeys_list_response_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,6 @@ class PasskeysListResponse extends PasskeysListResponseModel {
return resultMap;
}

static final BaseAPI _api = Injector()<BaseAPI>();

/// List all passkeys.
static Future<PasskeysListResponse> fetch(
PasskeysListRequest request,
) async {
final PasskeysListReceive response = await fetchRaw(request);

return PasskeysListResponse.fromJson(response.toJson());
}

/// Fetches raw passkeys list response.
static Future<PasskeysListReceive> 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<PasskeysListItem>? passkeysList,
Expand Down
38 changes: 38 additions & 0 deletions lib/api/response/passkeys_register_options_response_extended.dart
Original file line number Diff line number Diff line change
@@ -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()<BaseAPI>();

/// List all register passkeys options.
static Future<PasskeysRegisterOptionsResponse> fetch(
PasskeysRegisterOptionsRequest request,
) async {
final PasskeysRegisterOptionsReceive response = await fetchRaw(request);

return PasskeysRegisterOptionsResponse.fromJson(response.toJson());
}

/// Fetches raw register passkeys options response.
static Future<PasskeysRegisterOptionsReceive> fetchRaw(
PasskeysRegisterOptionsRequest request,
) async {
final PasskeysRegisterOptionsReceive response =
await _api.call(request: request);

checkException(
response: response,
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
BaseAPIException(baseExceptionModel: baseExceptionModel),
);

return response;
}
}
27 changes: 0 additions & 27 deletions lib/api/response/passkeys_register_options_response_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,6 @@ class PasskeysRegisterOptionsResponse
return resultMap;
}

static final BaseAPI _api = Injector()<BaseAPI>();

/// List all register passkeys options.
static Future<PasskeysRegisterOptionsResponse> fetch(
PasskeysRegisterOptionsRequest request,
) async {
final PasskeysRegisterOptionsReceive response = await fetchRaw(request);

return PasskeysRegisterOptionsResponse.fromJson(response.toJson());
}

/// Fetches raw register passkeys options response.
static Future<PasskeysRegisterOptionsReceive> 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,
Expand Down
36 changes: 36 additions & 0 deletions lib/api/response/passkeys_register_response_extended.dart
Original file line number Diff line number Diff line change
@@ -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()<BaseAPI>();

/// register a new passkey.
static Future<PasskeysRegisterResponse> fetch(
PasskeysRegisterRequest request,
) async {
final PasskeysRegisterReceive response = await fetchRaw(request);

return PasskeysRegisterResponse.fromJson(response.toJson());
}

/// Fetches raw passkeys register response.
static Future<PasskeysRegisterReceive> fetchRaw(
PasskeysRegisterRequest request,
) async {
final PasskeysRegisterReceive response = await _api.call(request: request);

checkException(
response: response,
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
BaseAPIException(baseExceptionModel: baseExceptionModel),
);

return response;
}
}
26 changes: 0 additions & 26 deletions lib/api/response/passkeys_register_response_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,6 @@ class PasskeysRegisterResponse extends PasskeysRegisterResponseModel {
return resultMap;
}

static final BaseAPI _api = Injector()<BaseAPI>();

/// register a new passkey.
static Future<PasskeysRegisterResponse> fetch(
PasskeysRegisterRequest request,
) async {
final PasskeysRegisterReceive response = await fetchRaw(request);

return PasskeysRegisterResponse.fromJson(response.toJson());
}

/// Fetches raw passkeys register response.
static Future<PasskeysRegisterReceive> 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,
Expand Down
36 changes: 36 additions & 0 deletions lib/api/response/passkeys_rename_response_extended.dart
Original file line number Diff line number Diff line change
@@ -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()<BaseAPI>();

/// rename a passkey.
static Future<PasskeysRenameResponse> fetch(
PasskeysRenameRequest request,
) async {
final PasskeysRenameReceive response = await fetchRaw(request);

return PasskeysRenameResponse.fromJson(response.toJson());
}

/// Fetches raw passkeys rename response.
static Future<PasskeysRenameReceive> fetchRaw(
PasskeysRenameRequest request,
) async {
final PasskeysRenameReceive response = await _api.call(request: request);

checkException(
response: response,
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
BaseAPIException(baseExceptionModel: baseExceptionModel),
);

return response;
}
}
26 changes: 0 additions & 26 deletions lib/api/response/passkeys_rename_response_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,6 @@ class PasskeysRenameResponse extends PasskeysRenameResponseModel {
return resultMap;
}

static final BaseAPI _api = Injector()<BaseAPI>();

/// rename a passkey.
static Future<PasskeysRenameResponse> fetch(
PasskeysRenameRequest request,
) async {
final PasskeysRenameReceive response = await fetchRaw(request);

return PasskeysRenameResponse.fromJson(response.toJson());
}

/// Fetches raw passkeys rename response.
static Future<PasskeysRenameReceive> 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,
Expand Down
36 changes: 36 additions & 0 deletions lib/api/response/passkeys_revoke_response_extended.dart
Original file line number Diff line number Diff line change
@@ -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()<BaseAPI>();

/// revoke a passkey.
static Future<PasskeysRevokeResponse> fetch(
PasskeysRevokeRequest request,
) async {
final PasskeysRevokeReceive response = await fetchRaw(request);

return PasskeysRevokeResponse.fromJson(response.toJson());
}

/// Fetches raw passkeys revoke response.
static Future<PasskeysRevokeReceive> fetchRaw(
PasskeysRevokeRequest request,
) async {
final PasskeysRevokeReceive response = await _api.call(request: request);

checkException(
response: response,
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
BaseAPIException(baseExceptionModel: baseExceptionModel),
);

return response;
}
}
26 changes: 0 additions & 26 deletions lib/api/response/passkeys_revoke_response_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,6 @@ class PasskeysRevokeResponse extends PasskeysRevokeResponseModel {
return resultMap;
}

static final BaseAPI _api = Injector()<BaseAPI>();

/// revoke a passkey.
static Future<PasskeysRevokeResponse> fetch(
PasskeysRevokeRequest request,
) async {
final PasskeysRevokeReceive response = await fetchRaw(request);

return PasskeysRevokeResponse.fromJson(response.toJson());
}

/// Fetches raw passkeys revoke response.
static Future<PasskeysRevokeReceive> 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,
Expand Down

0 comments on commit 861009a

Please sign in to comment.