-
Notifications
You must be signed in to change notification settings - Fork 570
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
Add support for auto-pagination #1414
Conversation
"n/a", | ||
RequestDate = response.Headers.Contains("Date") ? | ||
Convert.ToDateTime(response.Headers.GetValues("Date").First(), CultureInfo.InvariantCulture) : | ||
default(DateTime), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find a way to mock response headers, so I made the Date
header optional. I think that's better anyway.
@@ -4,7 +4,7 @@ namespace Stripe | |||
using System.Threading.Tasks; | |||
|
|||
public interface IListable<T, O> | |||
where T : IStripeEntity | |||
where T : IStripeEntity, IHasId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the resource to have an ID in order to be able to paginate. I also added IHasId
as a constraint on other interfaces where it makes sense to do so (i.e. everything except create).
using Stripe; | ||
using Xunit; | ||
|
||
public class AutoPagingTest : BaseStripeTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test seems pretty complex, but it's actually pretty straightforward:
- set up 3 stubbed requests with file fixtures
- call
ListAutoPaging
- check invocations to make sure the correct parameters were sent
22c7706
to
af74dd6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some high level feedback. This looks mostly okay to me though it's still beyond what I'm comfortable actively reviewing so also cc-in @anelder-stripe
Is there a way we don't have to add new prototypes for this? I assume not but was hoping you could do an autoPaginate = true
that defaults to false?
], | ||
"has_more": true, | ||
"object": "list", | ||
"url": "/v1/pageable_models" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OOC aren't we supposed to have ?starting_after=pm_124
in this URL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the API doesn't include starting_after
parameters in url
attributes.
Assert.Equal("pm_124", models[1].Id); | ||
Assert.Equal("pm_125", models[2].Id); | ||
Assert.Equal("pm_126", models[3].Id); | ||
Assert.Equal("pm_127", models[4].Id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So auto-paging basically builds the entire list in ram no matter what? You can't auto page while also getting items one by one and not filling your RAM with all your BTs history?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can. In these examples, I used ToList()
to directly convert the iterator into a list, but you can also iterate over the objects one by one:
foreach (var balanceTransaction in balanceTransactionService.ListAutoPaging(listOptions))
{
// Do something with balanceTransaction
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah neat! Can you put a test for this in our test suite? I know people refer to the test suite a lot to find example. I guess this is where your yield
applies. Fun how similar it is in each language you've shown me this approach!
No, because the types that are returned are different. When you use the existing |
af74dd6
to
f6c0384
Compare
42dd016
to
1ff3e3f
Compare
Okay, I think this is ready to be merged. ptal @remi-stripe @anelder-stripe |
65edf0a
to
7d6d6cc
Compare
dbe68b3
to
db53d82
Compare
ac8dca7
to
25ac4e9
Compare
c243a24
to
31bc80e
Compare
209077a
to
6bdca72
Compare
1bd903a
to
4603a3c
Compare
dcc89b7
to
19bb0cd
Compare
8ede288
to
74d2144
Compare
74d2144
to
19741d8
Compare
bc49f22
to
55c99ef
Compare
19741d8
to
df750eb
Compare
55c99ef
to
380ee0f
Compare
df750eb
to
935ce57
Compare
5ced76c
to
92db96e
Compare
935ce57
to
78eb929
Compare
1d872d7
to
a988be3
Compare
78eb929
to
c99c23d
Compare
Timing out and self-approving this one :) |
r? @remi-stripe
cc @stripe/api-libraries
Adds support for auto-pagination.
Example usages:
The second example uses the LINQ method
ToList()
to directly convert theIEnumerable<LineItem>
returned byInvoiceService.ListLineItemsAutoPaging()
into aList<LineItem>
.Fixes #1038.