account.go
changeset 232 de13b1d39099
parent 231 741291bb4772
child 235 263da7f71f03
--- 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