recombee_api_client 5.1.0 → 6.1.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 +4 -4
- data/lib/recombee_api_client/api/add_bookmark.rb +26 -26
- data/lib/recombee_api_client/api/add_cart_addition.rb +28 -28
- data/lib/recombee_api_client/api/add_detail_view.rb +32 -28
- data/lib/recombee_api_client/api/add_item.rb +15 -18
- data/lib/recombee_api_client/api/add_item_property.rb +34 -35
- data/lib/recombee_api_client/api/add_manual_reql_segment.rb +26 -27
- data/lib/recombee_api_client/api/add_purchase.rb +29 -29
- data/lib/recombee_api_client/api/add_rating.rb +27 -27
- data/lib/recombee_api_client/api/add_search_synonym.rb +29 -30
- data/lib/recombee_api_client/api/add_series.rb +20 -21
- data/lib/recombee_api_client/api/add_user.rb +14 -17
- data/lib/recombee_api_client/api/add_user_property.rb +30 -31
- data/lib/recombee_api_client/api/batch.rb +12 -16
- data/lib/recombee_api_client/api/composite_recommendation.rb +132 -0
- data/lib/recombee_api_client/api/create_auto_reql_segmentation.rb +29 -30
- data/lib/recombee_api_client/api/create_manual_reql_segmentation.rb +27 -28
- data/lib/recombee_api_client/api/create_property_based_segmentation.rb +30 -31
- data/lib/recombee_api_client/api/delete_all_search_synonyms.rb +15 -19
- data/lib/recombee_api_client/api/delete_bookmark.rb +21 -22
- data/lib/recombee_api_client/api/delete_cart_addition.rb +21 -22
- data/lib/recombee_api_client/api/delete_detail_view.rb +21 -22
- data/lib/recombee_api_client/api/delete_item.rb +16 -19
- data/lib/recombee_api_client/api/delete_item_property.rb +15 -18
- data/lib/recombee_api_client/api/delete_manual_reql_segment.rb +16 -19
- data/lib/recombee_api_client/api/delete_more_items.rb +18 -19
- data/lib/recombee_api_client/api/delete_purchase.rb +21 -22
- data/lib/recombee_api_client/api/delete_rating.rb +21 -22
- data/lib/recombee_api_client/api/delete_search_synonym.rb +15 -18
- data/lib/recombee_api_client/api/delete_segmentation.rb +15 -18
- data/lib/recombee_api_client/api/delete_series.rb +21 -22
- data/lib/recombee_api_client/api/delete_user.rb +15 -18
- data/lib/recombee_api_client/api/delete_user_property.rb +15 -18
- data/lib/recombee_api_client/api/delete_view_portion.rb +21 -22
- data/lib/recombee_api_client/api/get_item_property_info.rb +14 -17
- data/lib/recombee_api_client/api/get_item_values.rb +15 -18
- data/lib/recombee_api_client/api/get_segmentation.rb +15 -18
- data/lib/recombee_api_client/api/get_user_property_info.rb +15 -18
- data/lib/recombee_api_client/api/get_user_values.rb +15 -18
- data/lib/recombee_api_client/api/insert_to_series.rb +23 -24
- data/lib/recombee_api_client/api/list_item_bookmarks.rb +16 -19
- data/lib/recombee_api_client/api/list_item_cart_additions.rb +16 -19
- data/lib/recombee_api_client/api/list_item_detail_views.rb +16 -19
- data/lib/recombee_api_client/api/list_item_properties.rb +15 -19
- data/lib/recombee_api_client/api/list_item_purchases.rb +16 -19
- data/lib/recombee_api_client/api/list_item_ratings.rb +16 -19
- data/lib/recombee_api_client/api/list_item_view_portions.rb +16 -19
- data/lib/recombee_api_client/api/list_items.rb +62 -62
- data/lib/recombee_api_client/api/list_scenarios.rb +15 -19
- data/lib/recombee_api_client/api/list_search_synonyms.rb +20 -21
- data/lib/recombee_api_client/api/list_segmentations.rb +16 -17
- data/lib/recombee_api_client/api/list_series.rb +15 -19
- data/lib/recombee_api_client/api/list_series_items.rb +15 -18
- data/lib/recombee_api_client/api/list_user_bookmarks.rb +15 -18
- data/lib/recombee_api_client/api/list_user_cart_additions.rb +15 -18
- data/lib/recombee_api_client/api/list_user_detail_views.rb +15 -18
- data/lib/recombee_api_client/api/list_user_properties.rb +15 -19
- data/lib/recombee_api_client/api/list_user_purchases.rb +15 -18
- data/lib/recombee_api_client/api/list_user_ratings.rb +15 -18
- data/lib/recombee_api_client/api/list_user_view_portions.rb +15 -18
- data/lib/recombee_api_client/api/list_users.rb +56 -56
- data/lib/recombee_api_client/api/merge_users.rb +24 -25
- data/lib/recombee_api_client/api/recommend_item_segments_to_item.rb +108 -68
- data/lib/recombee_api_client/api/recommend_item_segments_to_item_segment.rb +109 -69
- data/lib/recombee_api_client/api/recommend_item_segments_to_user.rb +90 -50
- data/lib/recombee_api_client/api/recommend_items_to_item.rb +185 -139
- data/lib/recombee_api_client/api/recommend_items_to_item_segment.rb +181 -138
- data/lib/recombee_api_client/api/recommend_items_to_user.rb +165 -122
- data/lib/recombee_api_client/api/recommend_next_items.rb +24 -25
- data/lib/recombee_api_client/api/recommend_users_to_item.rb +151 -105
- data/lib/recombee_api_client/api/recommend_users_to_user.rb +154 -111
- data/lib/recombee_api_client/api/remove_from_series.rb +17 -18
- data/lib/recombee_api_client/api/request.rb +1 -1
- data/lib/recombee_api_client/api/reset_database.rb +15 -19
- data/lib/recombee_api_client/api/search_item_segments.rb +91 -51
- data/lib/recombee_api_client/api/search_items.rb +157 -114
- data/lib/recombee_api_client/api/set_item_values.rb +28 -29
- data/lib/recombee_api_client/api/set_user_values.rb +21 -22
- data/lib/recombee_api_client/api/set_values.rb +28 -28
- data/lib/recombee_api_client/api/set_view_portion.rb +37 -30
- data/lib/recombee_api_client/api/update_auto_reql_segmentation.rb +26 -27
- data/lib/recombee_api_client/api/update_manual_reql_segment.rb +25 -26
- data/lib/recombee_api_client/api/update_manual_reql_segmentation.rb +24 -25
- data/lib/recombee_api_client/api/update_more_items.rb +19 -20
- data/lib/recombee_api_client/api/update_property_based_segmentation.rb +26 -27
- data/lib/recombee_api_client/errors.rb +2 -5
- data/lib/recombee_api_client/inputs/composite_recommendation_stage_parameters.rb +240 -0
- data/lib/recombee_api_client/inputs/input.rb +9 -0
- data/lib/recombee_api_client/inputs/logic.rb +45 -0
- data/lib/recombee_api_client/utils/hash_normalizer.rb +21 -0
- data/lib/recombee_api_client/version.rb +1 -1
- data/lib/recombee_api_client.rb +40 -35
- data/recombee_api_client.gemspec +2 -3
- metadata +14 -10
- data/lib/recombee_api_client/api/hash_normalizer.rb +0 -21
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
#
|
|
2
|
+
# This file is auto-generated, do not edit
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
require 'json'
|
|
6
|
+
|
|
7
|
+
module RecombeeApiClient
|
|
8
|
+
require_relative 'input'
|
|
9
|
+
require_relative '../errors'
|
|
10
|
+
|
|
11
|
+
##
|
|
12
|
+
# Initializes CompositeRecommendationStageParameters input#
|
|
13
|
+
class CompositeRecommendationStageParameters < Input
|
|
14
|
+
attr_reader :return_properties, :included_properties, :filter, :booster, :logic, :reql_expressions, :min_relevance,
|
|
15
|
+
:rotation_rate, :rotation_time
|
|
16
|
+
|
|
17
|
+
##
|
|
18
|
+
#
|
|
19
|
+
# * *Optional arguments (given as hash optional)*
|
|
20
|
+
# - +returnProperties+ -> With `returnProperties=true`, property values of the recommended items are returned along with their IDs in a JSON dictionary. The acquired property values can be used to easily display the recommended items to the user.
|
|
21
|
+
#
|
|
22
|
+
# Example response with `returnProperties` set in the `resultSettings`:
|
|
23
|
+
# ```json
|
|
24
|
+
# {
|
|
25
|
+
# "recommId": "ee94fa8b-efe7-4b35-abc6-2bc3456d66ed",
|
|
26
|
+
# "source": {
|
|
27
|
+
# "id": "category-sport"
|
|
28
|
+
# },
|
|
29
|
+
# "recomms": [
|
|
30
|
+
# {
|
|
31
|
+
# "id": "article-1024",
|
|
32
|
+
# "values": {
|
|
33
|
+
# "title": "Champions League: Stunning Comeback Secures Final Spot",
|
|
34
|
+
# "categories": ["Sport", "Football"],
|
|
35
|
+
# "author": "Jane Smith",
|
|
36
|
+
# "url": "newsportal.com/articles/champions-league-comeback"
|
|
37
|
+
# }
|
|
38
|
+
# },
|
|
39
|
+
# {
|
|
40
|
+
# "id": "article-2031",
|
|
41
|
+
# "values": {
|
|
42
|
+
# "title": "Top 10 Moments from the Summer Olympics",
|
|
43
|
+
# "categories": ["Sport", "Olympics"],
|
|
44
|
+
# "author": "Mark Johnson",
|
|
45
|
+
# "url": "newsportal.com/articles/olympic-top-moments"
|
|
46
|
+
# }
|
|
47
|
+
# },
|
|
48
|
+
# {
|
|
49
|
+
# "id": "article-3042",
|
|
50
|
+
# "values": {
|
|
51
|
+
# "title": "Rising Stars in Women's Tennis to Watch This Season",
|
|
52
|
+
# "categories": ["Sport", "Tennis"],
|
|
53
|
+
# "author": "Laura Chen",
|
|
54
|
+
# "url": "newsportal.com/articles/womens-tennis-stars"
|
|
55
|
+
# }
|
|
56
|
+
# }
|
|
57
|
+
# ],
|
|
58
|
+
# "numberNextRecommsCalls": 0
|
|
59
|
+
# }
|
|
60
|
+
#
|
|
61
|
+
# ```
|
|
62
|
+
#
|
|
63
|
+
# - +includedProperties+ -> Allows specifying which properties should be returned when `returnProperties=true` is set. The properties are given as a comma-separated list.
|
|
64
|
+
#
|
|
65
|
+
# Example response for `returnProperties=true` and `includedProperties=title,url` set in `resultSettings`:
|
|
66
|
+
# ```json
|
|
67
|
+
# {
|
|
68
|
+
# "recommId": "ee94fa8b-efe7-4b35-abc6-2bc3456d66ed",
|
|
69
|
+
# "source": {
|
|
70
|
+
# "id": "category-sport"
|
|
71
|
+
# },
|
|
72
|
+
# "recomms": [
|
|
73
|
+
# {
|
|
74
|
+
# "id": "article-1024",
|
|
75
|
+
# "values": {
|
|
76
|
+
# "title": "Champions League: Stunning Comeback Secures Final Spot",
|
|
77
|
+
# "url": "newsportal.com/articles/champions-league-comeback"
|
|
78
|
+
# }
|
|
79
|
+
# },
|
|
80
|
+
# {
|
|
81
|
+
# "id": "article-2031",
|
|
82
|
+
# "values": {
|
|
83
|
+
# "title": "Top 10 Moments from the Summer Olympics",
|
|
84
|
+
# "url": "newsportal.com/articles/olympic-top-moments"
|
|
85
|
+
# }
|
|
86
|
+
# },
|
|
87
|
+
# {
|
|
88
|
+
# "id": "article-3042",
|
|
89
|
+
# "values": {
|
|
90
|
+
# "title": "Rising Stars in Women's Tennis to Watch This Season",
|
|
91
|
+
# "url": "newsportal.com/articles/womens-tennis-stars"
|
|
92
|
+
# }
|
|
93
|
+
# }
|
|
94
|
+
# ],
|
|
95
|
+
# "numberNextRecommsCalls": 0
|
|
96
|
+
# }
|
|
97
|
+
#
|
|
98
|
+
# ```
|
|
99
|
+
#
|
|
100
|
+
# - +filter+ -> Boolean-returning [ReQL](https://docs.recombee.com/reql) expression, which allows you to filter recommended entities based on the values of their attributes.
|
|
101
|
+
#
|
|
102
|
+
# Filters can also be assigned to a [scenario](https://docs.recombee.com/scenarios) in the [Admin UI](https://admin.recombee.com).
|
|
103
|
+
#
|
|
104
|
+
# - +booster+ -> Number-returning [ReQL](https://docs.recombee.com/reql) expression, which allows you to boost the recommendation rate of some entities based on the values of their attributes.
|
|
105
|
+
#
|
|
106
|
+
# Boosters can also be assigned to a [scenario](https://docs.recombee.com/scenarios) in the [Admin UI](https://admin.recombee.com).
|
|
107
|
+
#
|
|
108
|
+
# - +logic+ -> Logic specifies the particular behavior of the recommendation models. You can pick tailored logic for your domain and use case.
|
|
109
|
+
# See [this section](https://docs.recombee.com/recommendation_logics) for a list of available logics and other details.
|
|
110
|
+
#
|
|
111
|
+
# The difference between `logic` and `scenario` is that `logic` specifies mainly behavior, while `scenario` specifies the place where recommendations are shown to the users.
|
|
112
|
+
#
|
|
113
|
+
# Logic can also be set to a [scenario](https://docs.recombee.com/scenarios) in the [Admin UI](https://admin.recombee.com).
|
|
114
|
+
#
|
|
115
|
+
# - +reqlExpressions+ -> Only usable if the stage corresponds to the one of these recommendation endpoints:
|
|
116
|
+
#
|
|
117
|
+
# - [Recommend Items To User](https://docs.recombee.com/api#recommend-items-to-user)
|
|
118
|
+
# - [Recommend Items To Item](https://docs.recombee.com/api#recommend-items-to-item)
|
|
119
|
+
# - [Recommend Items to Item Segment](https://docs.recombee.com/api#recommend-items-to-item-segment)
|
|
120
|
+
# - [Recommend Users to Item](https://docs.recombee.com/api#recommend-users-to-item)
|
|
121
|
+
# - [Recommend Users To User](https://docs.recombee.com/api#recommend-users-to-user)
|
|
122
|
+
#
|
|
123
|
+
# A dictionary of [ReQL](https://docs.recombee.com/reql) expressions that will be executed for each recommended item.
|
|
124
|
+
# This can be used to compute additional properties of the recommended items that are not stored in the database.
|
|
125
|
+
#
|
|
126
|
+
# The keys are the names of the expressions, and the values are the actual ReQL expressions.
|
|
127
|
+
#
|
|
128
|
+
# Example request:
|
|
129
|
+
# ```json
|
|
130
|
+
# {
|
|
131
|
+
# "reqlExpressions": {
|
|
132
|
+
# "isInUsersCity": "context_user[\"city\"] in 'cities'",
|
|
133
|
+
# "distanceToUser": "earth_distance('location', context_user[\"location\"])"
|
|
134
|
+
# }
|
|
135
|
+
# }
|
|
136
|
+
# ```
|
|
137
|
+
#
|
|
138
|
+
# Example response:
|
|
139
|
+
# ```json
|
|
140
|
+
# {
|
|
141
|
+
# "recommId": "ce52ada4-e4d9-4885-943c-407db2dee837",
|
|
142
|
+
# "source": {
|
|
143
|
+
# "id": "restaurant-123",
|
|
144
|
+
# "reqlEvaluations": {
|
|
145
|
+
# "isInUsersCity": true,
|
|
146
|
+
# "distanceToUser": 3450.5
|
|
147
|
+
# }
|
|
148
|
+
# },
|
|
149
|
+
# "recomms":
|
|
150
|
+
# [
|
|
151
|
+
# {
|
|
152
|
+
# "id": "restaurant-178",
|
|
153
|
+
# "reqlEvaluations": {
|
|
154
|
+
# "isInUsersCity": true,
|
|
155
|
+
# "distanceToUser": 5200.2
|
|
156
|
+
# }
|
|
157
|
+
# },
|
|
158
|
+
# {
|
|
159
|
+
# "id": "bar-42",
|
|
160
|
+
# "reqlEvaluations": {
|
|
161
|
+
# "isInUsersCity": false,
|
|
162
|
+
# "distanceToUser": 2516.0
|
|
163
|
+
# }
|
|
164
|
+
# }
|
|
165
|
+
# ],
|
|
166
|
+
# "numberNextRecommsCalls": 0
|
|
167
|
+
# }
|
|
168
|
+
# ```
|
|
169
|
+
#
|
|
170
|
+
# - +minRelevance+ -> **Expert option:** Only usable if the stage corresponds to the one of these recommendation endpoints:
|
|
171
|
+
#
|
|
172
|
+
# - [Recommend Items To User](https://docs.recombee.com/api#recommend-items-to-user)
|
|
173
|
+
# - [Recommend Items To Item](https://docs.recombee.com/api#recommend-items-to-item)
|
|
174
|
+
# - [Recommend Items to Item Segment](https://docs.recombee.com/api#recommend-items-to-item-segment)
|
|
175
|
+
#
|
|
176
|
+
# If the *userId* is provided: Specifies the threshold of how relevant must the recommended items be to the user.
|
|
177
|
+
#
|
|
178
|
+
# Possible values one of: `"low"`, `"medium"`, `"high"`.
|
|
179
|
+
#
|
|
180
|
+
# The default value is `"low"`, meaning that the system attempts to recommend a number of items equal to *count* at any cost. If there is not enough data (such as interactions or item properties), this may even lead to bestseller-based recommendations being appended to reach the full *count*.
|
|
181
|
+
# This behavior may be suppressed by using `"medium"` or `"high"` values. In such case, the system only recommends items of at least the requested relevance and may return less than *count* items when there is not enough data to fulfill it.
|
|
182
|
+
#
|
|
183
|
+
# - +rotationRate+ -> **Expert option:** Only usable if the stage corresponds to the one of these recommendation endpoints:
|
|
184
|
+
# - [Recommend Items To User](https://docs.recombee.com/api#recommend-items-to-user)
|
|
185
|
+
# - [Recommend Items To Item](https://docs.recombee.com/api#recommend-items-to-item)
|
|
186
|
+
# - [Recommend Items to Item Segment](https://docs.recombee.com/api#recommend-items-to-item-segment)
|
|
187
|
+
# - [Recommend Users To User](https://docs.recombee.com/api#recommend-users-to-user)
|
|
188
|
+
#
|
|
189
|
+
# If the *userId* is provided: If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per request in a backward fashion.
|
|
190
|
+
#
|
|
191
|
+
# You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example, `rotationRate=0.2` for only slight rotation of recommended items.
|
|
192
|
+
#
|
|
193
|
+
# - +rotationTime+ -> **Expert option:** Only usable if the stage corresponds to the one of these recommendation endpoints:
|
|
194
|
+
# - [Recommend Items To User](https://docs.recombee.com/api#recommend-items-to-user)
|
|
195
|
+
# - [Recommend Items To Item](https://docs.recombee.com/api#recommend-items-to-item)
|
|
196
|
+
# - [Recommend Items to Item Segment](https://docs.recombee.com/api#recommend-items-to-item-segment)
|
|
197
|
+
# - [Recommend Users To User](https://docs.recombee.com/api#recommend-users-to-user)
|
|
198
|
+
#
|
|
199
|
+
# If the *userId* is provided: Taking *rotationRate* into account, specifies how long it takes for an item to recover from the penalization. For example, `rotationTime=7200.0` means that items recommended less than 2 hours ago are penalized.
|
|
200
|
+
#
|
|
201
|
+
#
|
|
202
|
+
def initialize(optional = {})
|
|
203
|
+
optional = normalize_hash_to_camel_case(optional)
|
|
204
|
+
@return_properties = optional['returnProperties']
|
|
205
|
+
@included_properties = optional['includedProperties']
|
|
206
|
+
@filter = optional['filter']
|
|
207
|
+
@booster = optional['booster']
|
|
208
|
+
@logic = optional['logic']
|
|
209
|
+
@reql_expressions = optional['reqlExpressions']
|
|
210
|
+
@min_relevance = optional['minRelevance']
|
|
211
|
+
@rotation_rate = optional['rotationRate']
|
|
212
|
+
@rotation_time = optional['rotationTime']
|
|
213
|
+
@optional = optional
|
|
214
|
+
@optional.each do |par, _|
|
|
215
|
+
raise UnknownOptionalParameter.new(par) unless %w[returnProperties includedProperties filter booster
|
|
216
|
+
logic reqlExpressions minRelevance rotationRate rotationTime].include? par
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
# Return only JSON-serializable primitives.
|
|
221
|
+
def as_json(_options = {})
|
|
222
|
+
res = {}
|
|
223
|
+
res['returnProperties'] = @optional['returnProperties'] if @optional['returnProperties']
|
|
224
|
+
res['includedProperties'] = @optional['includedProperties'] if @optional['includedProperties']
|
|
225
|
+
res['filter'] = @optional['filter'] if @optional['filter']
|
|
226
|
+
res['booster'] = @optional['booster'] if @optional['booster']
|
|
227
|
+
res['logic'] = @optional['logic'] if @optional['logic']
|
|
228
|
+
res['reqlExpressions'] = @optional['reqlExpressions'] if @optional['reqlExpressions']
|
|
229
|
+
res['minRelevance'] = @optional['minRelevance'] if @optional['minRelevance']
|
|
230
|
+
res['rotationRate'] = @optional['rotationRate'] if @optional['rotationRate']
|
|
231
|
+
res['rotationTime'] = @optional['rotationTime'] if @optional['rotationTime']
|
|
232
|
+
|
|
233
|
+
res
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def to_json(*args)
|
|
237
|
+
as_json.to_json(*args)
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#
|
|
2
|
+
# This file is auto-generated, do not edit
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
require 'json'
|
|
6
|
+
|
|
7
|
+
module RecombeeApiClient
|
|
8
|
+
require_relative 'input'
|
|
9
|
+
require_relative '../errors'
|
|
10
|
+
|
|
11
|
+
##
|
|
12
|
+
# Initializes Logic input#
|
|
13
|
+
class Logic < Input
|
|
14
|
+
attr_reader :name, :settings
|
|
15
|
+
|
|
16
|
+
##
|
|
17
|
+
#
|
|
18
|
+
# * *Optional arguments (given as hash optional)*
|
|
19
|
+
# - +name+ -> Name of the logic that should be used
|
|
20
|
+
# - +settings+ -> Parameters passed to the logic
|
|
21
|
+
#
|
|
22
|
+
def initialize(optional = {})
|
|
23
|
+
optional = normalize_hash_to_camel_case(optional)
|
|
24
|
+
@name = optional['name']
|
|
25
|
+
@settings = optional['settings']
|
|
26
|
+
@optional = optional
|
|
27
|
+
@optional.each do |par, _|
|
|
28
|
+
raise UnknownOptionalParameter.new(par) unless %w[name settings].include? par
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Return only JSON-serializable primitives.
|
|
33
|
+
def as_json(_options = {})
|
|
34
|
+
res = {}
|
|
35
|
+
res['name'] = @optional['name'] if @optional['name']
|
|
36
|
+
res['settings'] = @optional['settings'] if @optional['settings']
|
|
37
|
+
|
|
38
|
+
res
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def to_json(*args)
|
|
42
|
+
as_json.to_json(*args)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module RecombeeApiClient
|
|
2
|
+
##
|
|
3
|
+
# Module to convert Ruby conventions to Recombee's API namings
|
|
4
|
+
#
|
|
5
|
+
module HashNormalizer
|
|
6
|
+
def normalize_hash_to_camel_case(h)
|
|
7
|
+
return h unless h.is_a?(Hash)
|
|
8
|
+
|
|
9
|
+
h_new = {}
|
|
10
|
+
h.each do |k, v|
|
|
11
|
+
key = k.is_a?(String) ? camelize(k) : camelize(k.to_s)
|
|
12
|
+
h_new[key] = v
|
|
13
|
+
end
|
|
14
|
+
h_new
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def camelize(str)
|
|
18
|
+
str.gsub(/_(.)/) { |_e| ::Regexp.last_match(1).upcase }
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/recombee_api_client.rb
CHANGED
|
@@ -10,6 +10,7 @@ require 'cgi'
|
|
|
10
10
|
|
|
11
11
|
require 'recombee_api_client/errors'
|
|
12
12
|
Gem.find_files('recombee_api_client/api/*.rb').each { |path| require path }
|
|
13
|
+
Gem.find_files('recombee_api_client/inputs/*.rb').each { |path| require path }
|
|
13
14
|
|
|
14
15
|
module RecombeeApiClient
|
|
15
16
|
##
|
|
@@ -17,8 +18,8 @@ module RecombeeApiClient
|
|
|
17
18
|
class RecombeeClient
|
|
18
19
|
include HTTParty
|
|
19
20
|
|
|
20
|
-
BATCH_MAX_SIZE =
|
|
21
|
-
USER_AGENT = {'User-Agent' => 'recombee-ruby-api-client/
|
|
21
|
+
BATCH_MAX_SIZE = 10_000
|
|
22
|
+
USER_AGENT = { 'User-Agent' => 'recombee-ruby-api-client/6.1.0' }
|
|
22
23
|
|
|
23
24
|
##
|
|
24
25
|
# - +account+ -> Name of your account at Recombee
|
|
@@ -33,8 +34,7 @@ module RecombeeApiClient
|
|
|
33
34
|
##
|
|
34
35
|
# - +request+ -> ApiRequest to be sent to Recombee recommender
|
|
35
36
|
def send(request)
|
|
36
|
-
|
|
37
|
-
return send_multipart_batch(request) if request.kind_of? Batch and request.requests.size > BATCH_MAX_SIZE
|
|
37
|
+
return send_multipart_batch(request) if request.is_a? Batch and request.requests.size > BATCH_MAX_SIZE
|
|
38
38
|
|
|
39
39
|
timeout = request.timeout / 1000
|
|
40
40
|
uri = process_request_uri(request)
|
|
@@ -54,7 +54,7 @@ module RecombeeApiClient
|
|
|
54
54
|
delete(request, uri, timeout)
|
|
55
55
|
end
|
|
56
56
|
rescue Timeout::Error
|
|
57
|
-
|
|
57
|
+
raise ApiTimeout.new(request)
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
60
|
|
|
@@ -62,12 +62,15 @@ module RecombeeApiClient
|
|
|
62
62
|
|
|
63
63
|
def get_regional_base_uri(region)
|
|
64
64
|
uri = {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
'ap-se' => 'rapi-ap-se.recombee.com',
|
|
66
|
+
'ca-east' => 'rapi-ca-east.recombee.com',
|
|
67
|
+
'eu-west' => 'rapi-eu-west.recombee.com',
|
|
68
|
+
'us-west' => 'rapi-us-west.recombee.com'
|
|
69
|
+
}[region.to_s.gsub('_', '-').downcase]
|
|
70
|
+
if uri.nil?
|
|
71
|
+
raise ArgumentError.new("Region \"#{region}\" is unknown. You may need to update the version of the SDK.")
|
|
72
|
+
end
|
|
73
|
+
|
|
71
74
|
uri
|
|
72
75
|
end
|
|
73
76
|
|
|
@@ -77,16 +80,17 @@ module RecombeeApiClient
|
|
|
77
80
|
|
|
78
81
|
if options.key? :region
|
|
79
82
|
raise ArgumentError.new(':base_uri and :region cannot be specified at the same time') if base_uri
|
|
83
|
+
|
|
80
84
|
base_uri = get_regional_base_uri(options[:region])
|
|
81
85
|
end
|
|
82
|
-
base_uri||= 'rapi.recombee.com'
|
|
86
|
+
base_uri ||= 'rapi.recombee.com'
|
|
83
87
|
base_uri
|
|
84
88
|
end
|
|
85
89
|
|
|
86
90
|
def put(request, uri, timeout)
|
|
87
|
-
response = self.class.put(uri, body: request.body_parameters.to_json,
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
response = self.class.put(uri, body: request.body_parameters.to_json,
|
|
92
|
+
headers: { 'Content-Type' => 'application/json' }.merge(USER_AGENT),
|
|
93
|
+
timeout: timeout)
|
|
90
94
|
check_errors(response, request)
|
|
91
95
|
response.body
|
|
92
96
|
end
|
|
@@ -98,44 +102,45 @@ module RecombeeApiClient
|
|
|
98
102
|
end
|
|
99
103
|
|
|
100
104
|
def post(request, uri, timeout)
|
|
101
|
-
response = self.class.post(uri, body: request.body_parameters.to_json,
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
response = self.class.post(uri, body: request.body_parameters.to_json,
|
|
106
|
+
headers: { 'Content-Type' => 'application/json' }.merge(USER_AGENT),
|
|
107
|
+
timeout: timeout)
|
|
104
108
|
check_errors(response, request)
|
|
105
109
|
begin
|
|
106
|
-
|
|
110
|
+
JSON.parse(response.body)
|
|
107
111
|
rescue JSON::ParserError
|
|
108
|
-
|
|
112
|
+
response.body
|
|
109
113
|
end
|
|
110
114
|
end
|
|
111
115
|
|
|
112
116
|
def delete(request, uri, timeout)
|
|
113
117
|
response = self.class.delete(uri, body: request.body_parameters.to_json,
|
|
114
|
-
|
|
115
|
-
|
|
118
|
+
headers: { 'Content-Type' => 'application/json' }.merge(USER_AGENT),
|
|
119
|
+
timeout: timeout)
|
|
116
120
|
check_errors(response, request)
|
|
117
121
|
begin
|
|
118
|
-
|
|
122
|
+
JSON.parse(response.body)
|
|
119
123
|
rescue JSON::ParserError
|
|
120
|
-
|
|
124
|
+
response.body
|
|
121
125
|
end
|
|
122
126
|
end
|
|
123
127
|
|
|
124
128
|
def check_errors(response, request)
|
|
125
129
|
status_code = response.code
|
|
126
|
-
return if
|
|
127
|
-
|
|
130
|
+
return if [200, 201].include?(status_code)
|
|
131
|
+
|
|
132
|
+
raise ResponseError.new(request, status_code, response.body)
|
|
128
133
|
end
|
|
129
134
|
|
|
130
135
|
def send_multipart_batch(request)
|
|
131
136
|
requests_parts = request.requests.each_slice(BATCH_MAX_SIZE)
|
|
132
|
-
responses = requests_parts.map {|rqs| Batch.new(rqs)}.map{|batch| send(batch)}
|
|
133
|
-
responses.inject([]){|result,resp| result + resp}
|
|
137
|
+
responses = requests_parts.map { |rqs| Batch.new(rqs) }.map { |batch| send(batch) }
|
|
138
|
+
responses.inject([]) { |result, resp| result + resp }
|
|
134
139
|
end
|
|
135
140
|
|
|
136
141
|
def process_request_uri(request)
|
|
137
142
|
uri = request.path
|
|
138
|
-
uri.slice!
|
|
143
|
+
uri.slice!('/{databaseId}/')
|
|
139
144
|
uri += query_parameters_to_url(request)
|
|
140
145
|
uri
|
|
141
146
|
end
|
|
@@ -143,15 +148,16 @@ module RecombeeApiClient
|
|
|
143
148
|
def query_parameters_to_url(req)
|
|
144
149
|
ps = ''
|
|
145
150
|
req.query_parameters.each do |name, val|
|
|
146
|
-
ps +=
|
|
151
|
+
ps += ps.include?('?') ? '&' : '?'
|
|
147
152
|
ps += "#{name}=#{format_query_parameter_value(val)}"
|
|
148
153
|
end
|
|
149
154
|
ps
|
|
150
155
|
end
|
|
151
156
|
|
|
152
157
|
def format_query_parameter_value(value)
|
|
153
|
-
return CGI
|
|
154
|
-
|
|
158
|
+
return CGI.escape("#{value}") unless value.is_a?(Array)
|
|
159
|
+
|
|
160
|
+
value.map { |v| CGI.escape("#{v}") }.join(',')
|
|
155
161
|
end
|
|
156
162
|
|
|
157
163
|
# Sign request with HMAC, request URI must be exacly the same
|
|
@@ -160,12 +166,11 @@ module RecombeeApiClient
|
|
|
160
166
|
uri = "/#{@account}/#{req_part}"
|
|
161
167
|
time = hmac_time(uri)
|
|
162
168
|
sign = hmac_sign(uri, time)
|
|
163
|
-
|
|
164
|
-
res
|
|
169
|
+
uri + time + "&hmac_sign=#{sign}"
|
|
165
170
|
end
|
|
166
171
|
|
|
167
172
|
def hmac_time(uri)
|
|
168
|
-
res =
|
|
173
|
+
res = uri.include?('?') ? '&' : '?'
|
|
169
174
|
res << "hmac_timestamp=#{Time.now.utc.to_i}"
|
|
170
175
|
end
|
|
171
176
|
|
data/recombee_api_client.gemspec
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
3
|
require 'recombee_api_client/version'
|
|
5
4
|
|
|
@@ -19,8 +18,8 @@ Gem::Specification.new do |spec|
|
|
|
19
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
20
19
|
spec.require_paths = ['lib']
|
|
21
20
|
|
|
22
|
-
spec.add_dependency 'multi_json', '~> 1.15'
|
|
23
21
|
spec.add_dependency 'httparty', '~> 0.18'
|
|
22
|
+
spec.add_dependency 'multi_json', '~> 1.15'
|
|
24
23
|
|
|
25
24
|
spec.add_development_dependency 'bundler', '~> 2.6.2'
|
|
26
25
|
spec.add_development_dependency 'rake', '~> 13.0'
|
metadata
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: recombee_api_client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 6.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ondřej Fiedler
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
|
-
name:
|
|
13
|
+
name: httparty
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '
|
|
18
|
+
version: '0.18'
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '
|
|
25
|
+
version: '0.18'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
|
-
name:
|
|
27
|
+
name: multi_json
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
|
30
30
|
- - "~>"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '
|
|
32
|
+
version: '1.15'
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - "~>"
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '
|
|
39
|
+
version: '1.15'
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: bundler
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -105,6 +105,7 @@ files:
|
|
|
105
105
|
- lib/recombee_api_client/api/add_user.rb
|
|
106
106
|
- lib/recombee_api_client/api/add_user_property.rb
|
|
107
107
|
- lib/recombee_api_client/api/batch.rb
|
|
108
|
+
- lib/recombee_api_client/api/composite_recommendation.rb
|
|
108
109
|
- lib/recombee_api_client/api/create_auto_reql_segmentation.rb
|
|
109
110
|
- lib/recombee_api_client/api/create_manual_reql_segmentation.rb
|
|
110
111
|
- lib/recombee_api_client/api/create_property_based_segmentation.rb
|
|
@@ -129,7 +130,6 @@ files:
|
|
|
129
130
|
- lib/recombee_api_client/api/get_segmentation.rb
|
|
130
131
|
- lib/recombee_api_client/api/get_user_property_info.rb
|
|
131
132
|
- lib/recombee_api_client/api/get_user_values.rb
|
|
132
|
-
- lib/recombee_api_client/api/hash_normalizer.rb
|
|
133
133
|
- lib/recombee_api_client/api/insert_to_series.rb
|
|
134
134
|
- lib/recombee_api_client/api/list_item_bookmarks.rb
|
|
135
135
|
- lib/recombee_api_client/api/list_item_cart_additions.rb
|
|
@@ -177,6 +177,10 @@ files:
|
|
|
177
177
|
- lib/recombee_api_client/api/update_more_items.rb
|
|
178
178
|
- lib/recombee_api_client/api/update_property_based_segmentation.rb
|
|
179
179
|
- lib/recombee_api_client/errors.rb
|
|
180
|
+
- lib/recombee_api_client/inputs/composite_recommendation_stage_parameters.rb
|
|
181
|
+
- lib/recombee_api_client/inputs/input.rb
|
|
182
|
+
- lib/recombee_api_client/inputs/logic.rb
|
|
183
|
+
- lib/recombee_api_client/utils/hash_normalizer.rb
|
|
180
184
|
- lib/recombee_api_client/version.rb
|
|
181
185
|
- recombee_api_client.gemspec
|
|
182
186
|
homepage: https://recombee.com
|
|
@@ -197,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
197
201
|
- !ruby/object:Gem::Version
|
|
198
202
|
version: '0'
|
|
199
203
|
requirements: []
|
|
200
|
-
rubygems_version: 3.
|
|
204
|
+
rubygems_version: 3.7.2
|
|
201
205
|
specification_version: 4
|
|
202
206
|
summary: Client for Recombee recommendation API
|
|
203
207
|
test_files: []
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
module RecombeeApiClient
|
|
2
|
-
##
|
|
3
|
-
# Module to convert Ruby conventions to Recombee's API namings
|
|
4
|
-
#
|
|
5
|
-
module HashNormalizer
|
|
6
|
-
def normalize_optional opts
|
|
7
|
-
opts_new = {}
|
|
8
|
-
opts.each do |k,v|
|
|
9
|
-
case k
|
|
10
|
-
when String then opts_new[camelize(k)] = opts.delete(k)
|
|
11
|
-
when Symbol then opts_new[camelize(k.to_s)] = opts.delete(k)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
opts_new
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def camelize str
|
|
18
|
-
str.gsub(/_(.)/) {|e| $1.upcase}
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|