Class: SpotifyWebApi::AlbumBase

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

Overview

AlbumBase Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(album_type = nil, total_tracks = nil, available_markets = nil, external_urls = nil, href = nil, id = nil, images = nil, name = nil, release_date = nil, release_date_precision = nil, type = nil, uri = nil, restrictions = SKIP) ⇒ AlbumBase

Returns a new instance of AlbumBase.



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

def initialize(album_type = nil, total_tracks = nil,
               available_markets = nil, external_urls = nil, href = nil,
               id = nil, images = nil, name = nil, release_date = nil,
               release_date_precision = nil, type = nil, uri = nil,
               restrictions = SKIP)
  @album_type = album_type
  @total_tracks = total_tracks
  @available_markets = available_markets
  @external_urls = external_urls
  @href = href
  @id = id
  @images = images
  @name = name
  @release_date = release_date
  @release_date_precision = release_date_precision
  @restrictions = restrictions unless restrictions == SKIP
  @type = type
  @uri = uri
end

Instance Attribute Details

#album_typeAlbumTypeEnum

The type of the album.

Returns:



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

def album_type
  @album_type
end

#available_marketsArray[String]

The markets in which the album is available: [ISO 3166-1 alpha-2 country codes](en.wikipedia.org/wiki/ISO_3166-1_alpha-2). _NOTE: an album is considered available in a market when at least 1 of its tracks is available in that market._

Returns:

  • (Array[String])


25
26
27
# File 'lib/spotify_web_api/models/album_base.rb', line 25

def available_markets
  @available_markets
end

#external_urlsExternalUrlObject

Known external URLs for this album.

Returns:



29
30
31
# File 'lib/spotify_web_api/models/album_base.rb', line 29

def external_urls
  @external_urls
end

#hrefString

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

Returns:

  • (String)


33
34
35
# File 'lib/spotify_web_api/models/album_base.rb', line 33

def href
  @href
end

#idString

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

Returns:

  • (String)


38
39
40
# File 'lib/spotify_web_api/models/album_base.rb', line 38

def id
  @id
end

#imagesArray[ImageObject]

The cover art for the album in various sizes, widest first.

Returns:



42
43
44
# File 'lib/spotify_web_api/models/album_base.rb', line 42

def images
  @images
end

#nameString

The name of the album. In case of an album takedown, the value may be an empty string.

Returns:

  • (String)


47
48
49
# File 'lib/spotify_web_api/models/album_base.rb', line 47

def name
  @name
end

#release_dateString

The date the album was first released.

Returns:

  • (String)


51
52
53
# File 'lib/spotify_web_api/models/album_base.rb', line 51

def release_date
  @release_date
end

#release_date_precisionReleaseDatePrecisionEnum

The precision with which ‘release_date` value is known.



55
56
57
# File 'lib/spotify_web_api/models/album_base.rb', line 55

def release_date_precision
  @release_date_precision
end

#restrictionsAlbumRestrictionObject

Included in the response when a content restriction is applied.



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

def restrictions
  @restrictions
end

#total_tracksInteger

The number of tracks in the album.

Returns:

  • (Integer)


18
19
20
# File 'lib/spotify_web_api/models/album_base.rb', line 18

def total_tracks
  @total_tracks
end

#typeType2Enum

The object type.

Returns:



63
64
65
# File 'lib/spotify_web_api/models/album_base.rb', line 63

def type
  @type
end

#uriString

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

Returns:

  • (String)


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

def uri
  @uri
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/spotify_web_api/models/album_base.rb', line 122

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  album_type = hash.key?('album_type') ? hash['album_type'] : nil
  total_tracks = hash.key?('total_tracks') ? hash['total_tracks'] : nil
  available_markets =
    hash.key?('available_markets') ? hash['available_markets'] : nil
  external_urls = ExternalUrlObject.from_hash(hash['external_urls']) if hash['external_urls']
  href = hash.key?('href') ? hash['href'] : nil
  id = hash.key?('id') ? hash['id'] : nil
  # 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 = nil unless hash.key?('images')
  name = hash.key?('name') ? hash['name'] : nil
  release_date = hash.key?('release_date') ? hash['release_date'] : nil
  release_date_precision =
    hash.key?('release_date_precision') ? hash['release_date_precision'] : nil
  type = hash.key?('type') ? hash['type'] : nil
  uri = hash.key?('uri') ? hash['uri'] : nil
  restrictions = AlbumRestrictionObject.from_hash(hash['restrictions']) if
    hash['restrictions']

  # Create object from extracted values.
  AlbumBase.new(album_type,
                total_tracks,
                available_markets,
                external_urls,
                href,
                id,
                images,
                name,
                release_date,
                release_date_precision,
                type,
                uri,
                restrictions)
end

.namesObject

A mapping from model property names to API property names.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/spotify_web_api/models/album_base.rb', line 71

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['album_type'] = 'album_type'
  @_hash['total_tracks'] = 'total_tracks'
  @_hash['available_markets'] = 'available_markets'
  @_hash['external_urls'] = 'external_urls'
  @_hash['href'] = 'href'
  @_hash['id'] = 'id'
  @_hash['images'] = 'images'
  @_hash['name'] = 'name'
  @_hash['release_date'] = 'release_date'
  @_hash['release_date_precision'] = 'release_date_precision'
  @_hash['restrictions'] = 'restrictions'
  @_hash['type'] = 'type'
  @_hash['uri'] = 'uri'
  @_hash
end

.nullablesObject

An array for nullable fields



97
98
99
# File 'lib/spotify_web_api/models/album_base.rb', line 97

def self.nullables
  []
end

.optionalsObject

An array for optional fields



90
91
92
93
94
# File 'lib/spotify_web_api/models/album_base.rb', line 90

def self.optionals
  %w[
    restrictions
  ]
end