Skip to content

Commit 3586ac3

Browse files
committed
Use new recommendation endpoints
1 parent 08d41c0 commit 3586ac3

12 files changed

Lines changed: 35 additions & 41 deletions

README.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Or install it yourself as:
2929
require 'recombee_api_client'
3030
include RecombeeApiClient
3131

32-
client = RecombeeClient.new('client-test', 'jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L')
32+
client = RecombeeClient('--my-database-id--', '--my-secret-token--')
3333

3434
# Generate some random purchases of items by users
3535
NUM = 100
@@ -55,7 +55,7 @@ begin
5555
client.send(Batch.new(purchases))
5656

5757
# Get recommendations for user 'user-25'
58-
recommended = client.send(UserBasedRecommendation.new('user-25', 5))
58+
recommended = client.send(RecommendItemsToUser.new('user-25', 5))
5959
puts "Recommended items for user-25: #{recommended}"
6060
rescue APIError => e
6161
puts e
@@ -71,7 +71,7 @@ include RecombeeApiClient
7171
NUM = 100
7272
PROBABILITY_PURCHASED = 0.1
7373

74-
client = RecombeeClient.new('client-test', 'jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L')
74+
client = RecombeeClient('--my-database-id--', '--my-secret-token--')
7575
client.send(ResetDatabase.new) # Clear everything from the database
7676

7777
# We will use computers as items in this example
@@ -121,21 +121,19 @@ end
121121
client.send(Batch.new(requests))
122122

123123
# Get 5 recommendations for user-42, who is currently viewing computer-6
124-
recommended = client.send(ItemBasedRecommendation.new('computer-6', 5, 'targetUserId' => 'user-42') )
124+
recommended = client.send(RecommendItemsToItem.new('computer-6', 'user-42', 5) )
125125
puts "Recommended items: #{recommended}"
126126

127-
# Get 5 recommendations for user-42, but recommend only computers that
128-
# have at least 3 cores
127+
# Recommend only computers that have at least 3 cores
129128
recommended = client.send(
130-
ItemBasedRecommendation.new('computer-6', 5, {'targetUserId' => 'user-42', 'filter' => "'num-cores'>=3"})
129+
RecommendItemsToItem.new('computer-6', 'user-42', 5, {'filter' => "'num-cores'>=3"})
131130
)
132131
puts "Recommended items with at least 3 processor cores: #{recommended}"
133132

134-
# Get 5 recommendations for user-42, but recommend only items that
135-
# are more expensive then currently viewed item (up-sell)
133+
# Recommend only items thatare more expensive then currently viewed item (up-sell)
136134
recommended = client.send(
137-
ItemBasedRecommendation.new('computer-6', 5,
138-
{'targetUserId' => 'user-42', 'filter' => "'price' > context_item[\"price\"]"})
135+
RecommendItemsToItem.new('computer-6', 'user-42', 5,
136+
{'filter' => "'price' > context_item[\"price\"]"})
139137
)
140138
puts "Recommended up-sell items: #{recommended}"
141139
```
@@ -151,14 +149,14 @@ Example:
151149

152150
begin
153151
recommended = client.send(
154-
ItemBasedRecommendation.new('computer-6', 5,
155-
{'targetUserId' => 'user-42', 'filter' => "'price' > context_item[\"price\"]"})
152+
RecommendItemsToItem.new('computer-6', 'user-42', 5,
153+
{'filter' => "'price' > context_item[\"price\"]"})
156154
)
157155
rescue ResponseError => e
158-
#Handle errorneous request => use fallback
156+
# Handle errorneous request => use fallback
159157
rescue ApiTimeout => e
160-
#Handle timeout => use fallback
158+
# Handle timeout => use fallback
161159
rescue APIError => e
162-
#APIError is parent of both ResponseError and ApiTimeout
160+
# APIError is parent of both ResponseError and ApiTimeout
163161
end
164162
```

lib/recombee_api_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class RecombeeClient
1818
include HTTParty
1919

2020
BATCH_MAX_SIZE = 10000
21-
USER_AGENT = {'User-Agent' => 'recombee-ruby-api-client/1.6.0'}
21+
USER_AGENT = {'User-Agent' => 'recombee-ruby-api-client/2.0.0'}
2222

2323
##
2424
# - +account+ -> Name of your account at Recombee

lib/recombee_api_client/api/item_based_recommendation.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module RecombeeApiClient
77
require_relative '../errors'
88

99
##
10+
#Deprecated since version 2.0.0. Use RecommendItemsToItem request instead.
11+
#
1012
#Recommends set of items that are somehow related to one given item, *X*. Typical scenario for using item-based recommendation is when user *A* is viewing *X*. Then you may display items to the user that he might be also interested in. Item-recommendation request gives you Top-N such items, optionally taking the target user *A* into account.
1113
#
1214
# It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.

lib/recombee_api_client/api/recommend_items_to_item.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ module RecombeeApiClient
77
require_relative '../errors'
88

99
##
10-
#This feature is currently in beta.
11-
#
1210
#Recommends set of items that are somehow related to one given item, *X*. Typical scenario is when user *A* is viewing *X*. Then you may display items to the user that he might be also interested in. Recommend items to item request gives you Top-N such items, optionally taking the target user *A* into account.
1311
#
1412
#It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
@@ -34,8 +32,8 @@ class RecommendItemsToItem < ApiRequest
3432
#If you insist on not specifying the user, pass `null`
3533
#(`None`, `nil`, `NULL` etc. depending on language) to *targetUserId*.
3634
#Do not create some special dummy user for getting recommendations,
37-
#as it could cause mislead the recommendation models,
38-
#leading to wrong recommendations.
35+
#as it could mislead the recommendation models,
36+
#and result in wrong recommendations.
3937
#
4038
#For anonymous/unregistered users it is possible to use for example their session ID.
4139
#
@@ -53,7 +51,7 @@ class RecommendItemsToItem < ApiRequest
5351
#Example response:
5452
#```
5553
# {
56-
# "recommId": "8ac80708afe9148130528757ebf6aaba",
54+
# "recommId": "0c6189e7-dc1a-429a-b613-192696309361",
5755
# "recomms":
5856
# [
5957
# {
@@ -83,7 +81,7 @@ class RecommendItemsToItem < ApiRequest
8381
#Example response for `includedProperties=description,price`:
8482
#```
8583
# {
86-
# "recommId": "c7dbfc503d262b80b77b4949ee9855fb",
84+
# "recommId": "6842c725-a79f-4537-a02c-f34d668a3f80",
8785
# "recomms":
8886
# [
8987
# {

lib/recombee_api_client/api/recommend_items_to_user.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ module RecombeeApiClient
77
require_relative '../errors'
88

99
##
10-
#This feature is currently in beta.
11-
#
1210
#Based on user's past interactions (purchases, ratings, etc.) with the items, recommends top-N items that are most likely to be of high value for a given user.
1311
#
1412
#It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
@@ -33,7 +31,7 @@ class RecommendItemsToUser < ApiRequest
3331
#Example response:
3432
#```
3533
# {
36-
# "recommId": "1644e7b31759a08480da5f3b0a13045b",
34+
# "recommId": "ce52ada4-e4d9-4885-943c-407db2dee837",
3735
# "recomms":
3836
# [
3937
# {
@@ -63,7 +61,7 @@ class RecommendItemsToUser < ApiRequest
6361
#Example response for `includedProperties=description,price`:
6462
#```
6563
# {
66-
# "recommId": "e3ba43af1a4e59dd08a00adced1729a7",
64+
# "recommId": "a86ee8d5-cd8e-46d1-886c-8b3771d0520b",
6765
# "recomms":
6866
# [
6967
# {

lib/recombee_api_client/api/recommend_users_to_item.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ module RecombeeApiClient
77
require_relative '../errors'
88

99
##
10-
#This feature is currently in beta.
11-
#
1210
#Recommend users that are likely to be interested in a given item.
1311
#
1412
#It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
@@ -33,7 +31,7 @@ class RecommendUsersToItem < ApiRequest
3331
#Example response:
3432
#```
3533
# {
36-
# "recommId": "9eeebc318508302529e3241f4570834d",
34+
# "recommId": "039b71dc-b9cc-4645-a84f-62b841eecfce",
3735
# "recomms":
3836
# [
3937
# {
@@ -59,7 +57,7 @@ class RecommendUsersToItem < ApiRequest
5957
#Example response for `includedProperties=country`:
6058
#```
6159
# {
62-
# "recommId": "d4c826635efc3e01a83470008c5697f1",
60+
# "recommId": "b2b355dd-972a-4728-9c6b-2dc229db0678",
6361
# "recomms":
6462
# [
6563
# {
@@ -95,7 +93,7 @@ def initialize(item_id, count, optional = {})
9593
@diversity = optional['diversity']
9694
@expert_settings = optional['expertSettings']
9795
@optional = optional
98-
@timeout = 3000
96+
@timeout = 50000
9997
@ensure_https = false
10098
@optional.each do |par, _|
10199
fail UnknownOptionalParameter.new(par) unless ["filter","booster","cascadeCreate","scenario","returnProperties","includedProperties","diversity","expertSettings"].include? par

lib/recombee_api_client/api/recommend_users_to_user.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ module RecombeeApiClient
77
require_relative '../errors'
88

99
##
10-
#This feature is currently in beta.
11-
#
1210
#Get similar users as some given user, based on the user's past interactions (purchases, ratings, etc.) and values of properties.
1311
#
1412
#It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
@@ -33,7 +31,7 @@ class RecommendUsersToUser < ApiRequest
3331
#Example response:
3432
#```
3533
# {
36-
# "recommId": "32fc671480eb29d843e47def43503992",
34+
# "recommId": "9cb9c55d-50ba-4478-84fd-ab456136156e",
3735
# "recomms":
3836
# [
3937
# {
@@ -59,7 +57,7 @@ class RecommendUsersToUser < ApiRequest
5957
#Example response for `includedProperties=country`:
6058
#```
6159
# {
62-
# "recommId": "27d81ade643621f45cc6ba5d30d7d683",
60+
# "recommId": "b326d82d-5d57-4b45-b362-c9d6f0895855",
6361
# "recomms":
6462
# [
6563
# {
@@ -104,7 +102,7 @@ def initialize(user_id, count, optional = {})
104102
@rotation_time = optional['rotationTime']
105103
@expert_settings = optional['expertSettings']
106104
@optional = optional
107-
@timeout = 3000
105+
@timeout = 50000
108106
@ensure_https = false
109107
@optional.each do |par, _|
110108
fail UnknownOptionalParameter.new(par) unless ["filter","booster","cascadeCreate","scenario","returnProperties","includedProperties","diversity","minRelevance","rotationRate","rotationTime","expertSettings"].include? par

lib/recombee_api_client/api/user_based_recommendation.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module RecombeeApiClient
77
require_relative '../errors'
88

99
##
10+
#Deprecated since version 2.0.0. Use RecommendItemsToUser request instead.
11+
#
1012
#Based on user's past interactions (purchases, ratings, etc.) with the items, recommends top-N items that are most likely to be of high value for a given user.
1113
#
1214
#It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.

lib/recombee_api_client/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module RecombeeApiClient
2-
VERSION = '1.6.0'
2+
VERSION = '2.0.0'
33
end

spec/api/add_entity.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
end
1414

1515
it 'fails with invalid entity id' do
16-
req = described_class.new('...not_valid...')
16+
req = described_class.new('$$$not_valid$$$')
1717
expect { @client.send(req) }.to raise_exception { |exception|
1818
expect(exception).to be_a(RecombeeApiClient::ResponseError)
1919
expect(exception.status_code).to eq 400

0 commit comments

Comments
 (0)