Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Connecting with Ruby Spotify Gem Hangs

15 views
Skip to first unread message

Shawn Broukhim

unread,
Oct 24, 2014, 11:19:07 AM10/24/14
to ruby-s...@googlegroups.com

I have been trying to connect with the Spotify gem, have followed the documentation, but whenever I make a request it just hangs...

Here is the code I am working with:

I have created a Spotify Api Service Object which attempts to connect on initialization:

class SpotifyApiUtility
  require "bundler/setup"
  require "spotify"
  require "logger"
  require "pry"
  require "io/console"

 def initialize

  @config = Spotify::SessionConfig.new({
    api_version: Spotify::API_VERSION.to_i,
    application_key: File.binread("#{Rails.root}/app/services/spotify_appkey.key"),
    cache_location: "#{Rails.root}/app/services/spotify/",
    settings_location: "#{Rails.root}/app/services/spotify/",
    user_agent: "spotify for ruby",
    callbacks: Spotify::SessionCallbacks.new,
  })

  session = Spotify.session_create(@config)
  raise Spotify::APIError.new(error) if error
end

end

The session never gets created though, and it really just freezes. Does anyone have any suggestions about what I might be doing wrong?

Kim Burgestrand

unread,
Oct 27, 2014, 4:06:10 PM10/27/14
to Spotify for Ruby on behalf of Shawn Broukhim
Have you managed to get any of the examples to work, or have you managed to get this code to work outside of Rails?

I can't see anything immediately broken with this, but I could of course be wrong.

— Kim Burgestrand

--
You received this message because you are subscribed to the Google Groups "Spotify for Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-spotify...@googlegroups.com.
Visit this group at http://groups.google.com/group/ruby-spotify.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-spotify/cafef4d2-9837-4732-9849-7d141ae5c26b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kim Burgestrand

unread,
Oct 27, 2014, 4:08:39 PM10/27/14
to Spotify for Ruby on behalf of Shawn Broukhim
You'll also need to keep the session around. It's possible garbage collection is playing a prank on you. Store it in an instance variable at the very least.

— Kim Burgestrand

Shawn Broukhim

unread,
Oct 27, 2014, 4:42:39 PM10/27/14
to Spotify for Ruby on behalf of Kim Burgestrand
I haven't been able to get it to work on my system yet.  However, when I tried it on one of my colleague's computers it worked.  I am using Ruby version 2.1.2p95, my colleague's is an older build.  Could this be the root of the issue?

--
You received this message because you are subscribed to a topic in the Google Groups "Spotify for Ruby" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ruby-spotify/3gbkLVMq7mk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ruby-spotify...@googlegroups.com.

Kim Burgestrand

unread,
Oct 28, 2014, 3:52:54 AM10/28/14
to Spotify for Ruby on behalf of Shawn Broukhim
While nothing is impossible, the ruby version (as long as it's >= 2.0) should not affect this. Just to make sure, I tried the examples on 2.1.4p265 and I can create a session just fine.

In the past, I've used the following session configuration to diagnose issues:

    {
      api_version: Spotify::API_VERSION.to_i,
      application_key: File.binread("./spotify_appkey.key"),
      cache_location: ".spotify/",
      settings_location: ".spotify/",
      user_agent: "spotifyrb",
      tracefile: "tracefile.txt",
      callbacks: Spotify::SessionCallbacks.new({
        log_message: lambda do |session, message|
          $stdout.print "[LOG] #{message}"
        end
      })
    }

The above session configuration will create a file named tracefile.txt, which is a log of all libspotify calls made. In addition, it will also print log messages from libspotify to stdout.

Since I can't reproduce the hanging myself, I can't do much. However, the log output in the tracefile, and the output from stdout, could help in tracking down if the hanging is inside libspotify, or if it is inside the ruby code of the Spotify gem. This is the first step to resolving the issue.

It would be interesting to know which operating system you are using as well.

— Kim Burgestrand

Reply all
Reply to author
Forward
0 new messages