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

add support for external ranking vars #154

Merged
merged 7 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 34 additions & 0 deletions flat_feed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package stream_test

import (
"context"
"encoding/json"
"fmt"
"net/http"
"testing"
Expand Down Expand Up @@ -69,6 +70,39 @@ func TestFlatFeedGetActivities(t *testing.T) {
assert.NoError(t, err)
}
}
func TestFlatFeedGetActivitiesExternalRanking(t *testing.T) {
ctx := context.Background()
client, requester := newClient(t)
flat, _ := newFlatFeedWithUserID(client, "123")

externalVarJSON, err := json.Marshal(map[string]any{
"music": 1,
"sports": 2.1,
"boolVal": true,
"string": "str",
})

require.NoError(t, err)
testCases := []struct {
opts []stream.GetActivitiesOption
url string
enrichedURL string
}{
{
opts: []stream.GetActivitiesOption{
stream.WithExternalRankingVars(string(externalVarJSON)),
},
url: "https://api.stream-io-api.com/api/v1.0/feed/flat/123/?api_key=key&ranking_vars=%7B%22boolVal%22%3Atrue%2C%22music%22%3A1%2C%22sports%22%3A2.1%2C%22string%22%3A%22str%22%7D",
enrichedURL: "https://api.stream-io-api.com/api/v1.0/enrich/feed/flat/123/?api_key=key&ranking_vars=%7B%22boolVal%22%3Atrue%2C%22music%22%3A1%2C%22sports%22%3A2.1%2C%22string%22%3A%22str%22%7D",
},
}

for _, tc := range testCases {
_, err := flat.GetActivities(ctx, tc.opts...)
testRequest(t, requester.req, http.MethodGet, tc.url, "")
assert.NoError(t, err)
}
}

func TestFlatFeedGetNextPageActivities(t *testing.T) {
ctx := context.Background()
Expand Down
5 changes: 5 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ func WithRankingScoreVars() GetActivitiesOption {
return GetActivitiesOption{makeRequestOption("withScoreVars", true)}
}

// externalVarJSON should be valid json
func WithExternalRankingVars(externalVarJSON string) GetActivitiesOption {
return GetActivitiesOption{makeRequestOption("ranking_vars", externalVarJSON)}
}

// WithNotificationsMarkSeen marks as seen the given activity ids in a notification
// feed. If the all parameter is true, every activity in the feed is marked as seen.
func WithNotificationsMarkSeen(all bool, activityIDs ...string) GetActivitiesOption {
Expand Down