Class: SpotifyClient
- Inherits:
-
Object
- Object
- SpotifyClient
- Defined in:
- lib/spotifyexporter/lib/spotify.rb
Instance Method Summary collapse
-
#get_user(uname) ⇒ Object
GETs a user.
-
#get_user_playlists(uname) ⇒ Object
GETs all playlists for a user.
-
#initialize(conf) ⇒ SpotifyClient
constructor
A new instance of SpotifyClient.
Constructor Details
#initialize(conf) ⇒ SpotifyClient
Returns a new instance of SpotifyClient.
6 7 8 9 10 11 |
# File 'lib/spotifyexporter/lib/spotify.rb', line 6 def initialize(conf) RSpotify.authenticate( conf.spotify_client_id, conf.spotify_client_secret ) end |
Instance Method Details
#get_user(uname) ⇒ Object
GETs a user
18 19 20 |
# File 'lib/spotifyexporter/lib/spotify.rb', line 18 def get_user(uname) RSpotify::User.find(uname) end |
#get_user_playlists(uname) ⇒ Object
GETs all playlists for a user
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/spotifyexporter/lib/spotify.rb', line 27 def get_user_playlists(uname) u = get_user(uname) playlists = [] offset = 0 last_pull_count = 0 # You can only pull from API in increments of 50 # if the last pull count is a multiple of 50 # we know we can keep pulling, if not, stop while (last_pull_count % 50).zero? p = u.playlists(limit: 50, offset: offset) playlists << p offset += 50 last_pull_count = p.count end playlists.compact.flatten end |