Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save predictioniogists/6590736 to your computer and use it in GitHub Desktop.
Save predictioniogists/6590736 to your computer and use it in GitHub Desktop.
require "predictionio"
# In the beginning of your application, you need to instantiate the PredictionIO client object.
# You need this client object to import data into PredictionIO and retrieve prediction results.
# Add this line to the place where you do initialization:
client = PredictionIO::Client.new("your App Key")
# Then add the following lines to your codes which handle the corresponding application logic:
# When a new user registers:
begin
result = client.create_user("the new user ID")
rescue UserNotCreatedError => e
log_error(e)
end
# When a new meal is added:
begin
result = client.create_item("name of new meal", ["category type ID 1", "category type ID 2"])
rescue ItemNotCreatedError => e
log_error(e)
end
# When your user logs in:
client.identify("the logged-in user ID")
# When the logged-in user clicks or views a meal:
begin
result = client.record_action_on_item("view", "the viewed meal ID")
rescue U2IActionNotCreatedError => e
log_error(e)
end
# When the logged-in user orders a meal and pay:
# use built-in action "conversion" to represent the "order and pay" action
begin
result = client.record_action_on_item("conversion", "ordered meal ID")
rescue U2IActionNotCreatedError => e
log_error(e)
end
# When the logged-in user rates a meal:
# the variable rating stores the rating value (from 1 to 5 )
begin
result = client.record_action_on_item("rate", "rated meal ID", "pio_rate" => rating)
rescue U2IActionNotCreatedError => e
log_error(e)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment