Class: Spotify::SDK

Inherits:
Object
  • Object
show all
Defined in:
lib/spotify/sdk.rb,
lib/spotify/sdk/me.rb,
lib/spotify/sdk/base.rb,
lib/spotify/sdk/item.rb,
lib/spotify/sdk/album.rb,
lib/spotify/sdk/image.rb,
lib/spotify/sdk/model.rb,
lib/spotify/sdk/artist.rb,
lib/spotify/sdk/connect.rb,
lib/spotify/sdk/me/info.rb,
lib/spotify/sdk/connect/device.rb,
lib/spotify/sdk/connect/playback_state.rb

Overview

Spotify::SDK contains the complete Ruby DSL to interact with the Spotify Platform.

Defined Under Namespace

Classes: Album, Artist, Base, Connect, Image, Item, Me, Model

Constant Summary collapse

SDK_COMPONENTS =

This is where we mount new SDK components to the Spotify::SDK object. Simply add a key (this is your identifier) with the value being the object.

Notes:

  • Make sure your SDK component is being loaded at the top of this page.

  • You can name your identifier whatever you want:

    • This will be what people will use to call your code

    • For example: it would be the `connect` in `Spotify::SDK.new(@session).connect`

  • We'll call .new on your class, providing one parameter being the instance of this SDK (aka self).

  • Make sure to a test for it in spec/lib/spotify/sdk_spec.rb (see how we did it for others)

{
  connect: Spotify::SDK::Connect,
  me:      Spotify::SDK::Me
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ SDK

Initialize the Spotify SDK object.

Examples:

# Example 1: Load it in from an access token value.
@sdk = Spotify::SDK.new("access_token_here")

# Example 2: Load it in with values from your database.
@sdk = Spotify::SDK.new({
  access_token: "access_token_here",
  expires_in: 3_000_000,
  refresh_token: "refresh_token_here"
})

# Example 4: Load it in from an OAuth2::AccessToken object.
@sdk = Spotify::SDK.new(@auth.auth_code.get_token("auth code"))

# Example 5: Load it from a query string or a fully qualified URL.
@sdk = Spotify::SDK.new("https://localhost:8080/#token=...&expires_in=...")
@sdk = Spotify::SDK.new("token=...&expires_in=...")

Parameters:

  • session (String, Hash, OAuth2::AccessToken)

    Any supported object containing an access token.


48
49
50
51
52
53
# File 'lib/spotify/sdk.rb', line 48

def initialize(session)
  raise "Invalid Spotify::Accounts::Session object" unless session.instance_of?(Spotify::Accounts::Session)

  @session = session
  mount_sdk_components
end

Instance Attribute Details

#sessionObject (readonly)

Returns the value of attribute session


55
56
57
# File 'lib/spotify/sdk.rb', line 55

def session
  @session
end

Instance Method Details

#inspectObject

:nodoc:


57
58
59
# File 'lib/spotify/sdk.rb', line 57

def inspect # :nodoc:
  "#<%s:0x00%x>" % [self.class.name, (object_id << 1)]
end