mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
41 lines
1010 B
Go
41 lines
1010 B
Go
package codersdk
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
type NotificationsSettings struct {
|
|
NotifierPaused bool `json:"notifier_paused"`
|
|
}
|
|
|
|
func (c *Client) GetNotificationsSettings(ctx context.Context) (NotificationsSettings, error) {
|
|
res, err := c.Request(ctx, http.MethodGet, "/api/v2/notifications/settings", nil)
|
|
if err != nil {
|
|
return NotificationsSettings{}, err
|
|
}
|
|
defer res.Body.Close()
|
|
if res.StatusCode != http.StatusOK {
|
|
return NotificationsSettings{}, ReadBodyAsError(res)
|
|
}
|
|
var settings NotificationsSettings
|
|
return settings, json.NewDecoder(res.Body).Decode(&settings)
|
|
}
|
|
|
|
func (c *Client) PutNotificationsSettings(ctx context.Context, settings NotificationsSettings) error {
|
|
res, err := c.Request(ctx, http.MethodPut, "/api/v2/notifications/settings", settings)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer res.Body.Close()
|
|
|
|
if res.StatusCode == http.StatusNotModified {
|
|
return nil
|
|
}
|
|
if res.StatusCode != http.StatusOK {
|
|
return ReadBodyAsError(res)
|
|
}
|
|
return nil
|
|
}
|