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