lib/rspotify/playlist.rb in rspotify-1.18.0 vs lib/rspotify/playlist.rb in rspotify-1.19.0
- old
+ new
@@ -113,11 +113,11 @@
end
# Adds one or more tracks to a playlist in user's Spotify account. This method is only available when the
# current user has granted access to the *playlist-modify-public* and *playlist-modify-private* scopes.
#
- # @param tracks [Array<Track>] Tracks to be added. Maximum: 100 per request
+ # @param tracks [Array<Track>, Array<String>] Tracks to be added. Either array of Tracks or strings where each string is a valid spotify track uri. Maximum: 100 per request
# @param position [Integer, NilClass] The position to insert the tracks, a zero-based index. Default: tracks are appended to the playlist
# @return [Array<Track>] The tracks added
#
# @example
# tracks = RSpotify::Track.search('Know', 30)
@@ -128,10 +128,15 @@
# playlist.tracks.first.name #=> "Somebody That I Used To Know"
#
# playlist.add_tracks!(tracks, position: 20)
# playlist.tracks[20].name #=> "Somebody That I Used To Know"
def add_tracks!(tracks, position: nil)
- track_uris = tracks.map(&:uri).join(',')
+ track_uris = nil
+ if tracks.first.is_a? String
+ track_uris = tracks.join(',')
+ else
+ track_uris = tracks.map(&:uri).join(',')
+ end
url = "#{@path}/tracks?uris=#{track_uris}"
url << "&position=#{position}" if position
response = User.oauth_post(@owner.id, url, {})
@total += tracks.size