Class: Spotify::SDK::Item
- Defined in:
- lib/spotify/sdk/item.rb
Instance Attribute Summary
Attributes inherited from Model
Instance Method Summary collapse
-
#album ⇒ Spotify::SDK::Album
Get the album for this item.
-
#artist ⇒ Spotify::SDK::Artist
Get the primary artist/creator for this item.
-
#artists ⇒ Array
Get the artists/creators for this item.
-
#context ⇒ Hash
Get the context.
-
#duration ⇒ Integer
Get the duration.
-
#explicit? ⇒ TrueClass, FalseClass
Is this track explicit? Alias to self.explicit.
-
#initialize(payload, parent) ⇒ Item
constructor
Let's transform the item object into better for us.
-
#isrc ⇒ String
Get the ISRC for this track.
-
#local? ⇒ TrueClass, FalseClass
Is this a local track, not a Spotify track? Alias to self.is_local.
-
#playable? ⇒ TrueClass, FalseClass
Is this a playable track? Alias to self.is_playable.
-
#spotify_uri ⇒ String
Get the Spotify URI for this item.
-
#spotify_url ⇒ String
Get the Spotify HTTP URL for this item.
-
#track? ⇒ TrueClass, FalseClass
Is this a track? Alias to self.type == “track”.
Methods inherited from Model
alias_attribute, hash_selector, #to_h, #to_json
Constructor Details
#initialize(payload, parent) ⇒ Item
Let's transform the item object into better for us. Before: { track: …, played_at: …, context: … } After: { track_properties…, played_at: …, context: … }
:nodoc:
12 13 14 15 16 |
# File 'lib/spotify/sdk/item.rb', line 12 def initialize(payload, parent) track = payload.delete(:track) || payload.delete(:item) properties = payload.except(:parent, :device, :repeat_state, :shuffle_state) super(track.merge(properties: properties), parent) end |
Instance Method Details
#album ⇒ Spotify::SDK::Album
Get the album for this item.
26 27 28 |
# File 'lib/spotify/sdk/item.rb', line 26 def album Spotify::SDK::Album.new(super, parent) end |
#artist ⇒ Spotify::SDK::Artist
Get the primary artist/creator for this item.
52 53 54 |
# File 'lib/spotify/sdk/item.rb', line 52 def artist artists.first end |
#artists ⇒ Array
Get the artists/creators for this item.
38 39 40 41 42 |
# File 'lib/spotify/sdk/item.rb', line 38 def artists super.map do |artist| Spotify::SDK::Artist.new(artist, parent) end end |
#context ⇒ Hash
Get the context.
65 |
# File 'lib/spotify/sdk/item.rb', line 65 alias_attribute :context, "properties.context" |
#duration ⇒ Integer
Get the duration. Alias to self.duration_ms
76 |
# File 'lib/spotify/sdk/item.rb', line 76 alias_attribute :duration, :duration_ms |
#explicit? ⇒ TrueClass, FalseClass
Is this track explicit? Alias to self.explicit
87 |
# File 'lib/spotify/sdk/item.rb', line 87 alias_attribute :explicit?, :explicit |
#isrc ⇒ String
Get the ISRC for this track.
154 |
# File 'lib/spotify/sdk/item.rb', line 154 alias_attribute :isrc, "external_ids.isrc" |
#local? ⇒ TrueClass, FalseClass
Is this a local track, not a Spotify track? Alias to self.is_local
98 |
# File 'lib/spotify/sdk/item.rb', line 98 alias_attribute :local?, :is_local |
#playable? ⇒ TrueClass, FalseClass
Is this a playable track? Alias to self.is_playable
109 |
# File 'lib/spotify/sdk/item.rb', line 109 alias_attribute :playable?, :is_playable |
#spotify_uri ⇒ String
Get the Spotify URI for this item. Alias to self.uri
133 |
# File 'lib/spotify/sdk/item.rb', line 133 alias_attribute :spotify_uri, :uri |
#spotify_url ⇒ String
Get the Spotify HTTP URL for this item. Alias to self.external_urls
144 |
# File 'lib/spotify/sdk/item.rb', line 144 alias_attribute :spotify_url, "external_urls.spotify" |
#track? ⇒ TrueClass, FalseClass
Is this a track? Alias to self.type == “track”
120 121 122 |
# File 'lib/spotify/sdk/item.rb', line 120 def track? type == "track" end |