clojurewerkz / elephant

Modern Clojure client for the Stripe API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ability to retrieve total count of a resource

amoe opened this issue · comments

I wanted to retrieve the total count of customers. According to the documentation for the upstream Stripe API,

You can optionally request that the response include the total count of all
customers that match your filters. To do so, specify include[]=total_count in
your request.

However, I couldn't figure out if this is possible using Elephant and the clojurewerkz.elephant.customers/list function. I tried using (ecr/list {"include[]" "total_count"}) but, as the result is always a plain sequence of customer maps, the count was not accessible.

Elephant returns the JSON objects as they are returned (it does inject a couple of fields for its own use but they are clearly prefixed). I cannot say how to do it without running an experiment.

Although Elephant does return the untouched JSON for each individual customer, there are additional fields in the JSON at the top-level -- that is, calling .getData() on the CustomerCollection descends one level. .getTotalCount would also be possible directly on the CustomerCollection, but Elephant hides that. Seems quite technically simple to add, but quite disruptive to the interface in general. :/

https://github.com/clojurewerkz/elephant/blob/master/src/clojure/clojurewerkz/elephant/conversion.clj#L300

It's a pre-1.0 library. @amoe feel free to submit a PR. It's also possible to have data structures in Clojure that look and work like maps but are actually Java classes. I hope we can avoid it here but if we want to make something look like a map for all intents and purposes, we can do that.