mirror of
https://github.com/bestnite/go-igdb.git
synced 2025-04-19 23:35:54 +08:00
27 lines
656 B
Go
27 lines
656 B
Go
package igdb
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"github/bestnite/go-igdb/endpoint"
|
|
)
|
|
|
|
func (g *igdb) ActiveWebhook(endpoint endpoint.Endpoint, secret, callbackUrl string) error {
|
|
dataBody := url.Values{}
|
|
dataBody.Set("url", callbackUrl)
|
|
dataBody.Set("secret", secret)
|
|
dataBody.Set("method", "update")
|
|
resp, err := g.Request(fmt.Sprintf("https://api.igdb.com/v4/%s/webhooks/", endpoint), dataBody.Encode())
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("failed to make request: %s: %w", callbackUrl, err)
|
|
}
|
|
|
|
if resp.StatusCode() == http.StatusOK {
|
|
return nil
|
|
}
|
|
return fmt.Errorf("failed to activate webhook: %s: %s", callbackUrl, resp.String())
|
|
}
|