Skip to content

Commit

Permalink
Merge branch 'master' into fix/900
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurtanuki authored Jun 6, 2024
2 parents ff4dd67 + 1256fe6 commit e6e8ed8
Show file tree
Hide file tree
Showing 51 changed files with 770 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dartdoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
run: dart doc .

- name: Deploy API documentation to Github Pages
uses: JamesIves/[email protected].0
uses: JamesIves/[email protected].1
with:
BRANCH: gh-pages
FOLDER: doc/api/
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## [3.10.0](https://github.com/openfoodfacts/openfoodfacts-dart/compare/v3.9.0...v3.10.0) (2024-05-22)


### Features

* 933 - added osm location fields (countryCode, osmKey, osmValue) ([#934](https://github.com/openfoodfacts/openfoodfacts-dart/issues/934)) ([f653f6a](https://github.com/openfoodfacts/openfoodfacts-dart/commit/f653f6ab049e6ec30c0726cfae576ede57e5ce46))

## [3.9.0](https://github.com/openfoodfacts/openfoodfacts-dart/compare/v3.8.0...v3.9.0) (2024-05-17)


### Features

* 831 - prices methods getProofs, getProof and getUsers + fixed uploadProof ([#926](https://github.com/openfoodfacts/openfoodfacts-dart/issues/926)) ([baa1258](https://github.com/openfoodfacts/openfoodfacts-dart/commit/baa1258c71e38dfa194b568c5a20c70ee0dc6c6a))
* add localized additives and allergens ([#929](https://github.com/openfoodfacts/openfoodfacts-dart/issues/929)) ([9d17073](https://github.com/openfoodfacts/openfoodfacts-dart/commit/9d1707309ab035e3360740e5ef0772915c95120e))

## [3.8.0](https://github.com/openfoodfacts/openfoodfacts-dart/compare/v3.7.0...v3.8.0) (2024-05-10)


Expand Down
9 changes: 9 additions & 0 deletions lib/openfoodfacts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,29 @@ export 'src/personalized_search/preference_importance.dart';
export 'src/personalized_search/product_preferences_manager.dart';
export 'src/personalized_search/product_preferences_selection.dart';
export 'src/prices/currency.dart';
export 'src/prices/flavor.dart';
export 'src/prices/get_locations_order.dart';
export 'src/prices/get_locations_parameters.dart';
export 'src/prices/get_locations_result.dart';
// export 'src/prices/get_parameters_helper.dart'; // uncomment if really needed
export 'src/prices/get_prices_order.dart';
export 'src/prices/get_prices_parameters.dart';
export 'src/prices/get_prices_result.dart';
export 'src/prices/get_price_count_parameters_helper.dart';
export 'src/prices/get_proofs_order.dart';
export 'src/prices/get_proofs_parameters.dart';
export 'src/prices/get_proofs_result.dart';
export 'src/prices/get_users_order.dart';
export 'src/prices/get_users_parameters.dart';
export 'src/prices/get_users_result.dart';
export 'src/prices/location.dart';
export 'src/prices/location_osm_type.dart';
export 'src/prices/maybe_error.dart';
export 'src/prices/order_by.dart';
export 'src/prices/price.dart';
export 'src/prices/price_per.dart';
export 'src/prices/price_product.dart';
export 'src/prices/price_user.dart';
export 'src/prices/proof.dart';
export 'src/prices/proof_type.dart';
export 'src/prices/session.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/badge_base.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/src/model/events_base.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/src/model/key_stats.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/src/model/knowledge_panel_element.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/src/model/leaderboard_entry.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/src/model/ocr_ingredients_result.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/src/model/ocr_packaging_result.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/src/model/old_product_result.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/src/model/product.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/src/model/product_stats.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/src/model/product_tag.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/src/model/spelling_corrections.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 87 additions & 2 deletions lib/src/open_prices_api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import 'prices/get_locations_result.dart';
import 'prices/get_parameters_helper.dart';
import 'prices/get_prices_parameters.dart';
import 'prices/get_prices_result.dart';
import 'prices/get_proofs_parameters.dart';
import 'prices/get_proofs_result.dart';
import 'prices/get_users_parameters.dart';
import 'prices/get_users_result.dart';
import 'prices/location.dart';
import 'prices/location_osm_type.dart';
import 'prices/price_product.dart';
Expand Down Expand Up @@ -383,9 +387,37 @@ class OpenPricesAPIClient {
return MaybeError<bool>.responseError(response);
}

/// Get user proofs.
static Future<MaybeError<GetProofsResult>> getProofs(
final GetProofsParameters parameters, {
final UriProductHelper uriHelper = uriHelperFoodProd,
required final String bearerToken,
}) async {
final Uri uri = uriHelper.getUri(
path: '/api/v1/proofs',
queryParameters: parameters.getQueryParameters(),
forcedHost: _getHost(uriHelper),
);
final Response response = await HttpHelper().doGetRequest(
uri,
uriHelper: uriHelper,
bearerToken: bearerToken,
);
if (response.statusCode == 200) {
try {
final dynamic decodedResponse = HttpHelper().jsonDecodeUtf8(response);
return MaybeError<GetProofsResult>.value(
GetProofsResult.fromJson(decodedResponse),
);
} catch (e) {
//
}
}
return MaybeError<GetProofsResult>.responseError(response);
}

static Future<MaybeError<Proof>> uploadProof({
required final ProofType proofType,
required final bool isPublic,
required final Uri imageUri,
required final MediaType mediaType,
required final String bearerToken,
Expand All @@ -404,7 +436,6 @@ class OpenPricesAPIClient {
request.fields.addAll(
<String, String>{
'type': proofType.offTag,
'is_public': isPublic ? 'true' : 'false',
},
);
final List<int> fileBytes = await UriReader.instance!.readAsBytes(imageUri);
Expand Down Expand Up @@ -436,6 +467,32 @@ class OpenPricesAPIClient {
);
}

/// Get user proof by id.
static Future<MaybeError<Proof>> getProof(
final int proofId, {
final UriProductHelper uriHelper = uriHelperFoodProd,
required final String bearerToken,
}) async {
final Uri uri = uriHelper.getUri(
path: '/api/v1/proofs/$proofId',
forcedHost: _getHost(uriHelper),
);
final Response response = await HttpHelper().doGetRequest(
uri,
uriHelper: uriHelper,
bearerToken: bearerToken,
);
if (response.statusCode == 200) {
try {
final dynamic decodedResponse = HttpHelper().jsonDecodeUtf8(response);
return MaybeError<Proof>.value(Proof.fromJson(decodedResponse));
} catch (e) {
//
}
}
return MaybeError<Proof>.responseError(response);
}

/// Deletes a proof.
/// A user can delete only owned proofs. Can delete only proofs that are not associated with prices. A moderator can delete not owned proofs.
/// Returns true if successful.
Expand All @@ -458,4 +515,32 @@ class OpenPricesAPIClient {
}
return MaybeError<bool>.responseError(response);
}

static Future<MaybeError<GetUsersResult>> getUsers(
final GetUsersParameters parameters, {
final UriProductHelper uriHelper = uriHelperFoodProd,
final String? bearerToken,
}) async {
final Uri uri = uriHelper.getUri(
path: '/api/v1/users',
queryParameters: parameters.getQueryParameters(),
forcedHost: _getHost(uriHelper),
);
final Response response = await HttpHelper().doGetRequest(
uri,
uriHelper: uriHelper,
bearerToken: bearerToken,
);
if (response.statusCode == 200) {
try {
final dynamic decodedResponse = HttpHelper().jsonDecodeUtf8(response);
return MaybeError<GetUsersResult>.value(
GetUsersResult.fromJson(decodedResponse),
);
} catch (e) {
//
}
}
return MaybeError<GetUsersResult>.responseError(response);
}
}
36 changes: 36 additions & 0 deletions lib/src/prices/flavor.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:json_annotation/json_annotation.dart';
import '../model/off_tagged.dart';
import '../utils/server_type.dart';

/// Flavor is used to refer to a specific Open*Facts project.
///
/// cf. `Flavor` in https://prices.openfoodfacts.org/api/docs
/// Somehow redundant with [ServerType].
enum Flavor implements OffTagged {
/// Open Food Facts
@JsonValue('off')
openFoodFacts(offTag: 'off'),

/// Open Beauty Facts
@JsonValue('obf')
openBeautyFacts(offTag: 'obf'),

/// Open Pet Food Facts
@JsonValue('opff')
openPetFoodFacts(offTag: 'opff'),

/// Open Product Facts
@JsonValue('opf')
openProductFacts(offTag: 'opf'),

/// Open Product Facts (Pro platform)
@JsonValue('off-pro')
openFoodProductFactsPro(offTag: 'off-pro');

const Flavor({
required this.offTag,
});

@override
final String offTag;
}
22 changes: 3 additions & 19 deletions lib/src/prices/get_locations_parameters.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import 'get_locations_order.dart';
import 'order_by.dart';
import 'get_parameters_helper.dart';
import 'get_price_count_parameters_helper.dart';

/// Parameters for the "get locations" API query.
///
/// cf. https://prices.openfoodfacts.org/api/docs
class GetLocationsParameters extends GetParametersHelper {
class GetLocationsParameters
extends GetPriceCountParametersHelper<GetLocationsOrderField> {
String? osmNameLike;
String? osmCityLike;
String? osmPostcodeLike;
String? osmCountryLike;
int? priceCount;
int? priceCountGte;
int? priceCountLte;
List<OrderBy<GetLocationsOrderField>>? orderBy;

@override
Map<String, String> getQueryParameters() {
Expand All @@ -22,18 +18,6 @@ class GetLocationsParameters extends GetParametersHelper {
addNonNullString(osmCityLike, 'osm_address_city__like');
addNonNullString(osmPostcodeLike, 'osm_address_postcode__like');
addNonNullString(osmCountryLike, 'osm_address_country__like');
addNonNullInt(priceCount, 'price_count');
addNonNullInt(priceCountGte, 'price_count__gte');
addNonNullInt(priceCountLte, 'price_count__lte');
if (orderBy != null) {
final List<String> orders = <String>[];
for (final OrderBy order in orderBy!) {
orders.add(order.offTag);
}
if (orders.isNotEmpty) {
addNonNullString(orders.join(','), 'order_by');
}
}
return result;
}
}
Loading

0 comments on commit e6e8ed8

Please sign in to comment.