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 68
|
package linodego
import (
"context"
"encoding/json"
"time"
"github.com/linode/linodego/internal/parseabletime"
)
// Promotion represents a Promotion object
type Promotion struct {
// The amount available to spend per month.
CreditMonthlyCap string `json:"credit_monthly_cap"`
// The total amount of credit left for this promotion.
CreditRemaining string `json:"credit_remaining"`
// A detailed description of this promotion.
Description string `json:"description"`
// When this promotion's credits expire.
ExpirationDate *time.Time `json:"-"`
// The location of an image for this promotion.
ImageURL string `json:"image_url"`
// The service to which this promotion applies.
ServiceType string `json:"service_type"`
// Short details of this promotion.
Summary string `json:"summary"`
// The amount of credit left for this month for this promotion.
ThisMonthCreditRemaining string `json:"this_month_credit_remaining"`
}
// PromoCodeCreateOptions fields are those accepted by AddPromoCode
type PromoCodeCreateOptions struct {
// The Promo Code.
PromoCode string `json:"promo_code"`
}
// UnmarshalJSON implements the json.Unmarshaler interface
func (i *Promotion) UnmarshalJSON(b []byte) error {
type Mask Promotion
p := struct {
*Mask
ExpirationDate *parseabletime.ParseableTime `json:"date"`
}{
Mask: (*Mask)(i),
}
if err := json.Unmarshal(b, &p); err != nil {
return err
}
i.ExpirationDate = (*time.Time)(p.ExpirationDate)
return nil
}
// AddPromoCode adds the provided promo code to the account
func (c *Client) AddPromoCode(ctx context.Context, opts PromoCodeCreateOptions) (*Promotion, error) {
return doPOSTRequest[Promotion](ctx, c, "account/promo-codes", opts)
}
|