Class: SpotifyWebApi::RecommendationsObject

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

Overview

RecommendationsObject Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(seeds = nil, tracks = nil) ⇒ RecommendationsObject

Returns a new instance of RecommendationsObject.



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

def initialize(seeds = nil, tracks = nil)
  @seeds = seeds
  @tracks = tracks
end

Instance Attribute Details

#seedsArray[RecommendationSeedObject]

An array of recommendation seed objects.

Returns:



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

def seeds
  @seeds
end

#tracksArray[TrackObject]

An array of track objects ordered according to the parameters supplied.

Returns:



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

def tracks
  @tracks
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/spotify_web_api/models/recommendations_object.rb', line 44

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  # Parameter is an array, so we need to iterate through it
  seeds = nil
  unless hash['seeds'].nil?
    seeds = []
    hash['seeds'].each do |structure|
      seeds << (RecommendationSeedObject.from_hash(structure) if structure)
    end
  end

  seeds = nil unless hash.key?('seeds')
  # Parameter is an array, so we need to iterate through it
  tracks = nil
  unless hash['tracks'].nil?
    tracks = []
    hash['tracks'].each do |structure|
      tracks << (TrackObject.from_hash(structure) if structure)
    end
  end

  tracks = nil unless hash.key?('tracks')

  # Create object from extracted values.
  RecommendationsObject.new(seeds,
                            tracks)
end

.namesObject

A mapping from model property names to API property names.



21
22
23
24
25
26
# File 'lib/spotify_web_api/models/recommendations_object.rb', line 21

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['seeds'] = 'seeds'
  @_hash['tracks'] = 'tracks'
  @_hash
end

.nullablesObject

An array for nullable fields



34
35
36
# File 'lib/spotify_web_api/models/recommendations_object.rb', line 34

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  []
end