Class: SpotifyWebApi::CategoryObject

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

Overview

CategoryObject Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(href = nil, icons = nil, id = nil, name = nil) ⇒ CategoryObject

Returns a new instance of CategoryObject.



49
50
51
52
53
54
# File 'lib/spotify_web_api/models/category_object.rb', line 49

def initialize(href = nil, icons = nil, id = nil, name = nil)
  @href = href
  @icons = icons
  @id = id
  @name = name
end

Instance Attribute Details

#hrefString

A link to the Web API endpoint returning full details of the category.

Returns:

  • (String)


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

def href
  @href
end

#iconsArray[ImageObject]

The category icon, in various sizes.

Returns:



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

def icons
  @icons
end

#idString

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

Returns:

  • (String)


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

def id
  @id
end

#nameString

The name of the category.

Returns:

  • (String)


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

def name
  @name
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/spotify_web_api/models/category_object.rb', line 57

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  href = hash.key?('href') ? hash['href'] : nil
  # Parameter is an array, so we need to iterate through it

  icons = nil
  unless hash['icons'].nil?
    icons = []
    hash['icons'].each do |structure|
      icons << (ImageObject.from_hash(structure) if structure)
    end
  end

  icons = nil unless hash.key?('icons')
  id = hash.key?('id') ? hash['id'] : nil
  name = hash.key?('name') ? hash['name'] : nil

  # Create object from extracted values.

  CategoryObject.new(href,
                     icons,
                     id,
                     name)
end

.namesObject

A mapping from model property names to API property names.



30
31
32
33
34
35
36
37
# File 'lib/spotify_web_api/models/category_object.rb', line 30

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['href'] = 'href'
  @_hash['icons'] = 'icons'
  @_hash['id'] = 'id'
  @_hash['name'] = 'name'
  @_hash
end

.nullablesObject

An array for nullable fields



45
46
47
# File 'lib/spotify_web_api/models/category_object.rb', line 45

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  []
end