module Predictable::User

Predictable User Role

Defines the User role for the recommender. This module should be included in the User model of the appliation.

class User < ActiveRecord::Base
  include Predictable::User
  ...
end

Public Instance Methods

add_to_recommender(attrs={}) click to toggle source

Creates or updates a user in prediction.io When the user id already exists it updates the user. The operation is done asynchronously.

# File lib/predictable/user.rb, line 41
def add_to_recommender(attrs={})
  recommender.create_user(self, attrs)
  nil
end
delete_from_recommender() click to toggle source

Removes the user from prediction.io. The operation is done asynchronously.

# File lib/predictable/user.rb, line 48
def delete_from_recommender
  recommender.delete_user(self)
  nil
end
pio_uid() click to toggle source

Returns the user id

# File lib/predictable/user.rb, line 18
def pio_uid
  self.id
end
record_action(action, item, opts={}) click to toggle source

Record a user action in the recommender. Actions cannot be overwritten or deleted in prediction.io The operation is done asynchronously.

user.record_action(:conversion, item)
# File lib/predictable/user.rb, line 28
def record_action(action, item, opts={})
  recommender.record_action(self, action, item, opts)
  nil
end
record_conversion(item, opts={}) click to toggle source
# File lib/predictable/user.rb, line 33
def record_conversion(item, opts={})
  record_action(:conversion, item, opts)
  nil
end

Protected Instance Methods

recommender() click to toggle source
# File lib/predictable/user.rb, line 55
def recommender
  self.class.recommender
end