UploadMedia: Add description and focus parameters
authorMikael Berthe <mikael@lilotux.net>
Tue, 20 Mar 2018 20:51:27 +0100
changeset 215 40ed4e2db3b9
parent 214 642d690de0ba
child 216 403ce36a94ab
UploadMedia: Add description and focus parameters
media.go
--- a/media.go	Tue Mar 20 19:20:31 2018 +0100
+++ b/media.go	Tue Mar 20 20:51:27 2018 +0100
@@ -19,7 +19,9 @@
 )
 
 // UploadMedia uploads the given file and returns an attachment
-func (mc *Client) UploadMedia(filePath string) (*Attachment, error) {
+// The description and focus arguments can be empty strings.
+// 'focus' is the "focal point", written as two comma-delimited floating points.
+func (mc *Client) UploadMedia(filePath, description, focus string) (*Attachment, error) {
 	var b bytes.Buffer
 
 	if filePath == "" {
@@ -43,7 +45,18 @@
 
 	w.Close()
 
-	req, err := mc.prepareRequest("media", rest.Post, nil)
+	var params apiCallParams
+	if description != "" || focus != "" {
+		params = make(apiCallParams)
+		if description != "" {
+			params["description"] = description
+		}
+		if focus != "" {
+			params["focus"] = focus
+		}
+	}
+
+	req, err := mc.prepareRequest("media", rest.Post, params)
 	if err != nil {
 		return nil, errors.Wrap(err, "media prepareRequest failed")
 	}