go-twitch/api/entitlements/update_drops_entitlements.go

71 lines
2.3 KiB
Go
Raw Normal View History

2024-02-28 14:25:19 -05:00
package entitlements
import (
"context"
"encoding/json"
"io"
"net/http"
"net/url"
)
type UpdateDropsEntitlementsRequest struct {
// A list of IDs that identify the entitlements to update. You may specify a maximum of 100 IDs.
EntitlementIDs *[]string `json:"entitlement_ids,omitempty"`
// The fulfillment status to set the entitlements to.
FulfillmentStatus *FulfillmentStatus `json:"fulfillment_status,omitempty"`
}
type UpdateDropsEntitlementsResponse struct {
// A list that indicates which entitlements were successfully updated and those that werent.
Data []UpdateDropsEntitlementsData `json:"data"`
}
type UpdateDropsEntitlementsData struct {
// A string that indicates whether the status of the entitlements in the ids field were successfully updated.
Status UpdateStatus `json:"status"`
// The list of entitlements that the status in the status field applies to.
IDs []string `json:"ids"`
}
// Updates the Drop entitlements fulfillment status.
//
// The following table identifies which entitlements are updated based on the type of access token used.
// Access token type | Data thats updated
// ------------------|------------------------------------------------------------------------------------------------------------------------------------------
// App | Updates all entitlements with benefits owned by the organization in the access token.
// User | Updates all entitlements owned by the user in the access token and where the benefits are owned by the organization in the access token.
//
// Requires an app access token or user access token. The client ID in the access token must own the game.
func (c *Entitlements) UpdateDropsEntitlements(ctx context.Context, request *UpdateDropsEntitlementsRequest) (*UpdateDropsEntitlementsResponse, error) {
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "entitlements/drops"})
r, w := io.Pipe()
go func() {
if err := json.NewEncoder(w).Encode(request); err != nil {
w.CloseWithError(err)
} else {
w.Close()
}
}()
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r)
if err != nil {
return nil, err
}
res, err := c.client.Do(req)
if err != nil {
return nil, err
}
var data UpdateDropsEntitlementsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}