todoist-ruby
todoist-ruby copied to clipboard
Get Activity not fully functional
:wave: The activity API requires an 'object_type' parameter ('item,
noteor
project) in order to query by
object_id`. I was able to get everything work by making the call with the helper like the Activity class does and passing in the object type parameter.
I'd be happy to submit a PR with a fix, but I wasn't sure if there was a good way to detect what type of object was passed or if the field should just be a text field that you have to know to put the correct name in.
Additionally, there are a few other ways you can filter activities like event_type
that are not in the api.
params = { 'object_id' => task.id, 'object_type' => 'item', 'event_type' => 'completed' }
activity = @client.api_helper.get_response(Todoist::Config::TODOIST_ACTIVITY_GET_COMMAND, params)
@crimsonknave Thank you for pointing this out! Admittedly, I do not use the activity API much so it is not unsurprising that the implementation is too shallow/incomplete. Your contribution would be of great help.
Occasionally, I have surfaced OpenStructs, especially when returning values since that feels a bit more user-friendly and avoided typing the parameters when I can on input in large part because Todoist does have a tendency to make some rather breaking changes in its sync API.
Admittedly, it seems inelegant if we can't detect the type of object, and rely on magic strings. We could mitigate this by having constants defined, but the sheer number of magic constants is rather mind boggling so getting the codebase consistent would be a non-trivial exercise (plus the maintenance of it). What I ultimately chose to do instead is to throw caution and good coding practices to the wind and allow some flexibility in input parameters which has helped the library age rather gracefully. When new magic parameters come in, it does not force a large library rewrite but it more or less forces API users to not only understand how the library works, but unfortunately, also read the original document on Todoist.
Not sure if this answers any of your questions, but I'd love to see your PR and maybe we can go from there!