go-slack-scimapi

Slack SCIM API client for Golang

MIT License

Stars
1

go-slack-scimapi

Slack SCIM API client for Golang

https://api.slack.com/scim

How to use

Create a client

client := scim.NewClient("Slack API Token")

Get users

Note that returned *http.Response.Body is closed.

ctx := context.Background()
users, resp, err := client.GetUsers(ctx, nil, "")

Pagination

users, resp, err := client.GetUsers(ctx, &scim.Pagination{
	Count: 5000,
	StartInex: 1,
}, "")

Filter

users, resp, err := client.GetUsers(ctx, nil, `email eq "[email protected]"`)

Customize response handling

You can customize client's behavior with methods Client.WithXXX and Client.SetXXX . Client.SetXXX changes the receiver itself. On the other hand, Client.WithXXX changes a shallow copy of client and returns it. Client.WithXXX is useful for the method chain.

client.SetParseResp(func(resp *http.Response, output interface{}) error {
	b, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	fmt.Println(string(b))
	return json.Unmarshal(b, output)
})
users, resp, err := client.WithParseErrorResp(func(resp *http.Response) error {
	fmt.Println("customize")
	return ParseErrorRespDefault(resp)
}).GetUsers(ctx, nil, "")

client.XXXResp

Client.GetUsers parses response body and returns users. On the other hand, Client.GetUsersResp doesn't parse response body. Returned response body is open.

resp, err := client.GetUsersResp(ctx, nil, "")
if err != nil {
	log.Fatal(err)
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
resp, err := client.CreateUser(ctx, &scim.User{
	UserName: "foo",
	Emails: []scim.Email{
		Value: "[email protected]",
	},
})

License

MIT

Package Rankings
Top 8.17% on Proxy.golang.org
Badges
Extracted from project README
GoDoc Build Status codecov Go Report Card GitHub last commit GitHub tag License