Skip to content

Commit 13fb918

Browse files
committed
Release: v6.1.0
- Added support for `reqlExpressions` on recommended item segments - Formatting
1 parent 785b3cf commit 13fb918

17 files changed

+413
-117
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ https://github.com/recombee/swift-api-client
4646
Alternatively, in `Package.swift`:
4747

4848
```swift
49-
.package(url: "https://github.com/recombee/swift-api-client", from: "6.0.0")
49+
.package(url: "https://github.com/recombee/swift-api-client", from: "6.1.0")
5050
```
5151

5252
Then add to your target dependencies:

Sources/RecombeeClient/Requests/AddBookmark.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ public struct AddBookmark: Request {
1515
public let itemId: String
1616

1717
/// UTC timestamp of the bookmark as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
18-
public var timestamp: Date? = nil
18+
public var timestamp: Date?
1919

2020
/// Sets whether the given user/item should be created if not present in the database.
2121
public var cascadeCreate: Bool? = true
2222

2323
/// If this bookmark is based on a recommendation request, `recommId` is the id of the clicked recommendation.
24-
public var recommId: String? = nil
24+
public var recommId: String?
2525

2626
/// A dictionary of additional data for the interaction.
27-
public var additionalData: JSONDictionary? = nil
27+
public var additionalData: JSONDictionary?
2828

2929
/// Initializes AddBookmark request
3030
/// - Parameters:

Sources/RecombeeClient/Requests/AddCartAddition.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ public struct AddCartAddition: Request {
1515
public let itemId: String
1616

1717
/// UTC timestamp of the cart addition as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
18-
public var timestamp: Date? = nil
18+
public var timestamp: Date?
1919

2020
/// Sets whether the given user/item should be created if not present in the database.
2121
public var cascadeCreate: Bool? = true
2222

2323
/// 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 2.
24-
public var amount: Double? = nil
24+
public var amount: Double?
2525

2626
/// Price of the added item. If `amount` is greater than 1, the sum of prices of all the items should be given.
27-
public var price: Double? = nil
27+
public var price: Double?
2828

2929
/// If this cart addition is based on a recommendation request, `recommId` is the id of the clicked recommendation.
30-
public var recommId: String? = nil
30+
public var recommId: String?
3131

3232
/// A dictionary of additional data for the interaction.
33-
public var additionalData: JSONDictionary? = nil
33+
public var additionalData: JSONDictionary?
3434

3535
/// Initializes AddCartAddition request
3636
/// - Parameters:

Sources/RecombeeClient/Requests/AddDetailView.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ public struct AddDetailView: Request {
1515
public let itemId: String
1616

1717
/// UTC timestamp of the view as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
18-
public var timestamp: Date? = nil
18+
public var timestamp: Date?
1919

2020
/// Duration of the view
21-
public var duration: Int? = nil
21+
public var duration: Int?
2222

2323
/// Sets whether the given user/item should be created if not present in the database.
2424
public var cascadeCreate: Bool? = true
2525

2626
/// If this detail view is based on a recommendation request, `recommId` is the id of the clicked recommendation.
27-
public var recommId: String? = nil
27+
public var recommId: String?
2828

2929
/// A dictionary of additional data for the interaction.
30-
public var additionalData: JSONDictionary? = nil
30+
public var additionalData: JSONDictionary?
3131

3232
/// Indicates whether the item was automatically presented to the user (e.g., in a swiping feed) or explicitly requested by the user (e.g., by clicking on a link). Defaults to `false`.
33-
public var autoPresented: Bool? = nil
33+
public var autoPresented: Bool?
3434

3535
/// Initializes AddDetailView request
3636
/// - Parameters:

Sources/RecombeeClient/Requests/AddPurchase.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ public struct AddPurchase: Request {
1515
public let itemId: String
1616

1717
/// UTC timestamp of the purchase as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
18-
public var timestamp: Date? = nil
18+
public var timestamp: Date?
1919

2020
/// Sets whether the given user/item should be created if not present in the database.
2121
public var cascadeCreate: Bool? = true
2222

2323
/// 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 2.
24-
public var amount: Double? = nil
24+
public var amount: Double?
2525

2626
/// Price paid by the user for the item. If `amount` is greater than 1, the sum of prices of all the items should be given.
27-
public var price: Double? = nil
27+
public var price: Double?
2828

2929
/// Your profit from the purchased item. The profit is natural in the 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 also applicable in other domains (for example, at a news company it may be income from a displayed advertisement on article page). If `amount` is greater than 1, the sum of profit of all the items should be given.
30-
public var profit: Double? = nil
30+
public var profit: Double?
3131

3232
/// If this purchase is based on a recommendation request, `recommId` is the id of the clicked recommendation.
33-
public var recommId: String? = nil
33+
public var recommId: String?
3434

3535
/// A dictionary of additional data for the interaction.
36-
public var additionalData: JSONDictionary? = nil
36+
public var additionalData: JSONDictionary?
3737

3838
/// Initializes AddPurchase request
3939
/// - Parameters:

Sources/RecombeeClient/Requests/AddRating.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ public struct AddRating: Request {
1818
public let rating: Double
1919

2020
/// UTC timestamp of the rating as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
21-
public var timestamp: Date? = nil
21+
public var timestamp: Date?
2222

2323
/// Sets whether the given user/item should be created if not present in the database.
2424
public var cascadeCreate: Bool? = true
2525

2626
/// If this rating is based on a recommendation request, `recommId` is the id of the clicked recommendation.
27-
public var recommId: String? = nil
27+
public var recommId: String?
2828

2929
/// A dictionary of additional data for the interaction.
30-
public var additionalData: JSONDictionary? = nil
30+
public var additionalData: JSONDictionary?
3131

3232
/// Initializes AddRating request
3333
/// - Parameters:

Sources/RecombeeClient/Requests/Batch.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public struct Batch: Request {
88
public let requests: [any Request]
99

1010
/// Whether to return distinct recommendations across all batched requests (default is false).
11-
public var distinctRecomms: Bool? = nil
11+
public var distinctRecomms: Bool?
1212

1313
public var path: String { "/batch/" }
1414
public var method: HTTPMethod { .POST }

Sources/RecombeeClient/Requests/CompositeRecommendation.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,38 +37,38 @@ public struct CompositeRecommendation: Request {
3737

3838
/// ID of the item for which the recommendations are to be generated.
3939

40-
public var itemId: String? = nil
40+
public var itemId: String?
4141

4242
/// ID of the user for which the recommendations are to be generated.
4343

44-
public var userId: String? = nil
44+
public var userId: String?
4545

4646
/// Logic specifies the particular behavior of the recommendation models. You can pick tailored logic for your domain and use case.
4747
/// See [this section](https://docs.recombee.com/recommendation_logics) for a list of available logics and other details.
4848
/// The difference between `logic` and `scenario` is that `logic` specifies mainly behavior, while `scenario` specifies the place where recommendations are shown to the users.
4949
/// Logic can also be set to a [scenario](https://docs.recombee.com/scenarios) in the [Admin UI](https://admin.recombee.com).
5050

51-
public var logic: Logic? = nil
51+
public var logic: Logic?
5252

5353
/// ID of the segment from `contextSegmentationId` for which the recommendations are to be generated.
5454

55-
public var segmentId: String? = nil
55+
public var segmentId: String?
5656

5757
/// If the entity for the source recommendation does not exist in the database, returns a list of non-personalized recommendations and creates the user in the database. This allows, for example, rotations in the following recommendations for that entity, as the entity will be already known to the system.
5858

5959
public var cascadeCreate: Bool? = true
6060

6161
/// Parameters applied for recommending the *Source* stage. The accepted parameters correspond with the recommendation sub-endpoint used to recommend the *Source*.
6262

63-
public var sourceSettings: CompositeRecommendationStageParameters? = nil
63+
public var sourceSettings: CompositeRecommendationStageParameters?
6464

6565
/// Parameters applied for recommending the *Result* stage. The accepted parameters correspond with the recommendation sub-endpoint used to recommend the *Result*.
6666

67-
public var resultSettings: CompositeRecommendationStageParameters? = nil
67+
public var resultSettings: CompositeRecommendationStageParameters?
6868

6969
/// Dictionary of custom options.
7070

71-
public var expertSettings: JSONDictionary? = nil
71+
public var expertSettings: JSONDictionary?
7272

7373
/// Initializes CompositeRecommendation request
7474
/// - Parameters:

Sources/RecombeeClient/Requests/RecommendItemSegmentsToItem.swift

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,70 @@ public struct RecommendItemSegmentsToItem: Request {
4343
/// You can set various settings to the [scenario](https://docs.recombee.com/scenarios) in the [Admin UI](https://admin.recombee.com). You can also see the performance of each scenario in the Admin UI separately, so you can check how well each application performs.
4444
/// The AI that optimizes models to get the best results may optimize different scenarios separately or even use different models in each of the scenarios.
4545

46-
public var scenario: String? = nil
46+
public var scenario: String?
4747

4848
/// If the user does not exist in the database, returns a list of non-personalized recommendations and creates the user in the database. This allows, for example, rotations in the following recommendations for that user, as the user will be already known to the system.
4949

5050
public var cascadeCreate: Bool? = true
5151

5252
/// Boolean-returning [ReQL](https://docs.recombee.com/reql) expression which allows you to filter recommended segments based on the `segmentationId`.
5353

54-
public var filter: String? = nil
54+
public var filter: String?
5555

5656
/// Number-returning [ReQL](https://docs.recombee.com/reql) expression which allows you to boost recommendation rate of some segments based on the `segmentationId`.
5757

58-
public var booster: String? = nil
58+
public var booster: String?
5959

6060
/// Logic specifies the particular behavior of the recommendation models. You can pick tailored logic for your domain and use case.
6161
/// See [this section](https://docs.recombee.com/recommendation_logics) for a list of available logics and other details.
6262
/// The difference between `logic` and `scenario` is that `logic` specifies mainly behavior, while `scenario` specifies the place where recommendations are shown to the users.
6363
/// Logic can also be set to a [scenario](https://docs.recombee.com/scenarios) in the [Admin UI](https://admin.recombee.com).
6464

65-
public var logic: Logic? = nil
65+
public var logic: Logic?
6666

6767
/// Dictionary of custom options.
6868

69-
public var expertSettings: JSONDictionary? = nil
69+
public var expertSettings: JSONDictionary?
7070

7171
/// If there is a custom AB-testing running, return the name of the group to which the request belongs.
7272

73-
public var returnAbGroup: Bool? = nil
73+
public var returnAbGroup: Bool?
74+
75+
/// A dictionary of [ReQL](https://docs.recombee.com/reql) expressions that will be executed for each recommended Item Segment.
76+
/// This can be used to compute additional properties of the recommended Item Segments.
77+
/// The keys are the names of the expressions, and the values are the actual ReQL expressions.
78+
/// Example request:
79+
/// ```json
80+
/// {
81+
/// "reqlExpressions": {
82+
/// "countItems": "size(segment_items(\"categories\", 'segmentId'))"
83+
/// }
84+
/// }
85+
/// ```
86+
/// Example response:
87+
/// ```json
88+
/// {
89+
/// "recommId": "a7ac55a4-8d6e-4f19-addc-abac4164d8a8",
90+
/// "recomms":
91+
/// [
92+
/// {
93+
/// "id": "category-fantasy-books",
94+
/// "reqlEvaluations": {
95+
/// "countItems": 486
96+
/// }
97+
/// },
98+
/// {
99+
/// "id": "category-sci-fi-costumes",
100+
/// "reqlEvaluations": {
101+
/// "countItems": 19
102+
/// }
103+
/// }
104+
/// ],
105+
/// "numberNextRecommsCalls": 0
106+
/// }
107+
/// ```
108+
109+
public var reqlExpressions: JSONDictionary?
74110

75111
/// Initializes RecommendItemSegmentsToItem request
76112
/// - Parameters:
@@ -101,8 +137,41 @@ public struct RecommendItemSegmentsToItem: Request {
101137
/// Logic can also be set to a [scenario](https://docs.recombee.com/scenarios) in the [Admin UI](https://admin.recombee.com).
102138
/// - expertSettings: Dictionary of custom options.
103139
/// - returnAbGroup: If there is a custom AB-testing running, return the name of the group to which the request belongs.
104-
105-
public init(itemId: String, targetUserId: String, count: Int, scenario: String? = nil, cascadeCreate: Bool? = true, filter: String? = nil, booster: String? = nil, logic: Logic? = nil, expertSettings: JSONDictionary? = nil, returnAbGroup: Bool? = nil) {
140+
/// - reqlExpressions: A dictionary of [ReQL](https://docs.recombee.com/reql) expressions that will be executed for each recommended Item Segment.
141+
/// This can be used to compute additional properties of the recommended Item Segments.
142+
/// The keys are the names of the expressions, and the values are the actual ReQL expressions.
143+
/// Example request:
144+
/// ```json
145+
/// {
146+
/// "reqlExpressions": {
147+
/// "countItems": "size(segment_items(\"categories\", 'segmentId'))"
148+
/// }
149+
/// }
150+
/// ```
151+
/// Example response:
152+
/// ```json
153+
/// {
154+
/// "recommId": "a7ac55a4-8d6e-4f19-addc-abac4164d8a8",
155+
/// "recomms":
156+
/// [
157+
/// {
158+
/// "id": "category-fantasy-books",
159+
/// "reqlEvaluations": {
160+
/// "countItems": 486
161+
/// }
162+
/// },
163+
/// {
164+
/// "id": "category-sci-fi-costumes",
165+
/// "reqlEvaluations": {
166+
/// "countItems": 19
167+
/// }
168+
/// }
169+
/// ],
170+
/// "numberNextRecommsCalls": 0
171+
/// }
172+
/// ```
173+
174+
public init(itemId: String, targetUserId: String, count: Int, scenario: String? = nil, cascadeCreate: Bool? = true, filter: String? = nil, booster: String? = nil, logic: Logic? = nil, expertSettings: JSONDictionary? = nil, returnAbGroup: Bool? = nil, reqlExpressions: JSONDictionary? = nil) {
106175
self.itemId = itemId
107176
self.targetUserId = targetUserId
108177
self.count = count
@@ -113,6 +182,7 @@ public struct RecommendItemSegmentsToItem: Request {
113182
self.logic = logic
114183
self.expertSettings = expertSettings
115184
self.returnAbGroup = returnAbGroup
185+
self.reqlExpressions = reqlExpressions
116186
}
117187

118188
/// The API path for the request
@@ -167,6 +237,10 @@ public struct RecommendItemSegmentsToItem: Request {
167237
body["returnAbGroup"] = returnAbGroup
168238
}
169239

240+
if let reqlExpressions = reqlExpressions {
241+
body["reqlExpressions"] = reqlExpressions
242+
}
243+
170244
return body
171245
}
172246
}

0 commit comments

Comments
 (0)