Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reza/accept_null_request_json #314

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/lib/blocs/active_symbols/active_symbols_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ class ActiveSymbolsBloc extends Bloc<ActiveSymbolsEvent, ActiveSymbolsState> {
Future<ActiveSymbolsResponse> _fetchActiveSymbols() async =>
ActiveSymbolsResponse.fetchActiveSymbols(const ActiveSymbolsRequest(
activeSymbols: 'brief',
productType: 'basic',
productType: 'basic', landingCompany: '',
));
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:flutter_deriv_api/basic_api/generated/api.dart';
import '../active_symbols/active_symbols_bloc.dart';

part 'available_contracts_event.dart';

part 'available_contracts_state.dart';

/// AvailableContractsBloc
Expand Down Expand Up @@ -75,5 +76,6 @@ class AvailableContractsBloc
) async =>
ContractsForResponse.fetchContractsForSymbol(ContractsForRequest(
contractsFor: selectedSymbol?.symbol,
landingCompany: '',
));
}
6 changes: 5 additions & 1 deletion lib/api/response/p2p_advert_create_response_result.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import

import 'package:equatable/equatable.dart';
import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart';

import 'package:flutter_deriv_api/api/exceptions/p2p_advert_exception.dart';
import 'package:flutter_deriv_api/api/models/base_exception_model.dart';
import 'package:flutter_deriv_api/basic_api/generated/p2p_advert_create_receive.dart';
import 'package:flutter_deriv_api/basic_api/generated/p2p_advert_create_send.dart';
Expand Down Expand Up @@ -221,6 +221,7 @@ enum VisibilityStatusItemEnum {
/// advertiser_temp_ban.
advertiserTempBan,
}

/// P2p advert create model class.
abstract class P2pAdvertCreateModel {
/// Initializes P2p advert create model class .
Expand Down Expand Up @@ -720,6 +721,7 @@ class P2pAdvertCreate extends P2pAdvertCreateModel {
visibilityStatus: visibilityStatus ?? this.visibilityStatus,
);
}

/// Advertiser details model class.
abstract class AdvertiserDetailsModel {
/// Initializes Advertiser details model class .
Expand Down Expand Up @@ -861,6 +863,7 @@ class AdvertiserDetails extends AdvertiserDetailsModel {
totalCompletionRate: totalCompletionRate ?? this.totalCompletionRate,
);
}

/// Payment method details property model class.
abstract class PaymentMethodDetailsPropertyModel {
/// Initializes Payment method details property model class .
Expand Down Expand Up @@ -989,6 +992,7 @@ class PaymentMethodDetailsProperty extends PaymentMethodDetailsPropertyModel {
usedByOrders: usedByOrders ?? this.usedByOrders,
);
}

/// Fields property model class.
abstract class FieldsPropertyModel {
/// Initializes Fields property model class .
Expand Down
2 changes: 1 addition & 1 deletion lib/api/response/p2p_advert_list_response_result.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import

import 'package:equatable/equatable.dart';
import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart';

import 'package:flutter_deriv_api/api/exceptions/p2p_advert_exception.dart';
import 'package:flutter_deriv_api/api/models/base_exception_model.dart';
import 'package:flutter_deriv_api/basic_api/generated/p2p_advert_list_receive.dart';
import 'package:flutter_deriv_api/basic_api/generated/p2p_advert_list_send.dart';
Expand Down
5 changes: 4 additions & 1 deletion lib/services/connection/api_manager/base_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ abstract class BaseAPI {
void addToChannel(Map<String, dynamic> request);

/// Calls a API method by [request].
Future<T> call<T>({required Request request});
Future<T> call<T>({
required Request request,
List<String> nullableKeys = const <String>[],
});

/// Subscribe to a [request].
/// [comparePredicate] indicates compare condition for current [request] and [pendingRequest]s
Expand Down
4 changes: 3 additions & 1 deletion lib/services/connection/api_manager/binary_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ class BinaryAPI extends BaseAPI {
}

@override
Future<T> call<T>({required Request request}) async {
Future<T> call<T>(
{required Request request, List<String> nullableKeys = const <String>[],}) async {
final Response response = await (_callManager ??= CallManager(this))(
request: request,
nullableKeys: nullableKeys,
);

if (response is T) {
Expand Down
5 changes: 4 additions & 1 deletion lib/services/connection/api_manager/mock_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ class MockAPI extends BaseAPI {
void addToChannel(Map<String, dynamic> request) {}

@override
Future<T> call<T>({required Request request}) =>
Future<T> call<T>({
required Request request,
List<String> nullableKeys = const <String>[],
}) =>
_getFutureResponse<T>(request);

@override
Expand Down
11 changes: 9 additions & 2 deletions lib/services/connection/call_manager/base_call_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ abstract class BaseCallManager<T> {
bool contains(int? requestId) => _pendingRequests.containsKey(requestId);

/// Calls a API method by [request]
T call({required Request request});
T call({
required Request request,
List<String> nullableKeys = const <String>[],
});

/// Handle call [response] that comes from server
void handleResponse({
Expand All @@ -62,12 +65,14 @@ abstract class BaseCallManager<T> {
Future<Response> addToChannel({
required Request request,
SubscriptionStream<Response>? subscriptionStream,
List<String> nullableKeys = const <String>[],
}) {
final Completer<Response> responseCompleter = Completer<Response>();
final Request requestWithId = request.copyWith(reqId: _getRequestId());
final Map<String, dynamic> prepareRequest = _prepareRequest(
request: requestWithId,
isSubscription: subscriptionStream != null,
nullableKeys: nullableKeys,
);

_addPendingRequest(
Expand Down Expand Up @@ -104,9 +109,11 @@ abstract class BaseCallManager<T> {
Map<String, dynamic> _prepareRequest({
required Request request,
required bool isSubscription,
List<String> nullableKeys = const <String>[],
}) {
final Map<String, dynamic> result = request.toJson()
..removeWhere((String key, dynamic value) => value == null);
..removeWhere((String key, dynamic value) =>
value == null && !(nullableKeys.contains(key)));

if (isSubscription) {
result.putIfAbsent('subscribe', () => 1);
Expand Down
7 changes: 5 additions & 2 deletions lib/services/connection/call_manager/call_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class CallManager extends BaseCallManager<Future<Response>> {
}

@override
Future<Response> call({required Request request}) async =>
addToChannel(request: request);
Future<Response> call({
required Request request,
List<String> nullableKeys = const <String>[],
}) async =>
addToChannel(request: request, nullableKeys: nullableKeys);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SubscriptionManager extends BaseCallManager<Stream<Response>> {
required Request request,
int cacheSize = 0,
RequestCompareFunction? comparePredicate,
List<String> nullableKeys = const <String>[],
}) {
assert(cacheSize >= 0);

Expand All @@ -78,6 +79,7 @@ class SubscriptionManager extends BaseCallManager<Stream<Response>> {
addToChannel(
request: request,
subscriptionStream: subscriptionStream,
nullableKeys: nullableKeys,
);

return subscriptionStream.stream;
Expand Down
1 change: 1 addition & 0 deletions test/api/account/authorize/authorize_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void main() {
const AuthorizeRequest(
authorize: 'sample_token_334da73d',
addToLoginHistory: true,
tokens: [],
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ void main() {
request: const NewAccountWalletRequest(
accountType: 'crypto',
currency: 'BTC',
acceptRisk: null,
financialAssessment: {},
salutation: '',
taxIdentificationNumber: '',
taxResidence: '',
),
);

Expand Down
1 change: 1 addition & 0 deletions test/api/common/active_symbols/active_symbols_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void main() {
const ActiveSymbolsRequest(
activeSymbols: 'brief',
productType: 'basic',
landingCompany: '',
),
);

Expand Down
11 changes: 9 additions & 2 deletions test/services/call_manager/base_call_manager_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ class MockCallManager extends BaseCallManager<MockResponse> {
MockCallManager(BaseAPI api) : super(api);

@override
MockResponse call({required Request request}) {
MockResponse call({
required Request request,
List<String> nullableKeys = const <String>[],
}) {
throw UnimplementedError();
}
}
Expand All @@ -60,7 +63,11 @@ class MockAPI implements BaseAPI {
void addToChannel(Map<String, dynamic> request) {}

@override
Future<T> call<T>({required Request request}) => throw UnimplementedError();
Future<T> call<T>({
required Request request,
List<String> nullableKeys = const <String>[],
}) =>
throw UnimplementedError();

@override
Future<void> connect(
Expand Down
Loading