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

Keep pagination fields #206

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,16 @@ RSpotify.raw_response = true
RSpotify::Artist.search('Cher') #=> (String with raw json response)
```

## Getting pagination info

To get the pagination info from Spotify API requests, just toggle the `pagination_info` variable:


```ruby
RSpotify.pagination_info = true
RSpotify::Artist.search('Cher') #=> (String with raw json response)
```

## Notes

If you'd like to use OAuth outside rails, have a look [here](https://developer.spotify.com/web-api/authorization-guide/#authorization_code_flow) for the requests that need to be made. You should be able to pass the response to RSpotify::User.new just as well, and from there easily create playlists and more for your user.
Expand Down
1 change: 1 addition & 0 deletions lib/rspotify/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class MissingAuthentication < StandardError; end

class << self
attr_accessor :raw_response
attr_accessor :pagination_info
attr_reader :client_token

# Authenticates access to restricted data. Requires {https://developer.spotify.com/my-applications user credentials}
Expand Down
5 changes: 4 additions & 1 deletion lib/rspotify/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ def playlists(limit: 20, offset: 0)
url = "users/#{@id}/playlists?limit=#{limit}&offset=#{offset}"
response = RSpotify.resolve_auth_request(@id, url)
return response if RSpotify.raw_response
response['items'].map { |i| Playlist.new i }
result = response
result['items'] = response['items'].map { |i| Playlist.new i }
return result if RSpotify.pagination_info
result['items']
end

# Remove tracks from the user’s “Your Music” library.
Expand Down