Skip to content

Commit 0d6b3de

Browse files
add support for async export users endpoint (#298)
* add support for async export users endpoint * fix CODEOWNERS and add go 1.24 * bump to 1.22, change test versions, update deps * bump go verisons in other workflow files
1 parent 373c7ff commit 0d6b3de

File tree

9 files changed

+58
-9
lines changed

9 files changed

+58
-9
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @yaziine @totalimmersion @akupila @JimmyPettersson85
1+
* @totalimmersion @JimmyPettersson85

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
max-parallel: 3
1818
fail-fast: false
1919
matrix:
20-
goVer: ['1.18', '1.19', '1.20', '1.21', '1.22', '1.23']
20+
goVer: ['1.22', '1.23', '1.24']
2121
steps:
2222
- uses: actions/checkout@v4
2323

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Setup Go
2020
uses: actions/setup-go@v5
2121
with:
22-
go-version: "1.18"
22+
go-version: "1.22"
2323

2424
- name: Tidy
2525
run: go mod tidy -v && git diff --no-patch --exit-code || { git status; echo 'Unchecked diff, did you forget go mod tidy again?' ; false ; };

.github/workflows/reviewdog.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Setup Go
2121
uses: actions/setup-go@v5
2222
with:
23-
go-version: '1.18'
23+
go-version: '1.22'
2424

2525
- name: Install golangci-lint
2626
run: make install-golangci

.github/workflows/scheduled_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
- uses: actions/setup-go@v3
1616
with:
17-
go-version: "1.18"
17+
go-version: "1.22"
1818

1919
- name: Run tests
2020
env:

async_tasks.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,21 @@ func (c *Client) GetExportChannelsTask(ctx context.Context, taskID string) (*Tas
176176
err := c.makeRequest(ctx, http.MethodGet, p, nil, nil, &task)
177177
return &task, err
178178
}
179+
180+
// ExportUsers requests an asynchronous export of the provided user IDs.
181+
// It returns an AsyncTaskResponse object which contains the task ID, the status of the task can be check with client.GetTask method.
182+
func (c *Client) ExportUsers(ctx context.Context, userIDs []string) (*AsyncTaskResponse, error) {
183+
if len(userIDs) == 0 {
184+
return nil, errors.New("number of user IDs must be at least one")
185+
}
186+
187+
req := struct {
188+
UserIDs []string `json:"user_ids"`
189+
}{
190+
UserIDs: userIDs,
191+
}
192+
193+
var resp AsyncTaskResponse
194+
err := c.makeRequest(ctx, http.MethodPost, "export/users", nil, req, &resp)
195+
return &resp, err
196+
}

async_tasks_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,34 @@ func TestClient_ExportChannels(t *testing.T) {
124124
}
125125
})
126126
}
127+
128+
func TestClient_ExportUsers(t *testing.T) {
129+
c := initClient(t)
130+
ch1 := initChannel(t, c)
131+
ctx := context.Background()
132+
133+
t.Run("Return error if there are 0 user IDs", func(t *testing.T) {
134+
_, err := c.ExportUsers(ctx, nil)
135+
require.Error(t, err)
136+
})
137+
138+
t.Run("Export users with no error", func(t *testing.T) {
139+
resp, err := c.ExportUsers(ctx, []string{ch1.CreatedBy.ID})
140+
require.NoError(t, err)
141+
require.NotEmpty(t, resp.TaskID)
142+
143+
for i := 0; i < 10; i++ {
144+
task, err := c.GetTask(ctx, resp.TaskID)
145+
require.NoError(t, err)
146+
require.Equal(t, resp.TaskID, task.TaskID)
147+
require.NotEmpty(t, task.Status)
148+
149+
if task.Status == TaskStatusCompleted {
150+
require.Contains(t, task.Result["url"], "/exports/users/")
151+
break
152+
}
153+
154+
time.Sleep(time.Second)
155+
}
156+
})
157+
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module github.com/GetStream/stream-chat-go/v7
22

3-
go 1.18
3+
go 1.22
44

55
require (
6-
github.com/golang-jwt/jwt/v4 v4.0.0
6+
github.com/golang-jwt/jwt/v4 v4.5.1
77
github.com/stretchr/testify v1.7.0
88
)
99

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
22
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
33
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4-
github.com/golang-jwt/jwt/v4 v4.0.0 h1:RAqyYixv1p7uEnocuy8P1nru5wprCh/MH2BIlW5z5/o=
5-
github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
4+
github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
5+
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
66
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
77
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
88
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

0 commit comments

Comments
 (0)