1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
package linodego
import (
"context"
"encoding/json"
"time"
"github.com/linode/linodego/internal/parseabletime"
)
// The details and enrollment information of a Beta program that an account is enrolled in.
type AccountBetaProgram struct {
Label string `json:"label"`
ID string `json:"id"`
Description string `json:"description"`
Started *time.Time `json:"-"`
Ended *time.Time `json:"-"`
// Date the account was enrolled in the beta program
Enrolled *time.Time `json:"-"`
}
// AccountBetaProgramCreateOpts fields are those accepted by JoinBetaProgram
type AccountBetaProgramCreateOpts struct {
ID string `json:"id"`
}
// UnmarshalJSON implements the json.Unmarshaler interface
func (cBeta *AccountBetaProgram) UnmarshalJSON(b []byte) error {
type Mask AccountBetaProgram
p := struct {
*Mask
Started *parseabletime.ParseableTime `json:"started"`
Ended *parseabletime.ParseableTime `json:"ended"`
Enrolled *parseabletime.ParseableTime `json:"enrolled"`
}{
Mask: (*Mask)(cBeta),
}
if err := json.Unmarshal(b, &p); err != nil {
return err
}
cBeta.Started = (*time.Time)(p.Started)
cBeta.Ended = (*time.Time)(p.Ended)
cBeta.Enrolled = (*time.Time)(p.Enrolled)
return nil
}
// ListAccountBetaPrograms lists all beta programs an account is enrolled in.
func (c *Client) ListAccountBetaPrograms(ctx context.Context, opts *ListOptions) ([]AccountBetaProgram, error) {
return getPaginatedResults[AccountBetaProgram](ctx, c, "/account/betas", opts)
}
// GetAccountBetaProgram gets the details of a beta program an account is enrolled in.
func (c *Client) GetAccountBetaProgram(ctx context.Context, betaID string) (*AccountBetaProgram, error) {
e := formatAPIPath("/account/betas/%s", betaID)
return doGETRequest[AccountBetaProgram](ctx, c, e)
}
// JoinBetaProgram enrolls an account into a beta program.
func (c *Client) JoinBetaProgram(ctx context.Context, opts AccountBetaProgramCreateOpts) (*AccountBetaProgram, error) {
return doPOSTRequest[AccountBetaProgram](ctx, c, "account/betas", opts)
}
|