Skip to content

Commit

Permalink
Added parameters amount,price,profit to AddPurchase and amount,price …
Browse files Browse the repository at this point in the history
…to AddCartAddition
  • Loading branch information
OndraFiedler committed Oct 26, 2017
1 parent e7c599b commit e0ef79c
Show file tree
Hide file tree
Showing 61 changed files with 1,037 additions and 116 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A Python client for easy use of the `Recombee <https://www.recombee.com/>`_ rec

If you don't have an account at Recombee yet, you can create a free account `here <https://www.recombee.com/>`_.

Documentation of the API can be found at `docs.recombee.com <https://docs.recombee.com/)>`_.
Documentation of the API can be found at `docs.recombee.com <https://docs.recombee.com/>`_.

=============
Installation
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def send(self, request):

@staticmethod
def __get_http_headers(additional_headers=None):
headers = {'User-Agent': 'recombee-python-api-client/1.5.0'}
headers = {'User-Agent': 'recombee-python-api-client/1.6.0'}
if additional_headers:
headers.update(additional_headers)
return headers
Expand Down
4 changes: 4 additions & 0 deletions recombee_api_client/api_requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
from recombee_api_client.api_requests.delete_view_portion import DeleteViewPortion
from recombee_api_client.api_requests.list_item_view_portions import ListItemViewPortions
from recombee_api_client.api_requests.list_user_view_portions import ListUserViewPortions
from recombee_api_client.api_requests.recommend_items_to_user import RecommendItemsToUser
from recombee_api_client.api_requests.recommend_users_to_user import RecommendUsersToUser
from recombee_api_client.api_requests.recommend_items_to_item import RecommendItemsToItem
from recombee_api_client.api_requests.recommend_users_to_item import RecommendUsersToItem
from recombee_api_client.api_requests.user_based_recommendation import UserBasedRecommendation
from recombee_api_client.api_requests.item_based_recommendation import ItemBasedRecommendation
from recombee_api_client.api_requests.reset_database import ResetDatabase
Expand Down
12 changes: 11 additions & 1 deletion recombee_api_client/api_requests/add_cart_addition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AddCartAddition(Request):
"""

def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT):
def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT, amount=DEFAULT, price=DEFAULT):
"""
Required parameters:
@param user_id: User who added the item to the cart
Expand All @@ -22,11 +22,17 @@ def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT):
@param cascade_create: Sets whether the given user/item should be created if not present in the database.
@param amount: Amount (number) added to cart. The default is 1. For example if `user-x` adds two `item-y` during a single order (session...), the `amount` should equal to 2.
@param price: Price of the added item. If `amount` is greater than 1, sum of prices of all the items should be given.
"""
self.user_id = user_id
self.item_id = item_id
self.timestamp = timestamp
self.cascade_create = cascade_create
self.amount = amount
self.price = price
self.timeout = 1000
self.ensure_https = False
self.method = 'post'
Expand All @@ -43,6 +49,10 @@ def get_body_parameters(self):
p['timestamp'] = self.timestamp
if self.cascade_create is not DEFAULT:
p['cascadeCreate'] = self.cascade_create
if self.amount is not DEFAULT:
p['amount'] = self.amount
if self.price is not DEFAULT:
p['price'] = self.price
return p

def get_query_parameters(self):
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_requests/add_item_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, property_name, type):
"""
self.property_name = property_name
self.type = type
self.timeout = 1000
self.timeout = 100000
self.ensure_https = False
self.method = 'put'
self.path = "/items/properties/%s" % (self.property_name)
Expand Down
17 changes: 16 additions & 1 deletion recombee_api_client/api_requests/add_purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AddPurchase(Request):
"""

def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT):
def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT, amount=DEFAULT, price=DEFAULT, profit=DEFAULT):
"""
Required parameters:
@param user_id: User who purchased the item
Expand All @@ -22,11 +22,20 @@ def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT):
@param cascade_create: Sets whether the given user/item should be created if not present in the database.
@param 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.
@param 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.
@param 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.
"""
self.user_id = user_id
self.item_id = item_id
self.timestamp = timestamp
self.cascade_create = cascade_create
self.amount = amount
self.price = price
self.profit = profit
self.timeout = 1000
self.ensure_https = False
self.method = 'post'
Expand All @@ -43,6 +52,12 @@ def get_body_parameters(self):
p['timestamp'] = self.timestamp
if self.cascade_create is not DEFAULT:
p['cascadeCreate'] = self.cascade_create
if self.amount is not DEFAULT:
p['amount'] = self.amount
if self.price is not DEFAULT:
p['price'] = self.price
if self.profit is not DEFAULT:
p['profit'] = self.profit
return p

def get_query_parameters(self):
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_requests/add_user_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, property_name, type):
"""
self.property_name = property_name
self.type = type
self.timeout = 1000
self.timeout = 100000
self.ensure_https = False
self.method = 'put'
self.path = "/users/properties/%s" % (self.property_name)
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_requests/delete_item_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, property_name):
"""
self.property_name = property_name
self.timeout = 1000
self.timeout = 100000
self.ensure_https = False
self.method = 'delete'
self.path = "/items/properties/%s" % (self.property_name)
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_requests/delete_user_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, property_name):
"""
self.property_name = property_name
self.timeout = 1000
self.timeout = 100000
self.ensure_https = False
self.method = 'delete'
self.path = "/users/properties/%s" % (self.property_name)
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_requests/get_user_property_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, property_name):
"""
self.property_name = property_name
self.timeout = 1000
self.timeout = 100000
self.ensure_https = False
self.method = 'get'
self.path = "/users/properties/%s" % (self.property_name)
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_requests/list_group_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, group_id):
"""
self.group_id = group_id
self.timeout = 1000
self.timeout = 100000
self.ensure_https = False
self.method = 'get'
self.path = "/groups/%s/items/" % (self.group_id)
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_requests/list_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ListGroups(Request):
def __init__(self):
"""
"""
self.timeout = 239000
self.timeout = 100000
self.ensure_https = False
self.method = 'get'
self.path = "/groups/list/" % ()
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_requests/list_item_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ListItemProperties(Request):
def __init__(self):
"""
"""
self.timeout = 1000
self.timeout = 100000
self.ensure_https = False
self.method = 'get'
self.path = "/items/properties/list/" % ()
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_requests/list_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(self, filter=DEFAULT, count=DEFAULT, offset=DEFAULT, return_propert
self.offset = offset
self.return_properties = return_properties
self.included_properties = included_properties
self.timeout = 600000
self.timeout = 100000
self.ensure_https = False
self.method = 'get'
self.path = "/items/list/" % ()
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_requests/list_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ListSeries(Request):
def __init__(self):
"""
"""
self.timeout = 239000
self.timeout = 100000
self.ensure_https = False
self.method = 'get'
self.path = "/series/list/" % ()
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_requests/list_series_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, series_id):
"""
self.series_id = series_id
self.timeout = 1000
self.timeout = 100000
self.ensure_https = False
self.method = 'get'
self.path = "/series/%s/items/" % (self.series_id)
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_requests/list_user_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ListUserProperties(Request):
def __init__(self):
"""
"""
self.timeout = 1000
self.timeout = 100000
self.ensure_https = False
self.method = 'get'
self.path = "/users/properties/list/" % ()
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_requests/list_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(self, filter=DEFAULT, count=DEFAULT, offset=DEFAULT, return_propert
self.offset = offset
self.return_properties = return_properties
self.included_properties = included_properties
self.timeout = 239000
self.timeout = 100000
self.ensure_https = False
self.method = 'get'
self.path = "/users/list/" % ()
Expand Down
2 changes: 1 addition & 1 deletion recombee_api_client/api_requests/merge_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class MergeUsers(Request):
"""
Merges purchases, ratings, bookmarks, and detail views of two different users under a single user ID. This is especially useful for online e-commerce applications working with anonymous users identified by unique tokens such as the session ID. In such applications, it may often happen that a user owns a persistent account, yet accesses the system anonymously while, e.g., putting items into a shopping cart. At some point in time, such as when the user wishes to confirm the purchase, (s)he logs into the system using his/her username and password. The interactions made under anonymous session ID then become connected with the persistent account, and merging these two together becomes desirable.
Merges interactions (purchases, ratings, bookmarks, detail views ...) of two different users under a single user ID. This is especially useful for online e-commerce applications working with anonymous users identified by unique tokens such as the session ID. In such applications, it may often happen that a user owns a persistent account, yet accesses the system anonymously while, e.g., putting items into a shopping cart. At some point in time, such as when the user wishes to confirm the purchase, (s)he logs into the system using his/her username and password. The interactions made under anonymous session ID then become connected with the persistent account, and merging these two together becomes desirable.
Merging happens between two users referred to as the *target* and the *source*. After the merge, all the interactions of the source user are attributed to the target user, and the source user is **deleted** unless special parameter `keepSourceUser` is set `true`.
Expand Down
Loading

0 comments on commit e0ef79c

Please sign in to comment.