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

Pass an object as an argument to customer.list and coupons.list #37

Merged
merged 5 commits into from
Apr 3, 2013

Conversation

kc-dot-io
Copy link
Contributor

This is somewhat of situational PR but I think it's worth considering for the sake of consistent alignment of arguments.

I have some code that is looping through the charge, customer and invoice endpoints, making calls to list methods programmatically. It seems that the expected arguments for charge and invoice both accept an object however customer expects two separate arguments for count and offset. This PR just adds support for the short hand .list({ count: x, offset: x}, fn) arg style which makes for a slightly more consistent interface across these methods.

Side note, I ran the tests before writing this PR and they seem to fail for me, so I wasn't able to confirm this PR against the tests. This could be due to the fact I was testing with a stripe connect oauth key but I'll do some work on the tests and see what I can figure out.

I've also got some reasons to implement more support for connect so I'll see what help I can offer there in future PR's.

Feedback appreciated.

@abh
Copy link
Contributor

abh commented Mar 12, 2013

Yeah, I think the API should have been setup so only "primary key"-type paramaters are "bare" and everything else should have been an object (for "options").

If we're cleaning it up we should do it for all the functions though (with backwards compatibility, documentation and tests).

Maybe some utility function to help sort it out; a bunch of if () statements like you have in this patch will end up being a bit ugly and unmaintainable, I think.

@kc-dot-io
Copy link
Contributor Author

That's good feedback. I'll try to implement it. Can you give examples of what you consider "primary key" type parameters? My presumption would be things like id are required and therefor are arguments where as offset and count are optional and would be passed via a object.

@kc-dot-io
Copy link
Contributor Author

@abh - I added a function to normalize arguments for each of the list methods that it made sense to. It should be backwards compatible. I left charges.list, invoices.list and events.list alone because they are already passing the entire object so there is no backwards compatibility concerns. I also updated the documentation and ensured the tests pass:

slajax@slajax-desktop:~/repos/node-stripe $ STRIPE_API=XXX vows test/*
···· ····· · ········ ······ ··
  ✓ OK » 26 honored (16.687s)

Hopefully this is a little more along the lines of what you were looking for. Let me know what you think.

Also, to your knowledge is anyone working on the invoice/pay method? If not I'll take a stab at it later this week.

@abh
Copy link
Contributor

abh commented Apr 3, 2013

I like it; thank you!

Don't think there's anything for invoice/pay in the queue, so go crazy. :-)

abh added a commit that referenced this pull request Apr 3, 2013
Pass an object as an argument to customer.list and coupons.list
@abh abh merged commit 332a8df into stripe:master Apr 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants