Class OpenFoodFactsWebClient
java.lang.Object
com.alpermulayim.openfoodfacts_spring_boot_starter.OpenFoodFactsWebClient
- All Implemented Interfaces:
OpenFoodFactsApi
@Service("openFoodFactsWebClient")
public class OpenFoodFactsWebClient
extends Object
implements OpenFoodFactsApi
OpenFoodFactsWebClient designed to simplify the integration of OpenFoodFacts REST APIs into Spring Boot applications.
Developers can easily connect to the OpenFoodFacts API without implement any complex RESTFul calls.
- Author:
- Alper Mulayim https://github.com/AlperMulayim
-
Constructor Summary
ConstructorsConstructorDescriptionOpenFoodFactsWebClient
(OpenFoodFactsWebClientProperties clientProperties) Constructor for OpenFoodFactsWebClient.OpenFoodFactsWebClientProperties
. -
Method Summary
Modifier and TypeMethodDescriptionfindPrice
(PriceRequest priceRequest) Searches for product prices based on aPriceRequest
.Finds price details for a product.getProduct
(ProductRequest request) Retrieves product details using aProductRequest
.getProduct
(String productCode) Retrieves product details.getProduct
(String productCode, List<ProductField> fields) Retrieve Product with setted fields.saveProduct
(ProductSaveRequest request) Saves new product or updates product information.searchProduct
(ProductSearchRequest request) Searches for products based on aProductSearchRequest
.reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<String>>
Uploads a product image asynchronously.Uploads a product image synchronously.reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<String>>
Uploads a product image asynchronously.
-
Constructor Details
-
OpenFoodFactsWebClient
Constructor for OpenFoodFactsWebClient.OpenFoodFactsWebClientProperties
.- Parameters:
clientProperties
- Configuration properties for the API.
-
-
Method Details
-
getProduct
Retrieve Product with setted fields.- Specified by:
getProduct
in interfaceOpenFoodFactsApi
- Parameters:
productCode
- product codefields
- the retrieved fields list on response object.ProductField
.- Returns:
- The product details wrapped in an
OpenFoodFactsResponse
. - Throws:
OpenFoodFactsException
- if the product code is null or empty.
-
getProduct
Retrieves product details.- Specified by:
getProduct
in interfaceOpenFoodFactsApi
- Parameters:
productCode
- product code- Returns:
- The product details wrapped in an
OpenFoodFactsResponse
.
-
getProduct
Retrieves product details using aProductRequest
.- Specified by:
getProduct
in interfaceOpenFoodFactsApi
- Parameters:
request
- The request object containing productCode and fields.- Returns:
- The product details wrapped in an
OpenFoodFactsResponse
. - Throws:
OpenFoodFactsException
- if request or required fields are null.
-
searchProduct
public OpenFoodFactsPageResponse searchProduct(ProductSearchRequest request) throws InvocationTargetException, IllegalAccessException, OpenFoodFactsException Searches for products based on aProductSearchRequest
.- Specified by:
searchProduct
in interfaceOpenFoodFactsApi
- Parameters:
request
- The search request containing query parameters.- Returns:
- The paginated response wrapped in an
OpenFoodFactsPageResponse
. - Throws:
OpenFoodFactsException
- if request is null.InvocationTargetException
IllegalAccessException
-
findPrice
Finds price details for a product.- Specified by:
findPrice
in interfaceOpenFoodFactsApi
- Parameters:
productCode
- product code- Returns:
- The price details wrapped in an
OpenPriceFactsResponse
. - Throws:
OpenFoodFactsException
- if the product code is null or empty.
-
findPrice
Searches for product prices based on aPriceRequest
.- Specified by:
findPrice
in interfaceOpenFoodFactsApi
- Parameters:
priceRequest
- product code- Returns:
- The price details wrapped in an
OpenPriceFactsResponse
. - Throws:
OpenFoodFactsException
- if the product code is null or empty.
-
uploadProductImage
public reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<String>> uploadProductImage(ProductImageUploadRequest request) Uploads a product image asynchronously.- Specified by:
uploadProductImage
in interfaceOpenFoodFactsApi
- Parameters:
request
- The image uploadProductImageUploadRequest
. request containing image data.- Returns:
- A
Mono
with the server response.
-
uploadProductImageUnblocked
public reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<String>> uploadProductImageUnblocked(ProductImageUploadRequest request) throws OpenFoodFactsException Uploads a product image asynchronously.- Specified by:
uploadProductImageUnblocked
in interfaceOpenFoodFactsApi
- Parameters:
request
- The image uploadProductImageUploadRequest
. request containing image data.- Returns:
- A
Mono
with the server response. - Throws:
OpenFoodFactsException
-
uploadProductImageBlocked
public String uploadProductImageBlocked(ProductImageUploadRequest request) throws OpenFoodFactsException Uploads a product image synchronously.- Specified by:
uploadProductImageBlocked
in interfaceOpenFoodFactsApi
- Parameters:
request
- The image upload request containing image data.ProductImageUploadRequest
.- Returns:
- server response.
- Throws:
OpenFoodFactsException
-
saveProduct
Saves new product or updates product information.- Specified by:
saveProduct
in interfaceOpenFoodFactsApi
- Parameters:
request
- The product save new product or update product request.ProductSaveRequest
.- Returns:
- The saved product response wrapped in a
ProductSaveResponse
. - Throws:
OpenFoodFactsException
- if request is null or missing required fields.
-