Skip to content

Commit e355fac

Browse files
committed
Release: v6.1.0
- Added support for `reqlExpressions` on recommended item segments
1 parent 8a90cf8 commit e355fac

File tree

7 files changed

+169
-13
lines changed

7 files changed

+169
-13
lines changed

lib/recombee_api_client.rb

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

2121
BATCH_MAX_SIZE = 10_000
22-
USER_AGENT = { 'User-Agent' => 'recombee-ruby-api-client/6.0.0' }
22+
USER_AGENT = { 'User-Agent' => 'recombee-ruby-api-client/6.1.0' }
2323

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

lib/recombee_api_client/api/recommend_item_segments_to_item.rb

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module RecombeeApiClient
2424
#
2525
class RecommendItemSegmentsToItem < ApiRequest
2626
attr_reader :item_id, :target_user_id, :count, :scenario, :cascade_create, :filter, :booster, :logic,
27-
:expert_settings, :return_ab_group
27+
:expert_settings, :return_ab_group, :reql_expressions
2828
attr_accessor :timeout, :ensure_https
2929

3030
##
@@ -75,6 +75,43 @@ class RecommendItemSegmentsToItem < ApiRequest
7575
#
7676
# - +returnAbGroup+ -> If there is a custom AB-testing running, return the name of the group to which the request belongs.
7777
#
78+
# - +reqlExpressions+ -> A dictionary of [ReQL](https://docs.recombee.com/reql) expressions that will be executed for each recommended Item Segment.
79+
# This can be used to compute additional properties of the recommended Item Segments.
80+
#
81+
# The keys are the names of the expressions, and the values are the actual ReQL expressions.
82+
#
83+
# Example request:
84+
# ```json
85+
# {
86+
# "reqlExpressions": {
87+
# "countItems": "size(segment_items(\"categories\", 'segmentId'))"
88+
# }
89+
# }
90+
# ```
91+
#
92+
# Example response:
93+
# ```json
94+
# {
95+
# "recommId": "a7ac55a4-8d6e-4f19-addc-abac4164d8a8",
96+
# "recomms":
97+
# [
98+
# {
99+
# "id": "category-fantasy-books",
100+
# "reqlEvaluations": {
101+
# "countItems": 486
102+
# }
103+
# },
104+
# {
105+
# "id": "category-sci-fi-costumes",
106+
# "reqlEvaluations": {
107+
# "countItems": 19
108+
# }
109+
# }
110+
# ],
111+
# "numberNextRecommsCalls": 0
112+
# }
113+
# ```
114+
#
78115
#
79116
def initialize(item_id, target_user_id, count, optional = {})
80117
@item_id = item_id
@@ -88,12 +125,13 @@ def initialize(item_id, target_user_id, count, optional = {})
88125
@logic = optional['logic']
89126
@expert_settings = optional['expertSettings']
90127
@return_ab_group = optional['returnAbGroup']
128+
@reql_expressions = optional['reqlExpressions']
91129
@optional = optional
92130
@timeout = 3000
93131
@ensure_https = false
94132
@optional.each do |par, _|
95133
raise UnknownOptionalParameter.new(par) unless %w[scenario cascadeCreate filter booster logic
96-
expertSettings returnAbGroup].include? par
134+
expertSettings returnAbGroup reqlExpressions].include? par
97135
end
98136
end
99137

@@ -114,6 +152,7 @@ def body_parameters
114152
p['logic'] = @optional['logic'] if @optional.include? 'logic'
115153
p['expertSettings'] = @optional['expertSettings'] if @optional.include? 'expertSettings'
116154
p['returnAbGroup'] = @optional['returnAbGroup'] if @optional.include? 'returnAbGroup'
155+
p['reqlExpressions'] = @optional['reqlExpressions'] if @optional.include? 'reqlExpressions'
117156

118157
p
119158
end

lib/recombee_api_client/api/recommend_item_segments_to_item_segment.rb

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module RecombeeApiClient
2323
#
2424
class RecommendItemSegmentsToItemSegment < ApiRequest
2525
attr_reader :context_segment_id, :target_user_id, :count, :scenario, :cascade_create, :filter, :booster, :logic,
26-
:expert_settings, :return_ab_group
26+
:expert_settings, :return_ab_group, :reql_expressions
2727
attr_accessor :timeout, :ensure_https
2828

2929
##
@@ -74,6 +74,43 @@ class RecommendItemSegmentsToItemSegment < ApiRequest
7474
#
7575
# - +returnAbGroup+ -> If there is a custom AB-testing running, return the name of the group to which the request belongs.
7676
#
77+
# - +reqlExpressions+ -> A dictionary of [ReQL](https://docs.recombee.com/reql) expressions that will be executed for each recommended Item Segment.
78+
# This can be used to compute additional properties of the recommended Item Segments.
79+
#
80+
# The keys are the names of the expressions, and the values are the actual ReQL expressions.
81+
#
82+
# Example request:
83+
# ```json
84+
# {
85+
# "reqlExpressions": {
86+
# "countItems": "size(segment_items(\"categories\", 'segmentId'))"
87+
# }
88+
# }
89+
# ```
90+
#
91+
# Example response:
92+
# ```json
93+
# {
94+
# "recommId": "a7ac55a4-8d6e-4f19-addc-abac4164d8a8",
95+
# "recomms":
96+
# [
97+
# {
98+
# "id": "category-fantasy-books",
99+
# "reqlEvaluations": {
100+
# "countItems": 486
101+
# }
102+
# },
103+
# {
104+
# "id": "category-sci-fi-costumes",
105+
# "reqlEvaluations": {
106+
# "countItems": 19
107+
# }
108+
# }
109+
# ],
110+
# "numberNextRecommsCalls": 0
111+
# }
112+
# ```
113+
#
77114
#
78115
def initialize(context_segment_id, target_user_id, count, optional = {})
79116
@context_segment_id = context_segment_id
@@ -87,12 +124,13 @@ def initialize(context_segment_id, target_user_id, count, optional = {})
87124
@logic = optional['logic']
88125
@expert_settings = optional['expertSettings']
89126
@return_ab_group = optional['returnAbGroup']
127+
@reql_expressions = optional['reqlExpressions']
90128
@optional = optional
91129
@timeout = 3000
92130
@ensure_https = false
93131
@optional.each do |par, _|
94132
raise UnknownOptionalParameter.new(par) unless %w[scenario cascadeCreate filter booster logic
95-
expertSettings returnAbGroup].include? par
133+
expertSettings returnAbGroup reqlExpressions].include? par
96134
end
97135
end
98136

@@ -114,6 +152,7 @@ def body_parameters
114152
p['logic'] = @optional['logic'] if @optional.include? 'logic'
115153
p['expertSettings'] = @optional['expertSettings'] if @optional.include? 'expertSettings'
116154
p['returnAbGroup'] = @optional['returnAbGroup'] if @optional.include? 'returnAbGroup'
155+
p['reqlExpressions'] = @optional['reqlExpressions'] if @optional.include? 'reqlExpressions'
117156

118157
p
119158
end

lib/recombee_api_client/api/recommend_item_segments_to_user.rb

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module RecombeeApiClient
2424
#
2525
class RecommendItemSegmentsToUser < ApiRequest
2626
attr_reader :user_id, :count, :scenario, :cascade_create, :filter, :booster, :logic, :expert_settings,
27-
:return_ab_group
27+
:return_ab_group, :reql_expressions
2828
attr_accessor :timeout, :ensure_https
2929

3030
##
@@ -57,6 +57,43 @@ class RecommendItemSegmentsToUser < ApiRequest
5757
#
5858
# - +returnAbGroup+ -> If there is a custom AB-testing running, return the name of the group to which the request belongs.
5959
#
60+
# - +reqlExpressions+ -> A dictionary of [ReQL](https://docs.recombee.com/reql) expressions that will be executed for each recommended Item Segment.
61+
# This can be used to compute additional properties of the recommended Item Segments.
62+
#
63+
# The keys are the names of the expressions, and the values are the actual ReQL expressions.
64+
#
65+
# Example request:
66+
# ```json
67+
# {
68+
# "reqlExpressions": {
69+
# "countItems": "size(segment_items(\"categories\", 'segmentId'))"
70+
# }
71+
# }
72+
# ```
73+
#
74+
# Example response:
75+
# ```json
76+
# {
77+
# "recommId": "a7ac55a4-8d6e-4f19-addc-abac4164d8a8",
78+
# "recomms":
79+
# [
80+
# {
81+
# "id": "category-fantasy-books",
82+
# "reqlEvaluations": {
83+
# "countItems": 486
84+
# }
85+
# },
86+
# {
87+
# "id": "category-sci-fi-costumes",
88+
# "reqlEvaluations": {
89+
# "countItems": 19
90+
# }
91+
# }
92+
# ],
93+
# "numberNextRecommsCalls": 0
94+
# }
95+
# ```
96+
#
6097
#
6198
def initialize(user_id, count, optional = {})
6299
@user_id = user_id
@@ -69,12 +106,13 @@ def initialize(user_id, count, optional = {})
69106
@logic = optional['logic']
70107
@expert_settings = optional['expertSettings']
71108
@return_ab_group = optional['returnAbGroup']
109+
@reql_expressions = optional['reqlExpressions']
72110
@optional = optional
73111
@timeout = 3000
74112
@ensure_https = false
75113
@optional.each do |par, _|
76114
raise UnknownOptionalParameter.new(par) unless %w[scenario cascadeCreate filter booster logic
77-
expertSettings returnAbGroup].include? par
115+
expertSettings returnAbGroup reqlExpressions].include? par
78116
end
79117
end
80118

@@ -94,6 +132,7 @@ def body_parameters
94132
p['logic'] = @optional['logic'] if @optional.include? 'logic'
95133
p['expertSettings'] = @optional['expertSettings'] if @optional.include? 'expertSettings'
96134
p['returnAbGroup'] = @optional['returnAbGroup'] if @optional.include? 'returnAbGroup'
135+
p['reqlExpressions'] = @optional['reqlExpressions'] if @optional.include? 'reqlExpressions'
97136

98137
p
99138
end

lib/recombee_api_client/api/search_item_segments.rb

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module RecombeeApiClient
2424
#
2525
class SearchItemSegments < ApiRequest
2626
attr_reader :user_id, :search_query, :count, :scenario, :cascade_create, :filter, :booster, :logic,
27-
:expert_settings, :return_ab_group
27+
:expert_settings, :return_ab_group, :reql_expressions
2828
attr_accessor :timeout, :ensure_https
2929

3030
##
@@ -57,6 +57,43 @@ class SearchItemSegments < ApiRequest
5757
#
5858
# - +returnAbGroup+ -> If there is a custom AB-testing running, return the name of the group to which the request belongs.
5959
#
60+
# - +reqlExpressions+ -> A dictionary of [ReQL](https://docs.recombee.com/reql) expressions that will be executed for each recommended Item Segment.
61+
# This can be used to compute additional properties of the recommended Item Segments.
62+
#
63+
# The keys are the names of the expressions, and the values are the actual ReQL expressions.
64+
#
65+
# Example request:
66+
# ```json
67+
# {
68+
# "reqlExpressions": {
69+
# "countItems": "size(segment_items(\"categories\", 'segmentId'))"
70+
# }
71+
# }
72+
# ```
73+
#
74+
# Example response:
75+
# ```json
76+
# {
77+
# "recommId": "a7ac55a4-8d6e-4f19-addc-abac4164d8a8",
78+
# "recomms":
79+
# [
80+
# {
81+
# "id": "category-fantasy-books",
82+
# "reqlEvaluations": {
83+
# "countItems": 486
84+
# }
85+
# },
86+
# {
87+
# "id": "category-sci-fi-costumes",
88+
# "reqlEvaluations": {
89+
# "countItems": 19
90+
# }
91+
# }
92+
# ],
93+
# "numberNextRecommsCalls": 0
94+
# }
95+
# ```
96+
#
6097
#
6198
def initialize(user_id, search_query, count, optional = {})
6299
@user_id = user_id
@@ -70,12 +107,13 @@ def initialize(user_id, search_query, count, optional = {})
70107
@logic = optional['logic']
71108
@expert_settings = optional['expertSettings']
72109
@return_ab_group = optional['returnAbGroup']
110+
@reql_expressions = optional['reqlExpressions']
73111
@optional = optional
74112
@timeout = 3000
75113
@ensure_https = false
76114
@optional.each do |par, _|
77115
raise UnknownOptionalParameter.new(par) unless %w[scenario cascadeCreate filter booster logic
78-
expertSettings returnAbGroup].include? par
116+
expertSettings returnAbGroup reqlExpressions].include? par
79117
end
80118
end
81119

@@ -96,6 +134,7 @@ def body_parameters
96134
p['logic'] = @optional['logic'] if @optional.include? 'logic'
97135
p['expertSettings'] = @optional['expertSettings'] if @optional.include? 'expertSettings'
98136
p['returnAbGroup'] = @optional['returnAbGroup'] if @optional.include? 'returnAbGroup'
137+
p['reqlExpressions'] = @optional['reqlExpressions'] if @optional.include? 'reqlExpressions'
99138

100139
p
101140
end

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 = '6.0.0'
2+
VERSION = '6.1.0'
33
end

spec/api/batch_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
ListItems.new('filter' => "'num' >= 99"),
2626
AddCartAddition.new('user', 'item2'),
2727
AddCartAddition.new('user', 'item2', 'cascadeCreate' => true),
28-
RecommendItemsToUser.new('user_id', 25, filter: "'num'==68", cascade_create: True)
28+
RecommendItemsToUser.new('user_id', 25, filter: "'num'==68", cascade_create: true)
2929
]
3030
repl = @client.send(Batch.new(reqs))
3131

3232
codes = repl.map { |r| r['code'] }
33-
expect(codes).to match_array [200, 201, 201, 200, 409, 200, 200, 200, 200, 200, 404, 200]
34-
expect(repl[12]['json']['recomms'][0].sort).to match_array ['item2']
33+
expect(codes).to match_array [200, 201, 201, 200, 409, 200, 200, 200, 200, 200, 404, 200, 200]
34+
expect(repl[12]['json']['recomms'][0]['id']).to eq 'item2'
3535
end
3636

3737
it 'send large multi-part batch' do

0 commit comments

Comments
 (0)