recombee_api_client 2.2.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 891734600f45e2e25c9a44617f0e2ce033b6e90c
4
- data.tar.gz: 6aca79bfa8720f2187f14ec117a60b02a4e18995
2
+ SHA256:
3
+ metadata.gz: 993911797068c239b3eb1ed0bff4f115049a3a7c5c25cc10ee2e7606fabaecc5
4
+ data.tar.gz: 9759c4ad279ea317cbdf0d6b3ac93eee89761010b1d8aded8cdd946f9dc0e793
5
5
  SHA512:
6
- metadata.gz: bc1533bd22417f9ddb1fae6ce533e623854d425b966a72d98f2d994796c3aa909e73ef1a3a5cebb92cabd2397f2e7477f2c09765b8e1dfa498a0e9256da9cd73
7
- data.tar.gz: 5a8c325f7bce984ac02e397d9a16dfd21b132178ec836e7dddd509f7ef242c86cc61dc7b5fdabe06239f36e0813682e102d3cd92279e88dd8bd8fb6424799cea
6
+ metadata.gz: 7a5cccd32d72f4ec654b3ffc9c8f9d0f50e90618b104afc7618e24cf40f0ad9ceaf14b18031d7e8c4ef1ac05027a7857a592e3fc18fded5a7a2f1b27b80f9225
7
+ data.tar.gz: 8a68e11edd23890854ec6248994d77e4f494fd19b881d798eb7f916b0823b77987695ad0c439594fdadc82c7f229cda3128ce6d3dfecdd17162e38654d1f3200
data/README.md CHANGED
@@ -29,7 +29,7 @@ Or install it yourself as:
29
29
  require 'recombee_api_client'
30
30
  include RecombeeApiClient
31
31
 
32
- client = RecombeeClient('--my-database-id--', '--my-secret-token--')
32
+ client = RecombeeClient('--my-database-id--', '--db-private-token--')
33
33
 
34
34
  # Generate some random purchases of items by users
35
35
  NUM = 100
@@ -55,8 +55,13 @@ begin
55
55
  client.send(Batch.new(purchases))
56
56
 
57
57
  # Get recommendations for user 'user-25'
58
- recommended = client.send(RecommendItemsToUser.new('user-25', 5))
59
- puts "Recommended items for user-25: #{recommended}"
58
+ response = client.send(RecommendItemsToUser.new('user-25', 5))
59
+ puts "Recommended items for user-25: #{response}"
60
+
61
+ # User scrolled down - get next 3 recommended items
62
+ response = client.send(RecommendNextItems.new(response['recommId'], 3))
63
+ puts "Next recommended items for user-25: #{response}"
64
+
60
65
  rescue APIError => e
61
66
  puts e
62
67
  # Use fallback
@@ -71,8 +76,8 @@ include RecombeeApiClient
71
76
  NUM = 100
72
77
  PROBABILITY_PURCHASED = 0.1
73
78
 
74
- client = RecombeeClient('--my-database-id--', '--my-secret-token--')
75
- client.send(ResetDatabase.new) # Clear everything from the database
79
+ client = RecombeeClient('--my-database-id--', '--db-private-token--')
80
+ client.send(ResetDatabase.new) # Clear everything from the database (asynchronous)
76
81
 
77
82
  # We will use computers as items in this example
78
83
  # Computers have five properties
@@ -103,7 +108,7 @@ requests = (1..NUM).map do |i|
103
108
  },
104
109
  #optional parameters:
105
110
  {
106
- 'cascadeCreate' => true # Use cascadeCreate for creating item
111
+ :cascade_create => true # Use cascade_create for creating item
107
112
  # with given itemId, if it doesn't exist
108
113
  }
109
114
  )
@@ -117,29 +122,38 @@ requests = []
117
122
  (1..NUM).map{|i| "computer-#{i}"}.each do |item_id|
118
123
  user_ids = (1..NUM).map{|i| "user-#{i}"}
119
124
  user_ids = user_ids.select { |_| rand(0.0..1.0) < PROBABILITY_PURCHASED }
120
- # Use cascadeCreate to create unexisting users
121
- user_ids.each { |user_id| requests.push(AddPurchase.new(user_id, item_id, 'cascadeCreate' => true)) }
125
+ # Use cascade_create to create unexisting users
126
+ user_ids.each { |user_id| requests.push(AddPurchase.new(user_id, item_id, :cascade_create => true)) }
122
127
  end
123
128
 
124
129
  # Send purchases to the recommender system
125
130
  client.send(Batch.new(requests))
126
131
 
127
132
  # Get 5 recommendations for user-42, who is currently viewing computer-6
128
- recommended = client.send(RecommendItemsToItem.new('computer-6', 'user-42', 5) )
129
- puts "Recommended items: #{recommended}"
130
-
131
133
  # Recommend only computers that have at least 3 cores
132
134
  recommended = client.send(
133
- RecommendItemsToItem.new('computer-6', 'user-42', 5, {'filter' => "'num-cores'>=3"})
135
+ RecommendItemsToItem.new('computer-6', 'user-42', 5, {:filter => "'num-cores'>=3"})
134
136
  )
135
137
  puts "Recommended items with at least 3 processor cores: #{recommended}"
136
138
 
137
- # Recommend only items thatare more expensive then currently viewed item (up-sell)
139
+ # Recommend only items that are more expensive then currently viewed item (up-sell)
138
140
  recommended = client.send(
139
141
  RecommendItemsToItem.new('computer-6', 'user-42', 5,
140
- {'filter' => "'price' > context_item[\"price\"]"})
142
+ {:filter => "'price' > context_item[\"price\"]"})
141
143
  )
142
144
  puts "Recommended up-sell items: #{recommended}"
145
+
146
+ # Filters, boosters and other settings can be also set in the Admin UI (admin.recombee.com)
147
+ # when scenario is specified
148
+ recommended = client.send(
149
+ RecommendItemsToItem.new('computer-6', 'user-42', 5, {:scenario => 'product_detail'})
150
+ )
151
+
152
+ # Perform personalized full-text search with a user's search query (e.g. 'computers').
153
+ matches = client.send(
154
+ SearchItems.new('user-42', 'computers', 5, {:scenario => 'search_top'})
155
+ )
156
+ puts "Matched items: #{matches}"
143
157
  ```
144
158
 
145
159
  ### Exception handling
@@ -18,13 +18,13 @@ module RecombeeApiClient
18
18
  include HTTParty
19
19
 
20
20
  BATCH_MAX_SIZE = 10000
21
- USER_AGENT = {'User-Agent' => 'recombee-ruby-api-client/2.2.0'}
21
+ USER_AGENT = {'User-Agent' => 'recombee-ruby-api-client/3.2.0'}
22
22
 
23
23
  ##
24
24
  # - +account+ -> Name of your account at Recombee
25
25
  # - +token+ -> Secret token obtained from Recombee for signing requests
26
26
  # - +protocol+ -> Default protocol for sending requests. Possible values: 'http', 'https'.
27
- def initialize(account, token, protocol = 'http', options = {})
27
+ def initialize(account, token, protocol = 'https', options = {})
28
28
  @account = account
29
29
  @token = token
30
30
  @protocol = protocol
@@ -10,7 +10,7 @@ module RecombeeApiClient
10
10
  #Adds a bookmark of a given item made by a given user.
11
11
  #
12
12
  class AddBookmark < ApiRequest
13
- attr_reader :user_id, :item_id, :timestamp, :cascade_create, :recomm_id
13
+ attr_reader :user_id, :item_id, :timestamp, :cascade_create, :recomm_id, :additional_data
14
14
  attr_accessor :timeout
15
15
  attr_accessor :ensure_https
16
16
 
@@ -23,6 +23,7 @@ module RecombeeApiClient
23
23
  # - +timestamp+ -> UTC timestamp of the bookmark as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
24
24
  # - +cascadeCreate+ -> Sets whether the given user/item should be created if not present in the database.
25
25
  # - +recommId+ -> If this bookmark is based on a recommendation request, `recommId` is the id of the clicked recommendation.
26
+ # - +additionalData+ -> A dictionary of additional data for the interaction.
26
27
  #
27
28
  def initialize(user_id, item_id, optional = {})
28
29
  @user_id = user_id
@@ -31,11 +32,12 @@ module RecombeeApiClient
31
32
  @timestamp = optional['timestamp']
32
33
  @cascade_create = optional['cascadeCreate']
33
34
  @recomm_id = optional['recommId']
35
+ @additional_data = optional['additionalData']
34
36
  @optional = optional
35
37
  @timeout = 1000
36
38
  @ensure_https = false
37
39
  @optional.each do |par, _|
38
- fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate","recommId"].include? par
40
+ fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate","recommId","additionalData"].include? par
39
41
  end
40
42
  end
41
43
 
@@ -52,6 +54,7 @@ module RecombeeApiClient
52
54
  p['timestamp'] = @optional['timestamp'] if @optional.include? 'timestamp'
53
55
  p['cascadeCreate'] = @optional['cascadeCreate'] if @optional.include? 'cascadeCreate'
54
56
  p['recommId'] = @optional['recommId'] if @optional.include? 'recommId'
57
+ p['additionalData'] = @optional['additionalData'] if @optional.include? 'additionalData'
55
58
  p
56
59
  end
57
60
 
@@ -10,7 +10,7 @@ module RecombeeApiClient
10
10
  #Adds a cart addition of a given item made by a given user.
11
11
  #
12
12
  class AddCartAddition < ApiRequest
13
- attr_reader :user_id, :item_id, :timestamp, :cascade_create, :amount, :price, :recomm_id
13
+ attr_reader :user_id, :item_id, :timestamp, :cascade_create, :amount, :price, :recomm_id, :additional_data
14
14
  attr_accessor :timeout
15
15
  attr_accessor :ensure_https
16
16
 
@@ -25,6 +25,7 @@ module RecombeeApiClient
25
25
  # - +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.
26
26
  # - +price+ -> Price of the added item. If `amount` is greater than 1, sum of prices of all the items should be given.
27
27
  # - +recommId+ -> If this cart addition is based on a recommendation request, `recommId` is the id of the clicked recommendation.
28
+ # - +additionalData+ -> A dictionary of additional data for the interaction.
28
29
  #
29
30
  def initialize(user_id, item_id, optional = {})
30
31
  @user_id = user_id
@@ -35,11 +36,12 @@ module RecombeeApiClient
35
36
  @amount = optional['amount']
36
37
  @price = optional['price']
37
38
  @recomm_id = optional['recommId']
39
+ @additional_data = optional['additionalData']
38
40
  @optional = optional
39
41
  @timeout = 1000
40
42
  @ensure_https = false
41
43
  @optional.each do |par, _|
42
- fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate","amount","price","recommId"].include? par
44
+ fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate","amount","price","recommId","additionalData"].include? par
43
45
  end
44
46
  end
45
47
 
@@ -58,6 +60,7 @@ module RecombeeApiClient
58
60
  p['amount'] = @optional['amount'] if @optional.include? 'amount'
59
61
  p['price'] = @optional['price'] if @optional.include? 'price'
60
62
  p['recommId'] = @optional['recommId'] if @optional.include? 'recommId'
63
+ p['additionalData'] = @optional['additionalData'] if @optional.include? 'additionalData'
61
64
  p
62
65
  end
63
66
 
@@ -10,7 +10,7 @@ module RecombeeApiClient
10
10
  #Adds a detail view of a given item made by a given user.
11
11
  #
12
12
  class AddDetailView < ApiRequest
13
- attr_reader :user_id, :item_id, :timestamp, :duration, :cascade_create, :recomm_id
13
+ attr_reader :user_id, :item_id, :timestamp, :duration, :cascade_create, :recomm_id, :additional_data
14
14
  attr_accessor :timeout
15
15
  attr_accessor :ensure_https
16
16
 
@@ -24,6 +24,7 @@ module RecombeeApiClient
24
24
  # - +duration+ -> Duration of the view
25
25
  # - +cascadeCreate+ -> Sets whether the given user/item should be created if not present in the database.
26
26
  # - +recommId+ -> If this detail view is based on a recommendation request, `recommId` is the id of the clicked recommendation.
27
+ # - +additionalData+ -> A dictionary of additional data for the interaction.
27
28
  #
28
29
  def initialize(user_id, item_id, optional = {})
29
30
  @user_id = user_id
@@ -33,11 +34,12 @@ module RecombeeApiClient
33
34
  @duration = optional['duration']
34
35
  @cascade_create = optional['cascadeCreate']
35
36
  @recomm_id = optional['recommId']
37
+ @additional_data = optional['additionalData']
36
38
  @optional = optional
37
39
  @timeout = 1000
38
40
  @ensure_https = false
39
41
  @optional.each do |par, _|
40
- fail UnknownOptionalParameter.new(par) unless ["timestamp","duration","cascadeCreate","recommId"].include? par
42
+ fail UnknownOptionalParameter.new(par) unless ["timestamp","duration","cascadeCreate","recommId","additionalData"].include? par
41
43
  end
42
44
  end
43
45
 
@@ -55,6 +57,7 @@ module RecombeeApiClient
55
57
  p['duration'] = @optional['duration'] if @optional.include? 'duration'
56
58
  p['cascadeCreate'] = @optional['cascadeCreate'] if @optional.include? 'cascadeCreate'
57
59
  p['recommId'] = @optional['recommId'] if @optional.include? 'recommId'
60
+ p['additionalData'] = @optional['additionalData'] if @optional.include? 'additionalData'
58
61
  p
59
62
  end
60
63
 
@@ -10,7 +10,7 @@ module RecombeeApiClient
10
10
  #Adds a purchase of a given item made by a given user.
11
11
  #
12
12
  class AddPurchase < ApiRequest
13
- attr_reader :user_id, :item_id, :timestamp, :cascade_create, :amount, :price, :profit, :recomm_id
13
+ attr_reader :user_id, :item_id, :timestamp, :cascade_create, :amount, :price, :profit, :recomm_id, :additional_data
14
14
  attr_accessor :timeout
15
15
  attr_accessor :ensure_https
16
16
 
@@ -26,6 +26,7 @@ module RecombeeApiClient
26
26
  # - +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.
27
27
  # - +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.
28
28
  # - +recommId+ -> If this purchase is based on a recommendation request, `recommId` is the id of the clicked recommendation.
29
+ # - +additionalData+ -> A dictionary of additional data for the interaction.
29
30
  #
30
31
  def initialize(user_id, item_id, optional = {})
31
32
  @user_id = user_id
@@ -37,11 +38,12 @@ module RecombeeApiClient
37
38
  @price = optional['price']
38
39
  @profit = optional['profit']
39
40
  @recomm_id = optional['recommId']
41
+ @additional_data = optional['additionalData']
40
42
  @optional = optional
41
43
  @timeout = 1000
42
44
  @ensure_https = false
43
45
  @optional.each do |par, _|
44
- fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate","amount","price","profit","recommId"].include? par
46
+ fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate","amount","price","profit","recommId","additionalData"].include? par
45
47
  end
46
48
  end
47
49
 
@@ -61,6 +63,7 @@ module RecombeeApiClient
61
63
  p['price'] = @optional['price'] if @optional.include? 'price'
62
64
  p['profit'] = @optional['profit'] if @optional.include? 'profit'
63
65
  p['recommId'] = @optional['recommId'] if @optional.include? 'recommId'
66
+ p['additionalData'] = @optional['additionalData'] if @optional.include? 'additionalData'
64
67
  p
65
68
  end
66
69
 
@@ -10,7 +10,7 @@ module RecombeeApiClient
10
10
  #Adds a rating of given item made by a given user.
11
11
  #
12
12
  class AddRating < ApiRequest
13
- attr_reader :user_id, :item_id, :timestamp, :rating, :cascade_create, :recomm_id
13
+ attr_reader :user_id, :item_id, :timestamp, :rating, :cascade_create, :recomm_id, :additional_data
14
14
  attr_accessor :timeout
15
15
  attr_accessor :ensure_https
16
16
 
@@ -24,6 +24,7 @@ module RecombeeApiClient
24
24
  # - +timestamp+ -> UTC timestamp of the rating as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
25
25
  # - +cascadeCreate+ -> Sets whether the given user/item should be created if not present in the database.
26
26
  # - +recommId+ -> If this rating is based on a recommendation request, `recommId` is the id of the clicked recommendation.
27
+ # - +additionalData+ -> A dictionary of additional data for the interaction.
27
28
  #
28
29
  def initialize(user_id, item_id, rating, optional = {})
29
30
  @user_id = user_id
@@ -33,11 +34,12 @@ module RecombeeApiClient
33
34
  @timestamp = optional['timestamp']
34
35
  @cascade_create = optional['cascadeCreate']
35
36
  @recomm_id = optional['recommId']
37
+ @additional_data = optional['additionalData']
36
38
  @optional = optional
37
39
  @timeout = 1000
38
40
  @ensure_https = false
39
41
  @optional.each do |par, _|
40
- fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate","recommId"].include? par
42
+ fail UnknownOptionalParameter.new(par) unless ["timestamp","cascadeCreate","recommId","additionalData"].include? par
41
43
  end
42
44
  end
43
45
 
@@ -55,6 +57,7 @@ module RecombeeApiClient
55
57
  p['timestamp'] = @optional['timestamp'] if @optional.include? 'timestamp'
56
58
  p['cascadeCreate'] = @optional['cascadeCreate'] if @optional.include? 'cascadeCreate'
57
59
  p['recommId'] = @optional['recommId'] if @optional.include? 'recommId'
60
+ p['additionalData'] = @optional['additionalData'] if @optional.include? 'additionalData'
58
61
  p
59
62
  end
60
63
 
@@ -0,0 +1,72 @@
1
+ #
2
+ # This file is auto-generated, do not edit
3
+ #
4
+
5
+ module RecombeeApiClient
6
+ require_relative 'request'
7
+ require_relative '../errors'
8
+
9
+ ##
10
+ #Adds a new synonym for the [Search items](https://docs.recombee.com/api.html#search-items).
11
+ #
12
+ #When the `term` is used in the search query, the `synonym` is also used for the full-text search.
13
+ #Unless `oneWay=true`, it works also in the opposite way (`synonym` -> `term`).
14
+ #
15
+ #An example of a synonym can be `science fiction` for the term `sci-fi`.
16
+ #
17
+ class AddSearchSynonym < ApiRequest
18
+ attr_reader :term, :synonym, :one_way
19
+ attr_accessor :timeout
20
+ attr_accessor :ensure_https
21
+
22
+ ##
23
+ # * *Required arguments*
24
+ # - +term+ -> A word to which the `synonym` is specified.
25
+ # - +synonym+ -> A word that should be considered equal to the `term` by the full-text search engine.
26
+ #
27
+ # * *Optional arguments (given as hash optional)*
28
+ # - +oneWay+ -> If set to `true`, only `term` -> `synonym` is considered. If set to `false`, also `synonym` -> `term` works.
29
+ #
30
+ #Default: `false`.
31
+ #
32
+ #
33
+ def initialize(term, synonym, optional = {})
34
+ @term = term
35
+ @synonym = synonym
36
+ optional = normalize_optional(optional)
37
+ @one_way = optional['oneWay']
38
+ @optional = optional
39
+ @timeout = 10000
40
+ @ensure_https = false
41
+ @optional.each do |par, _|
42
+ fail UnknownOptionalParameter.new(par) unless ["oneWay"].include? par
43
+ end
44
+ end
45
+
46
+ # HTTP method
47
+ def method
48
+ :post
49
+ end
50
+
51
+ # Values of body parameters as a Hash
52
+ def body_parameters
53
+ p = Hash.new
54
+ p['term'] = @term
55
+ p['synonym'] = @synonym
56
+ p['oneWay'] = @optional['oneWay'] if @optional.include? 'oneWay'
57
+ p
58
+ end
59
+
60
+ # Values of query parameters as a Hash.
61
+ # name of parameter => value of the parameter
62
+ def query_parameters
63
+ params = {}
64
+ params
65
+ end
66
+
67
+ # Relative path to the endpoint
68
+ def path
69
+ "/{databaseId}/synonyms/items/"
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,47 @@
1
+ #
2
+ # This file is auto-generated, do not edit
3
+ #
4
+
5
+ module RecombeeApiClient
6
+ require_relative 'request'
7
+ require_relative '../errors'
8
+
9
+ ##
10
+ #Deletes all synonyms defined in the database.
11
+ #
12
+ class DeleteAllSearchSynonyms < ApiRequest
13
+
14
+ attr_accessor :timeout
15
+ attr_accessor :ensure_https
16
+
17
+ ##
18
+ #
19
+ def initialize()
20
+ @timeout = 10000
21
+ @ensure_https = false
22
+ end
23
+
24
+ # HTTP method
25
+ def method
26
+ :delete
27
+ end
28
+
29
+ # Values of body parameters as a Hash
30
+ def body_parameters
31
+ p = Hash.new
32
+ p
33
+ end
34
+
35
+ # Values of query parameters as a Hash.
36
+ # name of parameter => value of the parameter
37
+ def query_parameters
38
+ params = {}
39
+ params
40
+ end
41
+
42
+ # Relative path to the endpoint
43
+ def path
44
+ "/{databaseId}/synonyms/items/"
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,50 @@
1
+ #
2
+ # This file is auto-generated, do not edit
3
+ #
4
+
5
+ module RecombeeApiClient
6
+ require_relative 'request'
7
+ require_relative '../errors'
8
+
9
+ ##
10
+ #Deletes synonym of given `id` and this synonym is no longer taken into account in the [Search items](https://docs.recombee.com/api.html#search-items).
11
+ #
12
+ class DeleteSearchSynonym < ApiRequest
13
+ attr_reader :id
14
+ attr_accessor :timeout
15
+ attr_accessor :ensure_https
16
+
17
+ ##
18
+ # * *Required arguments*
19
+ # - +id+ -> ID of the synonym that should be deleted.
20
+ #
21
+ def initialize(id)
22
+ @id = id
23
+ @timeout = 10000
24
+ @ensure_https = false
25
+ end
26
+
27
+ # HTTP method
28
+ def method
29
+ :delete
30
+ end
31
+
32
+ # Values of body parameters as a Hash
33
+ def body_parameters
34
+ p = Hash.new
35
+ p
36
+ end
37
+
38
+ # Values of query parameters as a Hash.
39
+ # name of parameter => value of the parameter
40
+ def query_parameters
41
+ params = {}
42
+ params
43
+ end
44
+
45
+ # Relative path to the endpoint
46
+ def path
47
+ "/{databaseId}/synonyms/items/#{@id}"
48
+ end
49
+ end
50
+ end