Skip to content

Commit

Permalink
add support for async export users endpoint (#298)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JimmyPettersson85 authored Feb 24, 2025
1 parent 373c7ff commit 0d6b3de
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @yaziine @totalimmersion @akupila @JimmyPettersson85
* @totalimmersion @JimmyPettersson85
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
max-parallel: 3
fail-fast: false
matrix:
goVer: ['1.18', '1.19', '1.20', '1.21', '1.22', '1.23']
goVer: ['1.22', '1.23', '1.24']
steps:
- uses: actions/checkout@v4

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.18"
go-version: "1.22"

- name: Tidy
run: go mod tidy -v && git diff --no-patch --exit-code || { git status; echo 'Unchecked diff, did you forget go mod tidy again?' ; false ; };
2 changes: 1 addition & 1 deletion .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.18'
go-version: '1.22'

- name: Install golangci-lint
run: make install-golangci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scheduled_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

- uses: actions/setup-go@v3
with:
go-version: "1.18"
go-version: "1.22"

- name: Run tests
env:
Expand Down
18 changes: 18 additions & 0 deletions async_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,21 @@ func (c *Client) GetExportChannelsTask(ctx context.Context, taskID string) (*Tas
err := c.makeRequest(ctx, http.MethodGet, p, nil, nil, &task)
return &task, err
}

// ExportUsers requests an asynchronous export of the provided user IDs.
// It returns an AsyncTaskResponse object which contains the task ID, the status of the task can be check with client.GetTask method.
func (c *Client) ExportUsers(ctx context.Context, userIDs []string) (*AsyncTaskResponse, error) {
if len(userIDs) == 0 {
return nil, errors.New("number of user IDs must be at least one")
}

req := struct {
UserIDs []string `json:"user_ids"`
}{
UserIDs: userIDs,
}

var resp AsyncTaskResponse
err := c.makeRequest(ctx, http.MethodPost, "export/users", nil, req, &resp)
return &resp, err
}
31 changes: 31 additions & 0 deletions async_tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,34 @@ func TestClient_ExportChannels(t *testing.T) {
}
})
}

func TestClient_ExportUsers(t *testing.T) {
c := initClient(t)
ch1 := initChannel(t, c)
ctx := context.Background()

t.Run("Return error if there are 0 user IDs", func(t *testing.T) {
_, err := c.ExportUsers(ctx, nil)
require.Error(t, err)
})

t.Run("Export users with no error", func(t *testing.T) {
resp, err := c.ExportUsers(ctx, []string{ch1.CreatedBy.ID})
require.NoError(t, err)
require.NotEmpty(t, resp.TaskID)

for i := 0; i < 10; i++ {
task, err := c.GetTask(ctx, resp.TaskID)
require.NoError(t, err)
require.Equal(t, resp.TaskID, task.TaskID)
require.NotEmpty(t, task.Status)

if task.Status == TaskStatusCompleted {
require.Contains(t, task.Result["url"], "/exports/users/")
break
}

time.Sleep(time.Second)
}
})
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/GetStream/stream-chat-go/v7

go 1.18
go 1.22

require (
github.com/golang-jwt/jwt/v4 v4.0.0
github.com/golang-jwt/jwt/v4 v4.5.1
github.com/stretchr/testify v1.7.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang-jwt/jwt/v4 v4.0.0 h1:RAqyYixv1p7uEnocuy8P1nru5wprCh/MH2BIlW5z5/o=
github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down

0 comments on commit 0d6b3de

Please sign in to comment.