Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document the image refresh API #15

Closed
2 tasks
Tracked by #23
teolemon opened this issue Feb 14, 2021 · 1 comment
Closed
2 tasks
Tracked by #23

Document the image refresh API #15

teolemon opened this issue Feb 14, 2021 · 1 comment

Comments

@teolemon
Copy link
Member

image
Ensure we can request photo updates for select products to users for images which should be taken or re-taken (because they are too old, or possibly too small / blurry).

https://fr.openfoodfacts.org/api/v0/produit/3483130043180/beurre-cru-a-la-baratte-les-petites-laiteries?fields=images_to_update_fr

It returns a hash of image types + language code (only for the requested language code which should be the language of the app). The value is 0 for images we don't have, or the age of the image (in seconds) for apps that want to add some context like "Our photo of the ingredients is 14 months old, could you take a new one?".

Sample API response

product: {
images_to_update_fr: {
packaging_fr: 0,
front_fr: 83734290,
ingredients_fr: 83734290
}
},

Pseudo code to generate button text

for field in images_to_update_fr:
if field.value=0
verb = "take"
else:
verb = "refresh"
field_name = field.split.before("")
field_language = field.split.after("
")
button_text = fetch_button_text(field_name, field_language, verb)

Strings to combine (suffix the language at the end)

"Take %s picture"
"Refresh %s picture"
"ingredients"
"front"
"nutrition"
"packaging"

Optional - mention how old the image is

How to convert seconds in human readable format: 83734290 = 2 years and 7 months (example routine to convert) - https://stackoverflow.com/questions/29681328/convert-seconds-into-years-months-weeks-hours-minutes-and-seconds

Send the right query based on the initial field in images_to_update_fr

  • Do not use the computed values in the pseudo code
  • Probably refactor the methods we currently have to pass the field name, and make it future proof if we want to add new image fields.

Extra info

app/src/main/java/openfoodfacts/github/scrachx/openfood/images/ProductImage.java

@teolemon
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant