Class: RecombeeApiClient::AddPurchase
- Inherits:
-
ApiRequest
- Object
- ApiRequest
- RecombeeApiClient::AddPurchase
- Defined in:
- lib/recombee_api_client/api/add_purchase.rb
Overview
Adds a purchase of the given item made by the given user.
Instance Attribute Summary collapse
-
#additional_data ⇒ Object
readonly
Returns the value of attribute additional_data.
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#cascade_create ⇒ Object
readonly
Returns the value of attribute cascade_create.
-
#ensure_https ⇒ Object
Returns the value of attribute ensure_https.
-
#item_id ⇒ Object
readonly
Returns the value of attribute item_id.
-
#price ⇒ Object
readonly
Returns the value of attribute price.
-
#profit ⇒ Object
readonly
Returns the value of attribute profit.
-
#recomm_id ⇒ Object
readonly
Returns the value of attribute recomm_id.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Instance Method Summary collapse
-
#body_parameters ⇒ Object
Values of body parameters as a Hash.
-
#initialize(user_id, item_id, optional = {}) ⇒ AddPurchase
constructor
-
*Required arguments* -
user_id
-> User who purchased the item -item_id
-> Purchased item.
-
-
#method ⇒ Object
HTTP method.
-
#path ⇒ Object
Relative path to the endpoint.
-
#query_parameters ⇒ Object
Values of query parameters as a Hash.
Methods included from HashNormalizer
#camelize, #normalize_optional
Constructor Details
#initialize(user_id, item_id, optional = {}) ⇒ AddPurchase
-
*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 2. -
price
-> Price paid by the user for the item. If ‘amount` is greater than 1, the sum of prices of all the items should be given. -
profit
-> Your profit from the purchased item. The profit is natural in the 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 also applicable in other domains (for example, at a news company it may be income from a displayed advertisement on article page). If `amount` is greater than 1, the 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. -
additionalData
-> A dictionary of additional data for the interaction.
-
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/recombee_api_client/api/add_purchase.rb', line 31 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'] @additional_data = optional['additionalData'] @optional = optional @timeout = 3000 @ensure_https = false @optional.each do |par, _| fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate","amount","price","profit","recommId","additionalData"].include? par end end |
Instance Attribute Details
#additional_data ⇒ Object (readonly)
Returns the value of attribute additional_data.
13 14 15 |
# File 'lib/recombee_api_client/api/add_purchase.rb', line 13 def additional_data @additional_data end |
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
13 14 15 |
# File 'lib/recombee_api_client/api/add_purchase.rb', line 13 def amount @amount end |
#cascade_create ⇒ Object (readonly)
Returns the value of attribute cascade_create.
13 14 15 |
# File 'lib/recombee_api_client/api/add_purchase.rb', line 13 def cascade_create @cascade_create end |
#ensure_https ⇒ Object
Returns the value of attribute ensure_https.
15 16 17 |
# File 'lib/recombee_api_client/api/add_purchase.rb', line 15 def ensure_https @ensure_https end |
#item_id ⇒ Object (readonly)
Returns the value of attribute item_id.
13 14 15 |
# File 'lib/recombee_api_client/api/add_purchase.rb', line 13 def item_id @item_id end |
#price ⇒ Object (readonly)
Returns the value of attribute price.
13 14 15 |
# File 'lib/recombee_api_client/api/add_purchase.rb', line 13 def price @price end |
#profit ⇒ Object (readonly)
Returns the value of attribute profit.
13 14 15 |
# File 'lib/recombee_api_client/api/add_purchase.rb', line 13 def profit @profit end |
#recomm_id ⇒ Object (readonly)
Returns the value of attribute recomm_id.
13 14 15 |
# File 'lib/recombee_api_client/api/add_purchase.rb', line 13 def recomm_id @recomm_id end |
#timeout ⇒ Object
Returns the value of attribute timeout.
14 15 16 |
# File 'lib/recombee_api_client/api/add_purchase.rb', line 14 def timeout @timeout end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
13 14 15 |
# File 'lib/recombee_api_client/api/add_purchase.rb', line 13 def @timestamp end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
13 14 15 |
# File 'lib/recombee_api_client/api/add_purchase.rb', line 13 def user_id @user_id end |
Instance Method Details
#body_parameters ⇒ Object
Values of body parameters as a Hash
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/recombee_api_client/api/add_purchase.rb', line 56 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['additionalData'] = @optional['additionalData'] if @optional.include? 'additionalData' p end |
#method ⇒ Object
HTTP method
51 52 53 |
# File 'lib/recombee_api_client/api/add_purchase.rb', line 51 def method :post end |
#path ⇒ Object
Relative path to the endpoint
78 79 80 |
# File 'lib/recombee_api_client/api/add_purchase.rb', line 78 def path "/{databaseId}/purchases/" end |
#query_parameters ⇒ Object
Values of query parameters as a Hash. name of parameter => value of the parameter
72 73 74 75 |
# File 'lib/recombee_api_client/api/add_purchase.rb', line 72 def query_parameters params = {} params end |