Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: implement missing requests #6

Merged
merged 24 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
87498c5
feat: add search requests
stanislav-zeman Nov 24, 2023
8626fea
style: rename type variable
stanislav-zeman Nov 24, 2023
b5dc7f3
feat: add item properties listing
stanislav-zeman Nov 24, 2023
4eabdee
feat: add user properties definition requests
stanislav-zeman Nov 24, 2023
a8f4267
feat: add user properties values requests
stanislav-zeman Nov 24, 2023
42b0fbe
refactor: rename interaction details
stanislav-zeman Nov 24, 2023
c1f279f
feat: implement missing items requests
stanislav-zeman Nov 24, 2023
e321543
feat: implement missing user requests
stanislav-zeman Nov 24, 2023
7c6903b
feat: implement missing user item interaction requests
stanislav-zeman Nov 24, 2023
16319cb
feat: implement miscellaneous requests
stanislav-zeman Nov 24, 2023
dfa4aad
feat: implement missing items recommendations requests
stanislav-zeman Nov 24, 2023
433391d
feat: implement search synonyms requests
stanislav-zeman Nov 24, 2023
0ce79c4
refactor: rename recommendations
stanislav-zeman Nov 24, 2023
bf00999
feat: implement user recommendation requests
stanislav-zeman Nov 24, 2023
36acf44
feat: implement item segments recommendation requests
stanislav-zeman Nov 24, 2023
8f4e1e2
feat: implement general segmentation requests
stanislav-zeman Nov 24, 2023
5e09a94
feat: implement property based segmentation requests
stanislav-zeman Nov 24, 2023
298d238
feat: implement manual reql segmentation requests
stanislav-zeman Nov 24, 2023
d1dfc17
feat: implement auto reql segmentation requests
stanislav-zeman Nov 24, 2023
d6089a9
chore: update readme
stanislav-zeman Nov 24, 2023
a3c4db1
fix: recommendation file name typo
stanislav-zeman Nov 24, 2023
3bc85da
doc: add missing doc string to item values
stanislav-zeman Nov 24, 2023
693ecbf
doc: add missing doc string to items
stanislav-zeman Nov 24, 2023
a7c2f0a
doc: add missing doc string to search
stanislav-zeman Nov 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,27 @@ Is capable of managing:
* Add item
* Delete item
* List items
* Delete more items
* Item Properties
* Add item property
* Delete item property
* Get item property info
* List item properties
* Set item values
* Get item values
* Update more items
* Users
* Add user
* Delete user
* Merge users
* List users
* User Properties
* Add user property
* Delete user property
* Get user property info
* List user properties
* Set user values
* Get user values
* User-Item Interactions
* Add detail view
* Delete detail view
Expand All @@ -39,6 +49,10 @@ Is capable of managing:
* Delete rating
* List item ratings
* List user ratings
* Add cart addition
* Delete cart addition
* List item cart additions
* List user cart additions
* Add bookmark
* Delete bookmark
* List item bookmarks
Expand All @@ -48,12 +62,28 @@ Is capable of managing:
* List item view portions
* List user view portions
* Recommendations
* Recommend items to user
* Recommend items to item
* Recommending items
* Recommending item segments
* Recommending users
* Search
* Search items
* Search items segments
* Synonyms
* Series
* Add series
* Delete series
* List series
* List series items
* Insert to series
* Remove from series
* Segmentations definition
* General
* Property based
* Manual ReQL
* Auto ReQL
* Miscellaneous
* Reset database
* Batch

Uses [batch mode](https://docs.recombee.com/api.html#batch) by default to send requests to the API.

Expand Down
57 changes: 57 additions & 0 deletions interaction_cart_addition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package recombee

import (
"fmt"
"net/http"
)

// AddCartAddition adds a cart addition of the given item made by the given user.
func AddCartAddition(userId string, itemId string, opts ...RequestOption) Request {
params := map[string]interface{}{
"userId": userId,
"itemId": itemId,
}
for _, option := range opts {
option(params)
}

return Request{
Path: "/cartadditions/",
Method: http.MethodPost,
Params: params,
}
}

// DeleteCartAddition deletes an existing cart addition uniquely specified by userId, itemId, and timestamp
// or all the cart additions with the given userId and itemId if timestamp is omitted.
func DeleteCartAddition(userId string, itemId string, opts ...RequestOption) Request {
params := map[string]interface{}{
"userId": userId,
"itemId": itemId,
}
for _, option := range opts {
option(params)
}

return Request{
Path: "/cartadditions/",
Method: http.MethodDelete,
Params: params,
}
}

// ListItemCartAddition lists all the ever-made cart additions of the given item.
func ListItemCartAddition(itemId string) Request {
return Request{
Path: fmt.Sprintf("/items/%s/cartadditions/", itemId),
Method: http.MethodGet,
}
}

// ListUserCartAddition lists all the cart additions ever made by the given user.
func ListUserCartAddition(userId string) Request {
return Request{
Path: fmt.Sprintf("/users/%s/cartadditions/", userId),
Method: http.MethodGet,
}
}
File renamed without changes.
12 changes: 10 additions & 2 deletions item_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
//
// Adding an item property is somehow equivalent to adding a column to the table of items. The items may be
// characterized by various properties of different types.
func AddItemProperty(propertyName string, type_ string) Request {
func AddItemProperty(propertyName string, typ string) Request {
return Request{
Path: fmt.Sprintf("/items/properties/%s", propertyName),
Method: http.MethodPut,
Params: map[string]interface{}{
"type": type_,
"type": typ,
},
}
}
Expand All @@ -36,3 +36,11 @@ func GetItemPropertyInfo(propertyName string) Request {
Method: http.MethodGet,
}
}

// ListItemProperties gets the list of all the item properties in your database.
func ListItemProperties() Request {
return Request{
Path: "/items/properties/list/",
Method: http.MethodGet,
}
}
15 changes: 11 additions & 4 deletions item_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import (
"net/http"
)

// AddItemValues sets/updates (some) property values of the given item. The properties (columns) must be previously
// created by AddItemProperty.
func AddItemValues(itemId string, values map[string]interface{}) Request {
// SetItemValues sets or updates (some) property values of the given item.
// The properties (columns) must be previously created by AddItemProperty.
func SetItemValues(itemId string) Request {
return Request{
Path: fmt.Sprintf("/items/%s", itemId),
Method: http.MethodPost,
Params: values,
}
}

Expand All @@ -22,3 +21,11 @@ func GetItemValues(itemId string) Request {
Method: http.MethodGet,
}
}

// UpdateMoreItems updates (some) property values of all the items that pass the filter.
func UpdateMoreItems() Request {
Matovidlo marked this conversation as resolved.
Show resolved Hide resolved
return Request{
Path: "/more-items/",
Method: http.MethodPost,
}
}
12 changes: 12 additions & 0 deletions items.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,15 @@ func ListItems(opts ...RequestOption) Request {
Params: params,
}
}

// DeleteMoreItems deletes all the items that pass the filter.
//
// If an item becomes obsolete/no longer available, it is meaningful to keep it in the catalog
// (along with all the interaction data, which are very useful) and only exclude the item from recommendations.
// In such a case, use ReQL filter instead of deleting the item completely.
func DeleteMoreItems() Request {
Matovidlo marked this conversation as resolved.
Show resolved Hide resolved
return Request{
Path: "/more-items/",
Method: http.MethodDelete,
}
}
27 changes: 27 additions & 0 deletions miscellaneous.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package recombee

import (
"net/http"
)

// ResetDatabase completely erases all your data, including items, item properties, series,
// user database, purchases, ratings, detail views, and bookmarks.
// Make sure the request is never executed in the production environment!
// Resetting your database is irreversible.
func ResetDatabase() Request {
return Request{
Path: "/",
Method: http.MethodDelete,
}
}

// Batch processing allows you to submit arbitrary sequence of requests within a single HTTPS request.
//
// Any type of request from the above documentation may be used in the Batch, and the Batch
// may combine different types of requests arbitrarily as well.
func Batch() Request {
return Request{
Path: "/batch/",
Method: http.MethodPost,
}
}
9 changes: 9 additions & 0 deletions recommandation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package recombee

type Recommendations struct {
Matovidlo marked this conversation as resolved.
Show resolved Hide resolved
RecommID string `json:"recommId"`
Recomms []struct {
ID string `json:"id"`
} `json:"recomms"`
NumberNextRecommsCalls int `json:"numberNextRecommsCalls"`
}
147 changes: 147 additions & 0 deletions recommendation_items.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package recombee

import (
"fmt"
"net/http"
)

// RecommendItemsToUser recommends top-N items that are most likely to be of high value for the given user.
//
// The most typical use cases are recommendations on the homepage, in some “Picked just for you” section, or in email.
//
// The returned items are sorted by relevance (the first item being the most relevant).
//
// Besides the recommended items, also a unique recommId is returned in the response. It can be used to:
//
// - Let Recombee know that this recommendation was successful (e.g., user clicked one of the recommended items).
//
// - Get subsequent recommended items when the user scrolls down (infinite scroll) or goes to the next page.
func RecommendItemsToUser(userId string, count int, opts ...RequestOption) Request {
params := make(map[string]interface{})
params["count"] = count
for _, o := range opts {
o(params)
}

return Request{
Path: fmt.Sprintf("/recomms/users/%s/items/", userId),
Method: http.MethodGet,
Params: params,
}
}

// RecommendItemsToItem recommends a set of items that are somehow related to one given item, X. A typical scenario is
// when the user A is viewing X. Then you may display items to the user that he might also be interested in. Recommend
// items to item request gives you Top-N such items, optionally taking the target user A into account.
//
// The returned items are sorted by relevance (the first item being the most relevant).
//
// Besides the recommended items, also a unique recommId is returned in the response. It can be used to:
//
// - Let Recombee know that this recommendation was successful (e.g., user clicked one of the recommended items). See Reported metrics.
//
// - Get subsequent recommended items when the user scrolls down (infinite scroll) or goes to the next page. See Recommend Next Items.
func RecommendItemsToItem(itemId string, targetUserId string, count int, opts ...RequestOption) Request {
params := make(map[string]interface{})
params["count"] = count
params["targetUserId"] = targetUserId
for _, o := range opts {
o(params)
}

return Request{
Path: fmt.Sprintf("/recomms/items/%s/items/", itemId),
Method: http.MethodGet,
Params: params,
}
}

// RecommendNextItems returns items that shall be shown to a user as next recommendations when the
// user e.g. scrolls the page down (infinite scroll) or goes to the next page.
//
// It accepts recommId of a base recommendation request (e.g., request from the first page)
// and the number of items that shall be returned (count).
func RecommendNextItems(recommId string, count int, opts ...RequestOption) Request {
params := make(map[string]interface{})
params["count"] = count
for _, o := range opts {
o(params)
}

return Request{
Path: fmt.Sprintf("/recomms/next/items/%s", recommId),
Method: http.MethodGet,
Params: params,
}
}

// RecommendItemSegmentsToUser recommends the top Segments from a Segmentation
// for a particular user, based on the user’s past interactions.
//
// Based on the used Segmentation, this endpoint can be used for example for:
// - Recommending the top categories for the user
// - Recommending the top genres for the user
// - Recommending the top brands for the user
// - Recommending the top artists for the user
func RecommendItemSegmentsToUser(userId string, count int, opts ...RequestOption) Request {
params := make(map[string]interface{})
params["count"] = count
for _, o := range opts {
o(params)
}

return Request{
Path: fmt.Sprintf("/recomms/users/%s/item-segments/", userId),
Method: http.MethodGet,
Params: params,
}
}

// RecommendItemSegmentsToItem recommends Segments from a Segmentation that are the most relevant to a particular item.
//
// Based on the used Segmentation, this endpoint can be used for example for:
// - Recommending the related categories
// - Recommending the related genres
// - Recommending the related brands
// - Recommending the related artists
func RecommendItemSegmentsToItem(itemId string, targetUserId string, count int, opts ...RequestOption) Request {
params := make(map[string]interface{})
params["count"] = count
params["targetUserId"] = targetUserId
for _, o := range opts {
o(params)
}

return Request{
Path: fmt.Sprintf("/recomms/items/%s/item-segments/", itemId),
Method: http.MethodGet,
Params: params,
}
}

// RecommendItemSegmentsToItemSegment recommends Segments from a result Segmentation that are the most relevant to a particular Segment from a context Segmentation.
//
// Based on the used Segmentations, this endpoint can be used for example for:
// - Recommending the related brands to particular brand
// - Recommending the related brands to particular category
// - Recommending the related artists to a particular genre (assuming songs are the Items)
func RecommendItemSegmentsToItemSegment(
contextSegmentId string,
targetUserId string,
count int,
opts ...RequestOption,
) Request {
params := make(map[string]interface{})
params["count"] = count
params["targetUserId"] = targetUserId
params["contextSegmentId"] = contextSegmentId
for _, o := range opts {
o(params)
}

return Request{
Path: "/recomms/item-segments/item-segments/",
Method: http.MethodGet,
Params: params,
}
}
Loading