getProductsBySearch method

Future<ApiCallback<ProductPaginationResult>> getProductsBySearch(
  1. {String term,
  2. int page = 1,
  3. int perPage = 20,
  4. String continuationToken,
  5. ProductOrder sort,
  6. bool perSeller = false}
)

Implementation

Future<ApiCallback<ProductPaginationResult>> getProductsBySearch(
    {String term, int page = 1, int perPage = 20, String continuationToken, ProductOrder sort, bool perSeller = false}) async {
  Map<String, dynamic> queryParameters = {'page': page, 'perPage': perPage};

  queryParameters.addAll(_queryParametersForPagedProductRequest(continuationToken: continuationToken, sort: sort));

  try {
    Stopwatch stopwatch = new Stopwatch()..start();
    var response = await _requester.get(await _catalogEndpoint(API_PRODUCTS_BY_SEARCH_TERM.replaceAll("%", term), includeSeller: perSeller),
        queryParameters: queryParameters, options: Options(responseType: ResponseType.json));
    var paginationResult = ProductPaginationResult.fromJson(response.data);
    print("Page ${paginationResult.page}/${paginationResult.maxPage} loaded in ${stopwatch.elapsedMilliseconds}ms");
    return ApiCallback<ProductPaginationResult>(isSuccessful: true, resultData: paginationResult);
  } on DioError catch (e) {
    return ApiCallback<ProductPaginationResult>().defaultErrorCallback(e);
  }
}