Module: SpotifyWeb
- Defined in:
- lib/spotify_web.rb,
lib/spotify_web/resource.rb,
lib/spotify_web/song.rb,
lib/spotify_web/user.rb,
lib/spotify_web/album.rb,
lib/spotify_web/error.rb,
lib/spotify_web/event.rb,
lib/spotify_web/artist.rb,
lib/spotify_web/client.rb,
lib/spotify_web/schema.rb,
lib/spotify_web/handler.rb,
lib/spotify_web/version.rb,
lib/spotify_web/loggable.rb,
lib/spotify_web/playlist.rb,
lib/spotify_web/assertions.rb,
lib/spotify_web/connection.rb,
lib/spotify_web/restriction.rb,
lib/spotify_web/schema/core.pb.rb,
lib/spotify_web/authorized_user.rb,
lib/spotify_web/schema/radio.pb.rb,
lib/spotify_web/schema/mercury.pb.rb,
lib/spotify_web/schema/metadata.pb.rb,
lib/spotify_web/resource_collection.rb,
lib/spotify_web/schema/playlist4.pb.rb,
lib/spotify_web/schema/socialgraph.pb.rb
Overview
Spotify Web API for Ruby
Defined Under Namespace
Modules: Assertions, Loggable, Schema, Version Classes: APIError, Album, Artist, AuthorizedUser, Client, Connection, ConnectionError, Error, Event, Handler, Playlist, Resource, ResourceCollection, Restriction, Song, User
Constant Summary collapse
- USER_AGENT =
The user agent for Spotify access
'node-spotify-web (Chrome/13.37 compatible-ish)'
Class Attribute Summary collapse
-
.logger ⇒ Logger
The logger to use for all Spotify messages.
Class Method Summary collapse
-
.interactive ⇒ Object
Whether this is going to be used in an interactive console such as IRB.
-
.run(*args, &block) ⇒ Object
Sets up the proper EventMachine reactor / Fiber to run commands against a client.
Class Attribute Details
.logger ⇒ Logger
The logger to use for all Spotify messages. By default, everything is logged to STDOUT.
17 18 19 |
# File 'lib/spotify_web.rb', line 17 def logger @logger end |
Class Method Details
.interactive ⇒ Object
You must continue to run all commands on a client through SpotifyWeb#run.
Whether this is going to be used in an interactive console such as IRB. If this is enabled then EventMachine will run in a separate thread. This will allow IRB to continue to actually be interactive.
38 39 40 |
# File 'lib/spotify_web.rb', line 38 def interactive Thread.new { EM.run }.abort_on_exception = true end |
.run(*args, &block) ⇒ Object
If you’re already running within an EventMachine reactor and a
Sets up the proper EventMachine reactor / Fiber to run commands against a client. If this is not in interactive mode, then the block won’t return until the EventMachine reactor is stopped.
Fiber, then there’s no need to call this method prior to interacting with a SpotifyWeb::Client instance.
Exception handling
Any exceptions that occur within the block will be automatically caught and logged. This prevents the EventMachine reactor from dying.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/spotify_web.rb', line 81 def run(*args, &block) if EM.reactor_running? EM.next_tick do EM.synchrony do begin if args.any? # Run the block within a client Client.new(*args, &block) else # Just run the block within a fiber block.call end rescue StandardError => ex logger.error(([ex.] + ex.backtrace) * "\n") end end end else EM.synchrony { run(*args, &block) } end end |