Add support for Field, Source and Locked parameters to AccountUpdate()
This commit is contained in:
parent
bb2662b33c
commit
68ca31fccd
33
accounts.go
33
accounts.go
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -38,6 +39,15 @@ type Field struct {
|
|||
VerifiedAt time.Time `json:"verified_at"`
|
||||
}
|
||||
|
||||
// Source is a Mastodon account profile field
|
||||
type Source struct {
|
||||
Privacy string `json:"privacy"`
|
||||
Sensitive *bool `json:"sensitive"`
|
||||
Language string `json:"language"`
|
||||
Note string `json:"note"`
|
||||
Fields *[]Field `json:"fields"`
|
||||
}
|
||||
|
||||
// GetAccount return Account.
|
||||
func (c *Client) GetAccount(ctx context.Context, id ID) (*Account, error) {
|
||||
var account Account
|
||||
|
@ -64,6 +74,9 @@ type Profile struct {
|
|||
// If it is empty, update it with empty.
|
||||
DisplayName *string
|
||||
Note *string
|
||||
Locked *bool
|
||||
Fields *[]Field
|
||||
Source *Source
|
||||
|
||||
// Set the base64 encoded character string of the image.
|
||||
Avatar string
|
||||
|
@ -79,6 +92,26 @@ func (c *Client) AccountUpdate(ctx context.Context, profile *Profile) (*Account,
|
|||
if profile.Note != nil {
|
||||
params.Set("note", *profile.Note)
|
||||
}
|
||||
if profile.Locked != nil {
|
||||
params.Set("locked", strconv.FormatBool(*profile.Locked))
|
||||
}
|
||||
if profile.Fields != nil {
|
||||
for idx, field := range *profile.Fields {
|
||||
params.Set(fmt.Sprintf("fields_attributes[%d][name]", idx), field.Name)
|
||||
params.Set(fmt.Sprintf("fields_attributes[%d][value]", idx), field.Value)
|
||||
}
|
||||
}
|
||||
if profile.Source != nil {
|
||||
if len(profile.Source.Privacy) > 0 {
|
||||
params.Set("source[privacy]", profile.Source.Privacy)
|
||||
}
|
||||
if profile.Source.Sensitive != nil {
|
||||
params.Set("source[sensitive]", strconv.FormatBool(*profile.Source.Sensitive))
|
||||
}
|
||||
if len(profile.Source.Language) > 0 {
|
||||
params.Set("source[language]", profile.Source.Language)
|
||||
}
|
||||
}
|
||||
if profile.Avatar != "" {
|
||||
params.Set("avatar", profile.Avatar)
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestGetAccount(t *testing.T) {
|
||||
|
@ -93,9 +94,15 @@ func TestAccountUpdate(t *testing.T) {
|
|||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
tbool := true
|
||||
fields := []Field{{"foo", "bar", time.Time{}}, {"dum", "baz", time.Time{}}}
|
||||
source := Source{Language: "de", Privacy: "public", Sensitive: &tbool}
|
||||
a, err := client.AccountUpdate(context.Background(), &Profile{
|
||||
DisplayName: String("display_name"),
|
||||
Note: String("note"),
|
||||
Locked: &tbool,
|
||||
Fields: &fields,
|
||||
Source: &source,
|
||||
Avatar: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUoAAADrCAYAAAA...",
|
||||
Header: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUoAAADrCAYAAAA...",
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user