Class: SpotifyWeb::Event Private

Inherits:
Object
  • Object
show all
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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

.commandsHash<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

#argsArray<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

#dataHash<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

#nameString (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

#resultsArray<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.

Yields:

  • (data)

    Gives the data to typecast to the block

Yield Parameters:

  • data (Hash)

    The data received from Spotify

Yield Returns:

  • The typecasted data that should be passed into any handlers bound to the event



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