2024-03-02 22:45:59 -05:00
|
|
|
package extensions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
2024-03-07 19:41:05 -05:00
|
|
|
"fmt"
|
2024-03-02 22:45:59 -05:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/google/go-querystring/query"
|
|
|
|
)
|
|
|
|
|
|
|
|
type GetReleasedExtensionsParams struct {
|
|
|
|
// The ID of the extension to get.
|
|
|
|
ExtensionID string `url:"extension_id"`
|
|
|
|
|
|
|
|
// The version of the extension to get. If not specified, it returns the latest, released version.
|
|
|
|
ExtensionVersion *string `url:"extension_version,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type GetReleasedExtensionsResponse struct {
|
|
|
|
// A list that contains the specified extension.
|
|
|
|
Data []Extension `json:"data"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gets information about a released extension. Returns the extension if its state is Released.
|
|
|
|
//
|
|
|
|
// Requires an app access token or user access token.
|
|
|
|
func (c *Extensions) GetReleasedExtensions(ctx context.Context, params *GetReleasedExtensionsParams) (*GetReleasedExtensionsResponse, error) {
|
|
|
|
v, _ := query.Values(params)
|
|
|
|
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/released", 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()
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
if !statusOK {
|
|
|
|
return nil, fmt.Errorf("failed to get released extensions (%d)", res.StatusCode)
|
|
|
|
}
|
|
|
|
|
2024-03-02 22:45:59 -05:00
|
|
|
var data GetReleasedExtensionsResponse
|
|
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &data, nil
|
|
|
|
}
|