lib/meducation_sdk/services/recommender.rb in meducation_sdk-1.6.11 vs lib/meducation_sdk/services/recommender.rb in meducation_sdk-1.6.12

- old
+ new

@@ -1,11 +1,15 @@ module MeducationSDK class Recommender include Helpers def self.recommend(items, options = {}) - new(items, options).recommend + if items.is_a?(User) + UserRecommender.new(items, options).recommend + else + new(items, options).recommend + end end attr_reader :items def initialize(items, options = {}) @items = [items].flatten @@ -80,8 +84,24 @@ config.logger.error(*args) end def config MeducationSDK.config + end + + class UserRecommender + include Helpers + def initialize(user, options = {}) + @user = user + @options = options + @limit = options[:limit] || 5 + end + + def recommend + results = Loquor.get("items/recommendations_for_user", user_id: @user.id) + results.map do |result| + sdk_class_for(result[:type]).new(result) + end + end end end end