Skip to content

Commit

Permalink
feat: openfoodfacts#370 - new source configuration for saveProduct
Browse files Browse the repository at this point in the history
New file:
* `SourceConfiguration.dart`: Source Configuration for detection of apps (populates data sources on BE).

Impacted file:
* `openfoodfacts.dart`: added source configuration parameter to `saveProduct`
  • Loading branch information
monsieurtanuki committed Jan 23, 2022
1 parent 057e0a3 commit d52b6d2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/openfoodfacts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import 'package:openfoodfacts/utils/PnnsGroups.dart';
import 'package:openfoodfacts/utils/ProductFields.dart';
import 'package:openfoodfacts/utils/ProductListQueryConfiguration.dart';
import 'package:openfoodfacts/utils/QueryType.dart';
import 'package:openfoodfacts/utils/SourceConfiguration.dart';
import 'package:openfoodfacts/utils/TagType.dart';
import 'package:openfoodfacts/utils/TaxonomyQueryConfiguration.dart';
import 'package:openfoodfacts/utils/UriHelper.dart';
Expand Down Expand Up @@ -81,6 +82,7 @@ export 'utils/ProductFields.dart';
export 'utils/ProductHelper.dart';
export 'utils/ProductQueryConfigurations.dart';
export 'utils/ProductSearchQueryConfiguration.dart';
export 'utils/SourceConfiguration.dart';

/// Client calls of the Open Food Facts API
class OpenFoodAPIClient {
Expand All @@ -92,15 +94,19 @@ class OpenFoodAPIClient {
/// Please read the language mechanics explanation if you intend to display
/// or update data in specific language: https://github.com/openfoodfacts/openfoodfacts-dart/blob/master/DOCUMENTATION.md#about-languages-mechanics
static Future<Status> saveProduct(
User user,
Product product, {
QueryType? queryType,
final User user,
final Product product, {
final QueryType? queryType,
final SourceConfiguration? sourceConfiguration,
}) async {
var parameterMap = <String, String>{};
final Map<String, String> parameterMap = <String, String>{};
parameterMap.addAll(user.toData());
parameterMap.addAll(product.toServerData());
if (sourceConfiguration != null) {
parameterMap.addAll(sourceConfiguration.getParameters());
}

var productUri = UriHelper.getUri(
final Uri productUri = UriHelper.getUri(
path: '/cgi/product_jqm2.pl',
queryType: queryType,
);
Expand Down
26 changes: 26 additions & 0 deletions lib/utils/SourceConfiguration.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// Source Configuration for detection of apps (populates data sources on BE).
class SourceConfiguration {
const SourceConfiguration({
this.appName,
this.appVersion,
this.appUuid,
});

final String? appName;
final String? appVersion;
final String? appUuid;

Map<String, String> getParameters() {
final Map<String, String> result = <String, String>{};
if (appName != null) {
result['app_name'] = appName!;
}
if (appVersion != null) {
result['app_version'] = appVersion!;
}
if (appUuid != null) {
result['app_uuid'] = appUuid!;
}
return result;
}
}

0 comments on commit d52b6d2

Please sign in to comment.