I do the following call to get a Ruby object, which returns data from Spotify's API:
spotify_track = RSpotify::AudioFeatures.find('3RmAqYZZjiSyMV40hm6rDL')
That returns:
#<RSpotify::AudioFeatures:0x00007fe0cc079b30 @acousticness=nil, @analysis_url="https://api.spotify.com/v1/audio-analysis/3RmAqYZZjiSyMV40hm6rDL", @danceability=nil, @duration_ms=35361, @energy=nil, @instrumentalness=nil, @key=1, @liveness=nil, @loudness=-12.186, @mode=1, @speechiness=nil, @tempo=0, @time_signature=nil, @track_href="https://api.spotify.com/v1/tracks/3RmAqYZZjiSyMV40hm6rDL", @valence=nil, @external_urls=nil, @href=nil, @id="3RmAqYZZjiSyMV40hm6rDL", @type="audio_features", @uri="spotify:track:3RmAqYZZjiSyMV40hm6rDL">
When I try to get one of the attributes that's nil
, I get a 404 error:
> spotify_track.acousticness
Traceback (most recent call last):
1: from (irb):25
RestClient::NotFound (404 Not Found)
So, how can I check to see if an attribute is nil
or not?
The usual things like spotify_track.acousticness.present?
, spotify_track.acousticness.blank?
and spotify_track.try(:acousticness)
all return that same RestClient 404 error.
I'm using the RSpotify gem, which makes use of the REST Client gem.