Class: RSpotify::Recommendations
- Defined in:
- lib/rspotify/recommendations.rb
Instance Attribute Summary collapse
-
#seeds ⇒ Array<RecommendationSeed>
An array of recommendation seed objects.
-
#tracks ⇒ Array<Track>
An array of track object (simplified) ordered according to the parameters supplied.
Attributes inherited from Base
#external_urls, #href, #id, #type, #uri
Class Method Summary collapse
-
.available_genre_seeds ⇒ Array<String>
Retrieve a list of available genres seed parameter values for recommendations.
-
.generate(limit: 20, seed_artists: [], seed_genres: [], seed_tracks: [], market: nil, **options) ⇒ Array<Recommendations>
Create a playlist-style listening experience based on seed artists, tracks and genres.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Recommendations
constructor
A new instance of Recommendations.
Methods inherited from Base
#complete!, #embed, find, #method_missing, #respond_to?, search
Constructor Details
#initialize(options = {}) ⇒ Recommendations
Returns a new instance of Recommendations.
100 101 102 103 104 105 |
# File 'lib/rspotify/recommendations.rb', line 100 def initialize( = {}) @seeds = ['seeds'].map { |i| RecommendationSeed.new i } @tracks = ['tracks'].map { |i| Track.new i } super() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RSpotify::Base
Instance Attribute Details
#seeds ⇒ Array<RecommendationSeed>
An array of recommendation seed objects.
5 6 7 |
# File 'lib/rspotify/recommendations.rb', line 5 def seeds @seeds end |
#tracks ⇒ Array<Track>
An array of track object (simplified) ordered according to the parameters supplied.
5 6 7 |
# File 'lib/rspotify/recommendations.rb', line 5 def tracks @tracks end |
Class Method Details
.available_genre_seeds ⇒ Array<String>
Retrieve a list of available genres seed parameter values for recommendations.
12 13 14 15 16 17 |
# File 'lib/rspotify/recommendations.rb', line 12 def self.available_genre_seeds response = RSpotify.get('recommendations/available-genre-seeds') return response if RSpotify.raw_response response['genres'] end |
.generate(limit: 20, seed_artists: [], seed_genres: [], seed_tracks: [], market: nil, **options) ⇒ Array<Recommendations>
Up to 5 seed values may be provided in any combination of seed_artists, seed_tracks and seed_genres.
Create a playlist-style listening experience based on seed artists, tracks and genres
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/rspotify/recommendations.rb', line 76 def self.generate(limit: 20, seed_artists: [], seed_genres: [], seed_tracks: [], market: nil, **) url = "recommendations?limit=#{limit}" url << "&seed_artists=#{seed_artists.join(',')}" if seed_artists.any? url << "&seed_genres=#{seed_genres.join(',')}" if seed_genres.any? url << "&seed_tracks=#{seed_tracks.join(',')}" if seed_tracks.any? .each do |option, value| url << "&#{option}=#{value}" end response = if market.is_a? Hash url << '&market=from_token' User.oauth_get(market[:from].id, url) else url << "&market=#{market}" if market RSpotify.get(url) end return response if RSpotify.raw_response Recommendations.new response end |