Skip to content

Commit

Permalink
feat!: 801 - more url flexibility with non static UriHelper (#803)
Browse files Browse the repository at this point in the history
Deleted file:
* `query_type.dart`

Impacted files:
* `abstract_query_configuration.dart`: replaced `QueryType` with `UriHelper`
* `api_add_product_image_test.dart`: explicit usage of `uriHelperFoodTest`
* `api_events_test.dart`: explicit usage of `uriHelperEventsTest`
* `api_folksonomy_test.dart`: removed implicit usage of prod env
* `api_get_product_image_ids_test.dart`: removed implicit usage of prod env
* `api_get_product_test.dart`: removed implicit usage of prod env
* `api_get_robotoff_test.dart`: removed implicit usage of prod env
* `api_get_save_product_test.dart`: explicit usage of `uriHelperFoodTest`
* `api_get_suggestions_test.dart`: removed implicit usage of prod env
* `api_get_taxonomy_additives_server_test.dart`: removed implicit usage of prod env
* `api_get_taxonomy_allergens_server_test.dart`: removed implicit usage of prod env
* `api_get_taxonomy_categories_server_test.dart`: removed implicit usage of prod env
* `api_get_taxonomy_countries_server_test.dart`: removed implicit usage of prod env
* `api_get_taxonomy_ingredients_server_test.dart`: removed implicit usage of prod env
* `api_get_taxonomy_labels_server_test.dart`: removed implicit usage of prod env
* `api_get_taxonomy_languages_server_test.dart`: removed implicit usage of prod env
* `api_get_taxonomy_nova_server_test.dart`: removed implicit usage of prod env
* `api_get_taxonomy_origins_server_test.dart`: removed implicit usage of prod env
* `api_get_taxonomy_packaging_materials_server_test.dart`: removed implicit usage of prod env
* `api_get_taxonomy_packaging_recycling_server_test.dart`: removed implicit usage of prod env
* `api_get_taxonomy_packaging_shapes_server_test.dart`: removed implicit usage of prod env
* `api_get_taxonomy_packagings_server_test.dart`: removed implicit usage of prod env
* `api_get_to_be_completed_products_test.dart`: removed implicit usage of prod env
* `api_get_user_products_test.dart`: removed implicit usage of prod env
* `api_json_to_from_test.dart`: removed implicit usage of prod env
* `api_matched_product_v1_test.dart`: removed implicit usage of prod env
* `api_matched_product_v2_test.dart`: removed implicit usage of prod env
* `api_ocr_ingredients_test.dart`: removed implicit usage of prod env
* `api_post_robotoff_test.dart`: explicit usage of `uriHelperRobotoffTest`
* `api_product_preferences_test.dart`: removed implicit usage of prod env
* `api_save_product_test.dart`: explicit usage of `uriHelperFoodTest`
* `api_save_product_v3_test.dart`: explicit usage of `uriHelperFoodTest`
* `api_search_products_test.dart`: removed implicit usage of prod env
* `api_suggestion_manager_test.dart`: removed implicit usage of prod env
* `configuration_test.dart`: replaced `QueryType` with `UriHelper`
* `events.dart`: replaced `QueryType` with `UriHelper`
* `folksonomy.dart`: replaced `QueryType` with `UriHelper`
* `http_helper.dart`: replaced `QueryType` with `UriHelper`
* `image_helper.dart`: replaced `QueryType` with `UriHelper`
* `open_food_api_client.dart`: replaced `QueryType` with `UriHelper`
* `open_food_api_configuration.dart`: replaced all static `String`s with `const` instances of `UriHelper`
* `openfoodfacts.dart`: removed `query_type.dart`
* `ordered_nutrient_test.dart`: removed implicit usage of prod env
* `product_helper.dart`: now using `UriHelper` instead of `QueryType`
* `product_query_configurations.dart`: replaced `QueryType` with `UriHelper`
* `robot_off_api_client.dart`: replaced `QueryType` with `UriHelper`
* `suggestion_manager.dart`: replaced `QueryType` with `UriHelper`
* `taxonomy_query_configuration.dart`: replaced `QueryType` with `UriHelper`
* `uri_helper.dart`: made the class non static for more flexibility; replaced `QueryType` with `UriHelper`
* `user_management_test_prod.dart`: removed implicit usage of prod env
* `user_management_test_test_env.dart`: explicit usage of `uriHelperFoodTest`
  • Loading branch information
monsieurtanuki committed Sep 19, 2023
1 parent fc2e907 commit 7753cb0
Show file tree
Hide file tree
Showing 52 changed files with 449 additions and 466 deletions.
1 change: 0 additions & 1 deletion lib/openfoodfacts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export 'src/utils/product_fields.dart';
export 'src/utils/product_helper.dart';
export 'src/utils/product_query_configurations.dart';
export 'src/utils/product_search_query_configuration.dart';
export 'src/utils/query_type.dart';
export 'src/model/robotoff_question_order.dart';
export 'src/utils/server_type.dart';
export 'src/utils/suggestion_manager.dart';
Expand Down
37 changes: 16 additions & 21 deletions lib/src/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'model/events_base.dart';
import 'model/leaderboard_entry.dart';

import 'utils/http_helper.dart';
import 'utils/query_type.dart';
import 'utils/open_food_api_configuration.dart';
import 'utils/uri_helper.dart';

/// Client calls of the Events API (Open Food Facts).
Expand All @@ -21,7 +21,7 @@ class EventsAPIClient {
final String? deviceId,
final int? skip,
final int? limit,
final QueryType? queryType,
final UriHelper uriHelper = uriHelperEventsProd,
}) async {
final Map<String, String> parameters = <String, String>{};
if (userId != null) {
Expand All @@ -37,12 +37,11 @@ class EventsAPIClient {
parameters['limit'] = limit.toString();
}
final Response response = await HttpHelper().doGetRequest(
UriHelper.getEventsUri(
uriHelper.getUri(
path: '/events',
queryParameters: parameters,
queryType: queryType,
),
queryType: queryType,
uriHelper: uriHelper,
);
_checkResponse(response);
final List<EventsBase> result = <EventsBase>[];
Expand All @@ -58,7 +57,7 @@ class EventsAPIClient {
static Future<Map<String, int>> getEventsCount({
final String? userId,
final String? deviceId,
final QueryType? queryType,
final UriHelper uriHelper = uriHelperEventsProd,
}) async {
final Map<String, String> parameters = <String, String>{};
if (userId != null) {
Expand All @@ -68,12 +67,11 @@ class EventsAPIClient {
parameters['device_id'] = deviceId;
}
final Response response = await HttpHelper().doGetRequest(
UriHelper.getEventsUri(
uriHelper.getUri(
path: '/events/count',
queryParameters: parameters,
queryType: queryType,
),
queryType: queryType,
uriHelper: uriHelper,
);
_checkResponse(response);
final Map<String, int> result = <String, int>{};
Expand All @@ -90,7 +88,7 @@ class EventsAPIClient {
final String? userId,
final String? deviceId,
final String? eventType,
final QueryType? queryType,
final UriHelper uriHelper = uriHelperEventsProd,
}) async {
final Map<String, String> parameters = <String, String>{};
if (userId != null) {
Expand All @@ -103,12 +101,11 @@ class EventsAPIClient {
parameters['event_type'] = eventType;
}
final Response response = await HttpHelper().doGetRequest(
UriHelper.getEventsUri(
uriHelper.getUri(
path: '/scores',
queryParameters: parameters,
queryType: queryType,
),
queryType: queryType,
uriHelper: uriHelper,
);
_checkResponse(response);
final Map<String, dynamic> json =
Expand All @@ -120,7 +117,7 @@ class EventsAPIClient {
static Future<List<BadgeBase>> getBadges({
final String? userId,
final String? deviceId,
final QueryType? queryType,
final UriHelper uriHelper = uriHelperEventsProd,
}) async {
final Map<String, String> parameters = <String, String>{};
if (userId != null) {
Expand All @@ -130,12 +127,11 @@ class EventsAPIClient {
parameters['device_id'] = deviceId;
}
final Response response = await HttpHelper().doGetRequest(
UriHelper.getEventsUri(
uriHelper.getUri(
path: '/badges',
queryParameters: parameters,
queryType: queryType,
),
queryType: queryType,
uriHelper: uriHelper,
);
_checkResponse(response);
final List<BadgeBase> result = <BadgeBase>[];
Expand All @@ -150,19 +146,18 @@ class EventsAPIClient {
/// Returns all the [LeaderboardEntry], with optional filters.
static Future<List<LeaderboardEntry>> getLeaderboard({
final String? eventType,
final QueryType? queryType,
final UriHelper uriHelper = uriHelperEventsProd,
}) async {
final Map<String, String> parameters = <String, String>{};
if (eventType != null) {
parameters['event_type'] = eventType;
}
final Response response = await HttpHelper().doGetRequest(
UriHelper.getEventsUri(
uriHelper.getUri(
path: '/leaderboard',
queryParameters: parameters,
queryType: queryType,
),
queryType: queryType,
uriHelper: uriHelper,
);
_checkResponse(response);
final List<LeaderboardEntry> result = <LeaderboardEntry>[];
Expand Down
65 changes: 28 additions & 37 deletions lib/src/folksonomy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'model/product_list.dart';
import 'model/product_stats.dart';
import 'model/product_tag.dart';
import 'utils/http_helper.dart';
import 'utils/query_type.dart';
import 'utils/open_food_api_configuration.dart';
import 'utils/uri_helper.dart';

/// Client calls of the Folksonomy API (Open Food Facts)
Expand All @@ -18,14 +18,13 @@ class FolksonomyAPIClient {

/// "hello world"
static Future<void> hello({
final QueryType? queryType,
final UriHelper uriHelper = uriHelperFolksonomyProd,
}) async {
final Response response = await HttpHelper().doGetRequest(
UriHelper.getFolksonomyUri(
uriHelper.getUri(
path: '/',
queryType: queryType,
),
queryType: queryType,
uriHelper: uriHelper,
);
_checkResponse(response);
}
Expand All @@ -36,7 +35,7 @@ class FolksonomyAPIClient {
static Future<List<ProductStats>> getProductStats({
final String? key,
final String? value,
final QueryType? queryType,
final UriHelper uriHelper = uriHelperFolksonomyProd,
}) async {
final Map<String, String> parameters = <String, String>{};
/* TODO
Expand All @@ -55,12 +54,11 @@ class FolksonomyAPIClient {
parameters['v'] = value;
}
final Response response = await HttpHelper().doGetRequest(
UriHelper.getFolksonomyUri(
uriHelper.getUri(
path: 'products/stats',
queryParameters: parameters,
queryType: queryType,
),
queryType: queryType,
uriHelper: uriHelper,
);
_checkResponse(response);
final List<ProductStats> result = <ProductStats>[];
Expand All @@ -82,7 +80,7 @@ class FolksonomyAPIClient {
static Future<Map<String, String>> getProducts({
required final String key,
final String? value,
final QueryType? queryType,
final UriHelper uriHelper = uriHelperFolksonomyProd,
}) async {
final Map<String, String> parameters = <String, String>{};
/* TODO
Expand All @@ -95,12 +93,11 @@ class FolksonomyAPIClient {
parameters['v'] = value;
}
final Response response = await HttpHelper().doGetRequest(
UriHelper.getFolksonomyUri(
uriHelper.getUri(
path: 'products',
queryParameters: parameters,
queryType: queryType,
),
queryType: queryType,
uriHelper: uriHelper,
);
_checkResponse(response);
final Map<String, String> result = <String, String>{};
Expand All @@ -121,7 +118,7 @@ class FolksonomyAPIClient {
/// The key of the returned map is the tag key.
static Future<Map<String, ProductTag>> getProductTags({
required final String barcode,
final QueryType? queryType,
final UriHelper uriHelper = uriHelperFolksonomyProd,
}) async {
final Map<String, String> parameters = <String, String>{};
/* TODO
Expand All @@ -130,12 +127,11 @@ class FolksonomyAPIClient {
}
*/
final Response response = await HttpHelper().doGetRequest(
UriHelper.getFolksonomyUri(
uriHelper.getUri(
path: 'product/$barcode',
queryParameters: parameters,
queryType: queryType,
),
queryType: queryType,
uriHelper: uriHelper,
);
_checkResponse(response);
final Map<String, ProductTag> result = <String, ProductTag>{};
Expand All @@ -158,7 +154,7 @@ class FolksonomyAPIClient {
static Future<ProductTag?> getProductTag({
required final String barcode,
required final String key,
final QueryType? queryType,
final UriHelper uriHelper = uriHelperFolksonomyProd,
}) async {
final Map<String, String> parameters = <String, String>{};
/* TODO
Expand All @@ -167,12 +163,11 @@ class FolksonomyAPIClient {
}
*/
final Response response = await HttpHelper().doGetRequest(
UriHelper.getFolksonomyUri(
uriHelper.getUri(
path: 'product/$barcode/$key',
queryParameters: parameters,
queryType: queryType,
),
queryType: queryType,
uriHelper: uriHelper,
);
_checkResponse(response);
if (response.body == 'null') {
Expand All @@ -190,7 +185,7 @@ class FolksonomyAPIClient {
static Future<Map<String, ProductTag>> getProductTagWithSubKeys({
required final String barcode,
required final String key,
final QueryType? queryType,
final UriHelper uriHelper = uriHelperFolksonomyProd,
}) async {
final Map<String, String> parameters = <String, String>{};
/* TODO
Expand All @@ -199,12 +194,11 @@ class FolksonomyAPIClient {
}
*/
final Response response = await HttpHelper().doGetRequest(
UriHelper.getFolksonomyUri(
uriHelper.getUri(
path: 'product/$barcode/$key*', // look at the star!
queryParameters: parameters,
queryType: queryType,
),
queryType: queryType,
uriHelper: uriHelper,
);
_checkResponse(response);
final Map<String, ProductTag> result = <String, ProductTag>{};
Expand Down Expand Up @@ -250,7 +244,7 @@ Future<void> deleteProductTag({
static Future<List<ProductTag>> getProductTagVersions({
required final String barcode,
required final String key,
final QueryType? queryType,
final UriHelper uriHelper = uriHelperFolksonomyProd,
}) async {
final Map<String, String> parameters = <String, String>{};
/* TODO
Expand All @@ -259,12 +253,11 @@ Future<void> deleteProductTag({
}
*/
final Response response = await HttpHelper().doGetRequest(
UriHelper.getFolksonomyUri(
uriHelper.getUri(
path: 'product/$barcode/$key/versions',
queryParameters: parameters,
queryType: queryType,
),
queryType: queryType,
uriHelper: uriHelper,
);
_checkResponse(response);
final List<ProductTag> result = <ProductTag>[];
Expand Down Expand Up @@ -335,7 +328,7 @@ Future<void> deleteProductTag({

/// Returns the list of tag keys with statistics.
static Future<Map<String, KeyStats>> getKeys({
final QueryType? queryType,
final UriHelper uriHelper = uriHelperFolksonomyProd,
}) async {
final Map<String, String> parameters = <String, String>{};
/* TODO "The keys list can be restricted to private tags from some owner"
Expand All @@ -344,12 +337,11 @@ Future<void> deleteProductTag({
}
*/
final Response response = await HttpHelper().doGetRequest(
UriHelper.getFolksonomyUri(
uriHelper.getUri(
path: 'keys',
queryParameters: parameters,
queryType: queryType,
),
queryType: queryType,
uriHelper: uriHelper,
);
_checkResponse(response);
final Map<String, KeyStats> result = <String, KeyStats>{};
Expand All @@ -363,14 +355,13 @@ Future<void> deleteProductTag({
}

static Future<void> ping({
final QueryType? queryType,
final UriHelper uriHelper = uriHelperFolksonomyProd,
}) async {
final Response response = await HttpHelper().doGetRequest(
UriHelper.getFolksonomyUri(
uriHelper.getUri(
path: 'ping',
queryType: queryType,
),
queryType: queryType,
uriHelper: uriHelper,
);
_checkResponse(response);
}
Expand Down

0 comments on commit 7753cb0

Please sign in to comment.