Class: SpotifyWebApi::PlaylistObject

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/spotify_web_api/models/playlist_object.rb

Overview

PlaylistObject Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(collaborative = SKIP, description = SKIP, external_urls = SKIP, followers = SKIP, href = SKIP, id = SKIP, images = SKIP, name = SKIP, owner = SKIP, public = SKIP, snapshot_id = SKIP, tracks = SKIP, type = SKIP, uri = SKIP) ⇒ PlaylistObject

Returns a new instance of PlaylistObject.



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/spotify_web_api/models/playlist_object.rb', line 126

def initialize(collaborative = SKIP, description = SKIP,
               external_urls = SKIP, followers = SKIP, href = SKIP,
               id = SKIP, images = SKIP, name = SKIP, owner = SKIP,
               public = SKIP, snapshot_id = SKIP, tracks = SKIP,
               type = SKIP, uri = SKIP)
  @collaborative = collaborative unless collaborative == SKIP
  @description = description unless description == SKIP
  @external_urls = external_urls unless external_urls == SKIP
  @followers = followers unless followers == SKIP
  @href = href unless href == SKIP
  @id = id unless id == SKIP
  @images = images unless images == SKIP
  @name = name unless name == SKIP
  @owner = owner unless owner == SKIP
  @public = public unless public == SKIP
  @snapshot_id = snapshot_id unless snapshot_id == SKIP
  @tracks = tracks unless tracks == SKIP
  @type = type unless type == SKIP
  @uri = uri unless uri == SKIP
end

Instance Attribute Details

#collaborativeTrueClass | FalseClass

‘true` if the owner allows other users to modify the playlist.

Returns:

  • (TrueClass | FalseClass)


14
15
16
# File 'lib/spotify_web_api/models/playlist_object.rb', line 14

def collaborative
  @collaborative
end

#descriptionString

The playlist description. _Only returned for modified, verified playlists, otherwise_ ‘null`.

Returns:

  • (String)


19
20
21
# File 'lib/spotify_web_api/models/playlist_object.rb', line 19

def description
  @description
end

#external_urlsExternalUrlObject

Known external URLs for this playlist.

Returns:



23
24
25
# File 'lib/spotify_web_api/models/playlist_object.rb', line 23

def external_urls
  @external_urls
end

#followersFollowersObject

Information about the followers of the playlist.

Returns:



27
28
29
# File 'lib/spotify_web_api/models/playlist_object.rb', line 27

def followers
  @followers
end

#hrefString

A link to the Web API endpoint providing full details of the playlist.

Returns:

  • (String)


31
32
33
# File 'lib/spotify_web_api/models/playlist_object.rb', line 31

def href
  @href
end

#idString

The [Spotify ID](/documentation/web-api/concepts/spotify-uris-ids) for the playlist.

Returns:

  • (String)


36
37
38
# File 'lib/spotify_web_api/models/playlist_object.rb', line 36

def id
  @id
end

#imagesArray[ImageObject]

Images for the playlist. The array may be empty or contain up to three images. The images are returned by size in descending order. See [Working with Playlists](/documentation/web-api/concepts/playlists). _Note: If returned, the source URL for the image (‘url`) is temporary and will expire in less than a day._

Returns:



44
45
46
# File 'lib/spotify_web_api/models/playlist_object.rb', line 44

def images
  @images
end

#nameString

The name of the playlist.

Returns:

  • (String)


48
49
50
# File 'lib/spotify_web_api/models/playlist_object.rb', line 48

def name
  @name
end

#ownerPlaylistOwnerObject

The user who owns the playlist

Returns:



52
53
54
# File 'lib/spotify_web_api/models/playlist_object.rb', line 52

def owner
  @owner
end

#publicTrueClass | FalseClass

The playlist’s public/private status: ‘true` the playlist is public, `false` the playlist is private, `null` the playlist status is not relevant. For more about public/private status, see [Working with Playlists](/documentation/web-api/concepts/playlists)

Returns:

  • (TrueClass | FalseClass)


59
60
61
# File 'lib/spotify_web_api/models/playlist_object.rb', line 59

def public
  @public
end

#snapshot_idString

The version identifier for the current playlist. Can be supplied in other requests to target a specific playlist version

Returns:

  • (String)


64
65
66
# File 'lib/spotify_web_api/models/playlist_object.rb', line 64

def snapshot_id
  @snapshot_id
end

#tracksPagingPlaylistTrackObject

The tracks of the playlist.



68
69
70
# File 'lib/spotify_web_api/models/playlist_object.rb', line 68

def tracks
  @tracks
end

#typeString

The object type: “playlist”

Returns:

  • (String)


72
73
74
# File 'lib/spotify_web_api/models/playlist_object.rb', line 72

def type
  @type
end

#uriString

The [Spotify URI](/documentation/web-api/concepts/spotify-uris-ids) for the playlist.

Returns:

  • (String)


77
78
79
# File 'lib/spotify_web_api/models/playlist_object.rb', line 77

def uri
  @uri
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/spotify_web_api/models/playlist_object.rb', line 148

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  collaborative = hash.key?('collaborative') ? hash['collaborative'] : SKIP
  description = hash.key?('description') ? hash['description'] : SKIP
  external_urls = ExternalUrlObject.from_hash(hash['external_urls']) if hash['external_urls']
  followers = FollowersObject.from_hash(hash['followers']) if hash['followers']
  href = hash.key?('href') ? hash['href'] : SKIP
  id = hash.key?('id') ? hash['id'] : SKIP
  # Parameter is an array, so we need to iterate through it
  images = nil
  unless hash['images'].nil?
    images = []
    hash['images'].each do |structure|
      images << (ImageObject.from_hash(structure) if structure)
    end
  end

  images = SKIP unless hash.key?('images')
  name = hash.key?('name') ? hash['name'] : SKIP
  owner = PlaylistOwnerObject.from_hash(hash['owner']) if hash['owner']
  public = hash.key?('public') ? hash['public'] : SKIP
  snapshot_id = hash.key?('snapshot_id') ? hash['snapshot_id'] : SKIP
  tracks = PagingPlaylistTrackObject.from_hash(hash['tracks']) if hash['tracks']
  type = hash.key?('type') ? hash['type'] : SKIP
  uri = hash.key?('uri') ? hash['uri'] : SKIP

  # Create object from extracted values.
  PlaylistObject.new(collaborative,
                     description,
                     external_urls,
                     followers,
                     href,
                     id,
                     images,
                     name,
                     owner,
                     public,
                     snapshot_id,
                     tracks,
                     type,
                     uri)
end

.namesObject

A mapping from model property names to API property names.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/spotify_web_api/models/playlist_object.rb', line 80

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['collaborative'] = 'collaborative'
  @_hash['description'] = 'description'
  @_hash['external_urls'] = 'external_urls'
  @_hash['followers'] = 'followers'
  @_hash['href'] = 'href'
  @_hash['id'] = 'id'
  @_hash['images'] = 'images'
  @_hash['name'] = 'name'
  @_hash['owner'] = 'owner'
  @_hash['public'] = 'public'
  @_hash['snapshot_id'] = 'snapshot_id'
  @_hash['tracks'] = 'tracks'
  @_hash['type'] = 'type'
  @_hash['uri'] = 'uri'
  @_hash
end

.nullablesObject

An array for nullable fields



120
121
122
123
124
# File 'lib/spotify_web_api/models/playlist_object.rb', line 120

def self.nullables
  %w[
    description
  ]
end

.optionalsObject

An array for optional fields



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/spotify_web_api/models/playlist_object.rb', line 100

def self.optionals
  %w[
    collaborative
    description
    external_urls
    followers
    href
    id
    images
    name
    owner
    public
    snapshot_id
    tracks
    type
    uri
  ]
end