Class: SpotifyWebApi::ArtistObject

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

Overview

ArtistObject Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(external_urls = SKIP, followers = SKIP, genres = SKIP, href = SKIP, id = SKIP, images = SKIP, name = SKIP, popularity = SKIP, type = SKIP, uri = SKIP) ⇒ ArtistObject

Returns a new instance of ArtistObject.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/spotify_web_api/models/artist_object.rb', line 94

def initialize(external_urls = SKIP, followers = SKIP, genres = SKIP,
               href = SKIP, id = SKIP, images = SKIP, name = SKIP,
               popularity = SKIP, type = SKIP, uri = SKIP)
  @external_urls = external_urls unless external_urls == SKIP
  @followers = followers unless followers == SKIP
  @genres = genres unless genres == SKIP
  @href = href unless href == SKIP
  @id = id unless id == SKIP
  @images = images unless images == SKIP
  @name = name unless name == SKIP
  @popularity = popularity unless popularity == SKIP
  @type = type unless type == SKIP
  @uri = uri unless uri == SKIP
end

Instance Attribute Details

#external_urlsExternalUrlObject

Known external URLs for this artist.

Returns:



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

def external_urls
  @external_urls
end

#followersFollowersObject

Information about the followers of the artist.

Returns:



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

def followers
  @followers
end

#genresArray[String]

A list of the genres the artist is associated with. If not yet classified, the array is empty.

Returns:

  • (Array[String])


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

def genres
  @genres
end

#hrefString

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

Returns:

  • (String)


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

def href
  @href
end

#idString

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

Returns:

  • (String)


32
33
34
# File 'lib/spotify_web_api/models/artist_object.rb', line 32

def id
  @id
end

#imagesArray[ImageObject]

Images of the artist in various sizes, widest first.

Returns:



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

def images
  @images
end

#nameString

The name of the artist.

Returns:

  • (String)


40
41
42
# File 'lib/spotify_web_api/models/artist_object.rb', line 40

def name
  @name
end

#popularityInteger

The popularity of the artist. The value will be between 0 and 100, with 100 being the most popular. The artist’s popularity is calculated from the popularity of all the artist’s tracks.

Returns:

  • (Integer)


46
47
48
# File 'lib/spotify_web_api/models/artist_object.rb', line 46

def popularity
  @popularity
end

#typeTypeEnum

The object type.

Returns:



50
51
52
# File 'lib/spotify_web_api/models/artist_object.rb', line 50

def type
  @type
end

#uriString

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

Returns:

  • (String)


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

def uri
  @uri
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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/artist_object.rb', line 110

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  external_urls = ExternalUrlObject.from_hash(hash['external_urls']) if hash['external_urls']
  followers = FollowersObject.from_hash(hash['followers']) if hash['followers']
  genres = hash.key?('genres') ? hash['genres'] : SKIP
  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
  popularity = hash.key?('popularity') ? hash['popularity'] : SKIP
  type = hash.key?('type') ? hash['type'] : SKIP
  uri = hash.key?('uri') ? hash['uri'] : SKIP

  # Create object from extracted values.
  ArtistObject.new(external_urls,
                   followers,
                   genres,
                   href,
                   id,
                   images,
                   name,
                   popularity,
                   type,
                   uri)
end

.namesObject

A mapping from model property names to API property names.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/spotify_web_api/models/artist_object.rb', line 58

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['external_urls'] = 'external_urls'
  @_hash['followers'] = 'followers'
  @_hash['genres'] = 'genres'
  @_hash['href'] = 'href'
  @_hash['id'] = 'id'
  @_hash['images'] = 'images'
  @_hash['name'] = 'name'
  @_hash['popularity'] = 'popularity'
  @_hash['type'] = 'type'
  @_hash['uri'] = 'uri'
  @_hash
end

.nullablesObject

An array for nullable fields



90
91
92
# File 'lib/spotify_web_api/models/artist_object.rb', line 90

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    external_urls
    followers
    genres
    href
    id
    images
    name
    popularity
    type
    uri
  ]
end