Class: SpotifyWeb::Event Private
- Inherits:
-
Object
- Object
- SpotifyWeb::Event
- Defined in:
- lib/spotify_web/event.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Provides access to all of the events that get triggered by incoming messages from the Spotify Web API
Class Attribute Summary collapse
-
.commands ⇒ Hash<String, String>
readonly
private
Maps Spotify command => event name.
Instance Attribute Summary collapse
-
#args ⇒ Array<Object>
readonly
private
The raw arguments list from the event.
-
#data ⇒ Hash<String, Object>
readonly
private
The raw hash of data parsed from the event.
-
#name ⇒ String
readonly
private
The name of the event that was triggered.
-
#results ⇒ Array<Array<Object>>
readonly
private
The typecasted results args parsed from the event.
Class Method Summary collapse
-
.command?(command) ⇒ Boolean
private
Determines whether the given command is handled.
-
.handle(name, command = name) {|data| ... } ⇒ nil
private
Defines a new event that maps to the given Spotify command.
Instance Method Summary collapse
-
#initialize(client, command, args) ⇒ Event
constructor
private
Creates a new event triggered with the given data.
Constructor Details
#initialize(client, command, args) ⇒ Event
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new event triggered with the given data
82 83 84 85 86 87 88 89 |
# File 'lib/spotify_web/event.rb', line 82 def initialize(client, command, args) @client = client @args = args @data = args[0] @name = self.class.commands[command] @results = __send__("typecast_#{command}_event") @results = [[@results].compact] unless @results.is_a?(Array) end |
Class Attribute Details
.commands ⇒ Hash<String, String> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Maps Spotify command => event name
9 10 11 |
# File 'lib/spotify_web/event.rb', line 9 def commands @commands end |
Instance Attribute Details
#args ⇒ Array<Object> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The raw arguments list from the event
67 68 69 |
# File 'lib/spotify_web/event.rb', line 67 def args @args end |
#data ⇒ Hash<String, Object> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The raw hash of data parsed from the event
71 72 73 |
# File 'lib/spotify_web/event.rb', line 71 def data @data end |
#name ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The name of the event that was triggered
63 64 65 |
# File 'lib/spotify_web/event.rb', line 63 def name @name end |
#results ⇒ Array<Array<Object>> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The typecasted results args parsed from the event
75 76 77 |
# File 'lib/spotify_web/event.rb', line 75 def results @results end |
Class Method Details
.command?(command) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determines whether the given command is handled.
32 33 34 |
# File 'lib/spotify_web/event.rb', line 32 def command?(command) commands.include?(command) end |
.handle(name, command = name) {|data| ... } ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Defines a new event that maps to the given Spotify command. The block defines how to typecast the data that is received from Spotify.
20 21 22 23 24 25 26 |
# File 'lib/spotify_web/event.rb', line 20 def handle(name, command = name, &block) block ||= lambda { [args] } commands[command] = name define_method("typecast_#{command}_event", &block) protected :"typecast_#{command}_event" end |