# HG changeset patch # User Mikael Berthe # Date 1536107603 -7200 # Node ID de13b1d390992d93516079d14ffbe4bad06dce63 # Parent 741291bb47728844bc18996e4a67aef992f0a4c8 UpdateAccount: Add support for FieldsAttributes and Source parameters The source parameters don't seem to work, though (tested against Mastodon 2.5.0)... diff -r 741291bb4772 -r de13b1d39099 account.go --- a/account.go Wed Sep 05 02:33:23 2018 +0200 +++ b/account.go Wed Sep 05 02:33:23 2018 +0200 @@ -35,14 +35,14 @@ // UpdateAccountParams contains option fields for the UpdateAccount command type UpdateAccountParams struct { - DisplayName *string - Note *string - AvatarImagePath *string - HeaderImagePath *string - Locked *bool - Bot *bool - //FieldsAttributes *[]Field - //Source *SourceParams + DisplayName *string + Note *string + AvatarImagePath *string + HeaderImagePath *string + Locked *bool + Bot *bool + FieldsAttributes *[]Field + Source *SourceParams } // updateRelationship returns a Relationship entity @@ -447,6 +447,24 @@ params["bot"] = "false" } } + if cmdParams.FieldsAttributes != nil { + if len(*cmdParams.FieldsAttributes) > 4 { + return nil, errors.New("too many fields (max=4)") + } + for i, attr := range *cmdParams.FieldsAttributes { + qName := fmt.Sprintf("fields_attributes[%d][name]", i) + qValue := fmt.Sprintf("fields_attributes[%d][value]", i) + params[qName] = attr.Name + params[qValue] = attr.Value + } + } + if cmdParams.Source != nil { + sourceJSON, err := json.Marshal(*cmdParams.Source) + if err != nil { + return nil, errors.Wrap(err, "could not encode source data") + } + params["source"] = string(sourceJSON) + } var err error var avatar, headerImage []byte diff -r 741291bb4772 -r de13b1d39099 types.go --- a/types.go Wed Sep 05 02:33:23 2018 +0200 +++ b/types.go Wed Sep 05 02:33:23 2018 +0200 @@ -257,9 +257,9 @@ // SourceParams is a source params structure type SourceParams struct { // Used for verify_credentials - Privacy *string `json:"privacy"` - Language *string `json:"language"` - Sensitive *bool `json:"sensitive"` - Note *string `json:"note"` - Fields *[]Field `json:"fields"` + Privacy *string `json:"privacy,omitempty"` + Language *string `json:"language,omitempty"` + Sensitive *bool `json:"sensitive,omitempty"` + Note *string `json:"note,omitempty"` + Fields *[]Field `json:"fields,omitempty"` }