controlshift / action-network-rest

Ruby client for interacting with the ActionNetwork REST API
MIT License
8 stars 4 forks source link

Allow additional filter statements in list #15

Open dweebo opened 4 years ago

dweebo commented 4 years ago

I would like to be able to filter people by created_date in order to find new activists.

I started a branch to add an optional filter parameter to list but realized it gets complicated quickly. Multiple filter options with and and or are supported. For example

filter=(email_address eq 'a@example.com' or email_address eq 'b@example.com') and created_date lt '2018-01-01'

Before I get too far wanted to get your thoughts on how you'd like to support this (if at all). I see that the special method People#find_by_email uses filtering, so some possible options are

I'm happy to contribute this feature, just wanted to get feedback before working on it.

woodhull commented 4 years ago

I'm not familiar with the details in ActionNetwork around this, do you have a pointer for the relevant docs? I found this https://actionnetwork.org/docs/v2/people but I don't see the filter bit.

Filter could just be an arbitrary string (moving all of the filter building complexity to the consumer) or we could try and build out a nice query building interface in ruby -- that seems tricky to do well though.

woodhull commented 4 years ago

Working backwards: what would the ideal ruby ergonomics be like in a perfect world? Something like arel feels hard to pull off, but maybe I'm wrong about that.

dweebo commented 4 years ago

https://actionnetwork.org/docs/v2#odata has some details, that is where I first saw how to do filtering. Then I searched around for OData multiple filters and found some examples of using and/or syntax like I showed in my example.

Good point about just allowing arbitrary string filtering, I did consider that briefly as well but forgot to include it in my list of options. I don't love it... but that would certainly be easiest!

I've just started using ActionNetwork within the past week, and never used OData before, so certainly not well-versed yet! I haven't used arel much either but looking briefly at docs don't quite see how that would work.

I like your idea of thinking thru how it would work with idiomatic ruby, as long as this doesn't become too complex. I'm more of a ruby hacker so not sure the best way forward off the top of my head. I know just enough to get by and not cause too much trouble when I am working with ruby 😄 .

joe-irving commented 2 years ago

Not sure if you have seen but it looks like there is already an oData ruby library here. I guess the simplest thing would be to use that to generate query strings?

Potentially worth adding a raw_filter parameter to #list to allow people to do simple filtering for now with just a oData filter string