profile_preferences.go raw

   1  package linodego
   2  
   3  import (
   4  	"context"
   5  	"encoding/json"
   6  )
   7  
   8  // ProfilePreferences represents the user's preferences.
   9  // The user preferences endpoints allow consumers of the API to store arbitrary JSON data,
  10  // such as a user's font size preference or preferred display name.
  11  type ProfilePreferences map[string]any
  12  
  13  // UnmarshalJSON implements the json.Unmarshaler interface
  14  func (p *ProfilePreferences) UnmarshalJSON(b []byte) error {
  15  	var data map[string]any
  16  	if err := json.Unmarshal(b, &data); err != nil {
  17  		return err
  18  	}
  19  
  20  	*p = data
  21  
  22  	return nil
  23  }
  24  
  25  // GetProfilePreferences retrieves the user preferences for the current User
  26  func (c *Client) GetProfilePreferences(ctx context.Context) (*ProfilePreferences, error) {
  27  	return doGETRequest[ProfilePreferences](ctx, c, "profile/preferences")
  28  }
  29  
  30  // UpdateProfilePreferences updates the user's preferences with the provided data
  31  func (c *Client) UpdateProfilePreferences(ctx context.Context, opts ProfilePreferences) (*ProfilePreferences, error) {
  32  	return doPUTRequest[ProfilePreferences](ctx, c, "profile/preferences", opts)
  33  }
  34