go-twitch/api/extensions/get_extension_bits_products.go

47 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package extensions
import (
"context"
"encoding/json"
"net/http"
"net/url"
"github.com/google/go-querystring/query"
)
type GetExtensionBitsProductsParams struct {
// A Boolean value that determines whether to include disabled or expired Bits products in the response. The default is false.
ShouldIncludeAll *bool `url:"should_include_all,omitempty"`
}
type GetExtensionBitsProductsResponse struct {
// A list that contains the specified Bits products.
Data []BitsProduct `json:"data"`
}
// Gets the list of Bits products that belongs to the extension. The client ID in the app access token identifies the extension.
//
// Requires an app access token. The client ID in the app access token must be the extensions client ID.
func (c *Extensions) GetExtensionBitsProducts(ctx context.Context, params *GetExtensionBitsProductsParams) (*GetExtensionBitsProductsResponse, error) {
v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "bits/extensions", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil {
return nil, err
}
res, err := c.client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
var data GetExtensionBitsProductsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}