From 9b5f676e31c80727573e01fb43ed86427571567a Mon Sep 17 00:00:00 2001 From: Ryan Loomba Date: Sun, 17 Mar 2013 23:54:53 -0700 Subject: [PATCH] added similar tracks feature --- lib/beatport/catalog/track.rb | 11 +++++++++++ spec/catalog/track_spec.rb | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/beatport/catalog/track.rb b/lib/beatport/catalog/track.rb index 4f02800..bbebe90 100644 --- a/lib/beatport/catalog/track.rb +++ b/lib/beatport/catalog/track.rb @@ -43,6 +43,17 @@ def self.most_popular_for_label(id, options = {}) options[:collection] = true Client.retrieve "most-popular/label", Track, options end + + # also works for multiple id's as input + def self.similar(id, options = {}) + options[:id] = id + options[:collection] = true + Client.retrieve "tracks/similar", Track, options + end + + def similar(options = {}) + @similar ||= Track.similar(id, options) + end end end diff --git a/spec/catalog/track_spec.rb b/spec/catalog/track_spec.rb index 477e234..fe81d5e 100644 --- a/spec/catalog/track_spec.rb +++ b/spec/catalog/track_spec.rb @@ -177,6 +177,16 @@ module Beatport::Catalog end end end + describe '.similar' do + it "should get a list of tracks similar to track with id 1217790" do + tracks = Track.similar 1217790 + tracks.length.should be > 1 + end + it "should get a list of tracks similar to a list of track ids" do + tracks = Track.similar "4166013,1217790" + tracks.length.should be > 1 + end + end end end