appstoreconnect-swift-sdk
appstoreconnect-swift-sdk copied to clipboard
Add documentation about pagination
It might not be clear from the get-go how to use pagination support. Adding this to the readme would help implementors!
Please please please Antoine. I had paging sorted with the pre 2.0.0 releases but I'm completely stuck without any clue with this new API. I can see the old version specified cursor and limit parameters in the endpoint requests but can't see anywhere in the 2.x API for these to be passed to the server.
I have constructed this code snippet that builds on from the example on the main README.md but processes a response's PagedDocumentLinks to obtain more results using a method similar to the pre-2.0.0 releases.
Whilst this method works, is this the limit of what's achievable or can it be done in a tidier, more elegant way?
func getApps(nextPage: String? = nil) async throws -> [AppStoreConnect_Swift_SDK.App] {
var request = APIEndpoint
.v1
.apps
.get(parameters: .init(
sort: [.bundleID],
fieldsApps: [.appInfos, .name, .bundleID],
limit: 5
))
// Append to the query the cursor pointing to the next page of results required, if populated
if let nextPageCursor = nextPage {
request.query!.append(("cursor", nextPageCursor))
}
let requestResult = try await provider.request(request)
let apps = requestResult.data
if let linkNextURL = requestResult.links.next.flatMap({ URL(string: $0) }),
let queryComponents = URLComponents(url: linkNextURL, resolvingAgainstBaseURL: false)?.queryItems,
let nextPageCursor = queryComponents.first(where: { $0.name == "cursor" })?.value {
return try await apps + getApps(nextPage: nextPageCursor)
} else {
return apps
}
}
let allApps = try await getApps()
This is pretty much how it should work, but it would obviously be much nicer if the SDK supports this out of the box. Feel free to open a PR for that if you're able to make a generic solution. It would be inside APIProvider
I think!
OK. I have.
I think we need to create new release that support this pagination 🙏
@jeffersonsetiawan yes, good point! Just triggered a new release 🙏
The pull request #195 that closed this issue was merged and released as part of Release 2.3.0 :rocket: Please let us know if the functionality works as expected as a reply here. If it does not, please open a new issue. Thanks!
Generated by GitBuddy