Module: Predictable::User

Extended by:
ActiveSupport::Concern
Defined in:
lib/predictable/user.rb

Overview

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

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#add_to_recommender(attrs = {}) ⇒ Object

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



47
48
49
50
# File 'lib/predictable/user.rb', line 47

def add_to_recommender(attrs={})
  recommender.create_user(self, attrs)
  nil
end

#delete_from_recommenderObject

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



54
55
56
57
# File 'lib/predictable/user.rb', line 54

def delete_from_recommender
  recommender.delete_user(self)
  nil
end

#pio_uidObject

Returns the user id



24
25
26
# File 'lib/predictable/user.rb', line 24

def pio_uid
  self.id
end

#record_action(action, item, opts = {}) ⇒ Object

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)


34
35
36
37
# File 'lib/predictable/user.rb', line 34

def record_action(action, item, opts={})
  recommender.record_action(self, action, item, opts)
  nil
end

#record_conversion(item, opts = {}) ⇒ Object



39
40
41
42
# File 'lib/predictable/user.rb', line 39

def record_conversion(item, opts={})
  record_action(:conversion, item, opts)
  nil
end