47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
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 extension’s 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
|
||
}
|