class RecombeeApiClient::AddPurchase

Adds a purchase of a given item made by a given user.

Attributes

amount[R]
cascade_create[R]
ensure_https[RW]
item_id[R]
price[R]
profit[R]
recomm_id[R]
timeout[RW]
timestamp[R]
user_id[R]

Public Class Methods

new(user_id, item_id, optional = {}) click to toggle source
  • *Required arguments*

    • user_id -> User who purchased the item

    • item_id -> Purchased item

  • *Optional arguments (given as hash optional)*

    • timestamp -> UTC timestamp of the purchase as ISO8601-1 pattern or UTC epoch time. The default value is the current time.

    • cascadeCreate -> Sets whether the given user/item should be created if not present in the database.

    • amount -> Amount (number) of purchased items. The default is 1. For example if `user-x` purchases two `item-y` during a single order (session…), the `amount` should equal to 2.

    • price -> Price paid by the user for the item. If `amount` is greater than 1, sum of prices of all the items should be given.

    • profit -> Your profit from the purchased item. The profit is natural in e-commerce domain (for example if `user-x` purchases `item-y` for $100 and the gross margin is 30 %, then the profit is $30), but is applicable also in other domains (for example at a news company it may be income from displayed advertisement on article page). If `amount` is greater than 1, sum of profit of all the items should be given.

    • recommId -> If this purchase is based on a recommendation request, `recommId` is the id of the clicked recommendation.

# File lib/recombee_api_client/api/add_purchase.rb, line 30
def initialize(user_id, item_id, optional = {})
  @user_id = user_id
  @item_id = item_id
  optional = normalize_optional(optional)
  @timestamp = optional['timestamp']
  @cascade_create = optional['cascadeCreate']
  @amount = optional['amount']
  @price = optional['price']
  @profit = optional['profit']
  @recomm_id = optional['recommId']
  @optional = optional
  @timeout = 1000
  @ensure_https = false
  @optional.each do |par, _|
    fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate","amount","price","profit","recommId"].include? par
  end
end

Public Instance Methods

body_parameters() click to toggle source

Values of body parameters as a Hash

# File lib/recombee_api_client/api/add_purchase.rb, line 54
def body_parameters
  p = Hash.new
  p['userId'] = @user_id
  p['itemId'] = @item_id
  p['timestamp'] = @optional['timestamp'] if @optional.include? 'timestamp'
  p['cascadeCreate'] = @optional['cascadeCreate'] if @optional.include? 'cascadeCreate'
  p['amount'] = @optional['amount'] if @optional.include? 'amount'
  p['price'] = @optional['price'] if @optional.include? 'price'
  p['profit'] = @optional['profit'] if @optional.include? 'profit'
  p['recommId'] = @optional['recommId'] if @optional.include? 'recommId'
  p
end
method() click to toggle source

HTTP method

# File lib/recombee_api_client/api/add_purchase.rb, line 49
def method
  :post
end
path() click to toggle source

Relative path to the endpoint

# File lib/recombee_api_client/api/add_purchase.rb, line 75
def path
  "/{databaseId}/purchases/"
end
query_parameters() click to toggle source

Values of query parameters as a Hash. name of parameter => value of the parameter

# File lib/recombee_api_client/api/add_purchase.rb, line 69
def query_parameters
  params = {}
  params
end