user6495201
user6495201

Reputation:

Getting undefined method when trying to use a ruby wrapper for the Spotify Web API

I was messing around with RSpotify which is a ruby wrapper for the Spotify API.

I added a form and sent the search result param to be looked up in the API but i'm getting the following error:

NoMethodError: undefined method `empty?' for nil:NilClass
from /Users/user/.rvm/gems/ruby-2.3.1/gems/rspotify-1.21.0/lib/rspotify/connection.rb:71:in `send_request'

I double checked and reinstalled the gem, added it to the gemfile and everything. I can't seem to figure out why it's not working.

Here's the code (It was working a few weeks ago when I wrote it):

post '/music' do
  search =  RSpotify::Artist.search(params[:search])
    @artist = search.first
    @image = @artist.images.first["url"]
    @top_tracks = @artist.top_tracks(:US)
    albums = @artist.albums
    @titles = []
    albums.each { |album| @titles << album.name }
    @titles.uniq!
    @related_artists = @artist.related_artists
    erb :'/music/show'
end

Upvotes: 1

Views: 168

Answers (1)

Clemens Kofler
Clemens Kofler

Reputation: 1968

You seem to be using an outdated version (1.21.0, judging by your output). The current version is 1.22.1 (see https://rubygems.org/gems/rspotify) => maybe try updating.

Also, like Jeff said: Apparently there's an open GitHub issue that says that this issue occurs when you're not properly authenticated. So maybe check that your credentials are 1) set and 2) still valid. A simple way to check your credentials is to simply use them with the API directly (see http://www.compciv.org/recipes/data/touring-the-spotify-api/) => if they don't work there, it's probably not the code but your credentials that aren't working properly.

Upvotes: 1

Related Questions