Class: SpotifyWebApi::PublicUserObject

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

Overview

PublicUserObject Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(display_name = SKIP, external_urls = SKIP, followers = SKIP, href = SKIP, id = SKIP, images = SKIP, type = SKIP, uri = SKIP) ⇒ PublicUserObject

Returns a new instance of PublicUserObject.



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/spotify_web_api/models/public_user_object.rb', line 81

def initialize(display_name = SKIP, external_urls = SKIP, followers = SKIP,
               href = SKIP, id = SKIP, images = SKIP, type = SKIP,
               uri = SKIP)
  @display_name = display_name unless display_name == 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
  @type = type unless type == SKIP
  @uri = uri unless uri == SKIP
end

Instance Attribute Details

#display_nameString

The name displayed on the user’s profile. ‘null` if not available.

Returns:

  • (String)


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

def display_name
  @display_name
end

#external_urlsExternalUrlObject

Known public external URLs for this user.

Returns:



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

def external_urls
  @external_urls
end

#followersFollowersObject

Information about the followers of this user.

Returns:



22
23
24
# File 'lib/spotify_web_api/models/public_user_object.rb', line 22

def followers
  @followers
end

#hrefString

A link to the Web API endpoint for this user.

Returns:

  • (String)


26
27
28
# File 'lib/spotify_web_api/models/public_user_object.rb', line 26

def href
  @href
end

#idString

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

Returns:

  • (String)


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

def id
  @id
end

#imagesArray[ImageObject]

The user’s profile image.

Returns:



35
36
37
# File 'lib/spotify_web_api/models/public_user_object.rb', line 35

def images
  @images
end

#typeType4Enum

The object type.

Returns:



39
40
41
# File 'lib/spotify_web_api/models/public_user_object.rb', line 39

def type
  @type
end

#uriString

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

Returns:

  • (String)


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

def uri
  @uri
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/spotify_web_api/models/public_user_object.rb', line 95

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  display_name = hash.key?('display_name') ? hash['display_name'] : 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')
  type = hash.key?('type') ? hash['type'] : SKIP
  uri = hash.key?('uri') ? hash['uri'] : SKIP

  # Create object from extracted values.
  PublicUserObject.new(display_name,
                       external_urls,
                       followers,
                       href,
                       id,
                       images,
                       type,
                       uri)
end

.namesObject

A mapping from model property names to API property names.



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/spotify_web_api/models/public_user_object.rb', line 47

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

.nullablesObject

An array for nullable fields



75
76
77
78
79
# File 'lib/spotify_web_api/models/public_user_object.rb', line 75

def self.nullables
  %w[
    display_name
  ]
end

.optionalsObject

An array for optional fields



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/spotify_web_api/models/public_user_object.rb', line 61

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