ramsayleung / rspotify

Spotify Web API SDK implemented on Rust
MIT License
639 stars 122 forks source link

Automatically do paginated post requests #296

Open nick-lehmann opened 2 years ago

nick-lehmann commented 2 years ago

Is your feature request related to a problem? Please describe.

After gathering some information from the Spotify API, I tried to add around 300 tracks to a single playlist. I knew that Spotify restricts the number of items that can be passed to an endpoint. For the Add Items to Playlist endpoint, Spotify imposes a limit of a 100 tracks in a single request. The API does not reflect this restriction in any way.

Describe the solution you'd like

While it would be possible to add some type information to functions like playlist_add_items, I would rather prefer that all method do chunking automatically. If the given number of items surpasses the limit of the API, a second request will be sent.

Describe alternatives you've considered

It is quite easy to implement the chunking on my own. However, it is dull and the returned responses with a status code of 400 might surprise some users.

Additional context

I am quite new to Rust and, given you agree to this proposal, I would love to create a PR for this.

ramsayleung commented 2 years ago

Hi Nick, this idea sounds great!

Rspotify just supports automatically fetch the paginated requests, but it doesn't support automatically feed the paginated requests. It will be great if you could help us add this feature.

marioortizmanero commented 2 years ago

I think in this case there's no nerd to have a _manual and an iterator version right? Mainly because it doesn't really work with pages. It could just work transparently for user friendliness, as long as it's clearly commented.

nick-lehmann commented 2 years ago

@ramsayleung thank you very much, I will try to get a PR going this week 👍🏻

@marioortizmanero I guess there is a always a nerd 😝 But no, I don't think we would need both. I don't see why anyone would need the manual version...

github-actions[bot] commented 1 year ago

Message to comment on stale issues. If none provided, will not mark issues stale