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

feat: #349 - added support for Events API #386

Merged
merged 1 commit into from
Feb 15, 2022

Conversation

monsieurtanuki
Copy link
Contributor

@monsieurtanuki monsieurtanuki commented Feb 15, 2022

Still missing: couldn't test how to create an event. Are we talking about the same users as in the "official OpenFoodFacts" API? (aka "off off"). Good news is that the TEST env works - which is not the case for Folksonomy.

New files:

  • api_events_test.dart: Tests around Events API.
  • BadgeBase.dart: Events API: badge.
  • BadgeBase.g.dart: generated
  • EventCreate.dart: Events API: event create.
  • EventCreate.g.dart: generated
  • events.dart: Client calls of the Events API (Open Food Facts).
  • EventsBase.dart: Events API: event.
  • EventsBase.g.dart: generated
  • LeaderboardEntry.dart: Events API: leaderboard entry.
  • LeaderboardEntry.g.dart: generated

Impacted files:

  • JsonHelper.dart: added a nullable timestamp conversion method.
  • OpenFoodAPIConfiguration.dart: added host entries for Events API.
  • openfoodfacts.dart: exported new Events related files.
  • UriHelper.dart: added Events related method getEventsUri.

New files:
* `api_events_test.dart`: Tests around Events API.
* `BadgeBase.dart`: Events API: badge.
* `BadgeBase.g.dart`: generated
* `EventCreate.dart`: Events API: event create.
* `EventCreate.g.dart`: generated
* `events.dart`: Client calls of the Events API (Open Food Facts).
* `EventsBase.dart`: Events API: event.
* `EventsBase.g.dart`: generated
* `LeaderboardEntry.dart`: Events API: leaderboard entry.
* `LeaderboardEntry.g.dart`: generated

Impacted files:
* `JsonHelper.dart`: added a nullable timestamp conversion method.
* `OpenFoodAPIConfiguration.dart`: added host entries for Events API.
* `openfoodfacts.dart`: exported new Events related files.
* `UriHelper.dart`: added Events related method `getEventsUri`.
@teolemon
Copy link
Member

Oh great :-) gamification in Smoothie 🎉

@teolemon teolemon requested a review from a team February 15, 2022 12:25
@teolemon teolemon requested a review from a team February 15, 2022 12:26
Copy link
Member

@M123-dev M123-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks @monsieurtanuki good start that it is in it's own class

@monsieurtanuki monsieurtanuki merged commit ea79ad0 into openfoodfacts:master Feb 15, 2022
@monsieurtanuki
Copy link
Contributor Author

Thank you @teolemon @M123-dev for your review!

As mentioned earlier, there's one method that I could not test, the only one that writes: "create events", because I get the following error: Incorrect username or password.
@ocervell in my tests I saw that you were the only user with Events data in TEST and PROD environments: where do the Events users come from? Are they supposed to be "standard" open food facts users or are they specific to Events - if so how are they created?

@monsieurtanuki
Copy link
Contributor Author

@ocervell ping

@ocervell
Copy link

ocervell commented Mar 21, 2022

@monsieurtanuki events are currently created by the admin user, set on the API side by the env variables ADMIN_USERNAME and ADMIN_PASSWORD. Initially we were not supposed to expose that to the client-side, so the OFF API should contact it, not the client app.

The request flow should be:

  • User in app responds to questions / adds a product / etc...
  • API call made to off-server backend
  • off-server backend authentifies to Events API using admin credentials and adds the event

The problem with client app authenticating directly to the Events API is that anyone could add as many events as they want by simply using the API, thus falsifying the data (imagine if I just trace the API calls to events API I could add myself 20 "product_add" events and thus increase my score artifically).

@teolemon
Copy link
Member

Oh, I really goofed on that one. I'm so sorry.

@ocervell
Copy link

Note that only the CreateEvent method is obsolete, the rest is still valid (querying badges for a user, querying leaderboard, querying events ...) so the PR is still mostly valid.

@monsieurtanuki
Copy link
Contributor Author

Thank you @ocervell for your answers.

If I understand correctly, that means that we need the off backend to directly call CreateEvent each time an "event" is detected, like "product_add". And there's nothing we have to do on the app side, except read/count the events, right?

@ocervell
Copy link

Yes, that's correct, robotoff and the OFF backend will have code to contact the Events API CreateEvent endpoint internally. There might be an exception for the 'invite_shared' event as this is an in-app event but we could add an API call in off backend for that one (or just remove that event).

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

Successfully merging this pull request may close these issues.

Add support for the openfoodfacts-events API (leaderboard, badge and gamification system)
4 participants