2015-12-07 12:01:03 +08:00
|
|
|
package src
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"io"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
|
|
|
//CustomPropertyResponse struct we send and is returned by the API for CustomProperty request.
|
|
|
|
type CustomPropertyResponse struct {
|
|
|
|
CustomProperties map[string]interface{} `json:"custom_properties"`
|
|
|
|
}
|
|
|
|
|
|
|
|
//SetCustomProperty will set specified data from Yandex Disk
|
|
|
|
func (c *Client) SetCustomProperty(remotePath string, property string, value string) error {
|
|
|
|
rcm := map[string]interface{}{
|
|
|
|
property: value,
|
|
|
|
}
|
|
|
|
cpr := CustomPropertyResponse{rcm}
|
|
|
|
data, _ := json.Marshal(cpr)
|
|
|
|
body := bytes.NewReader(data)
|
|
|
|
err := c.SetCustomPropertyRequest(remotePath, body)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
//SetCustomPropertyRequest will make an CustomProperty request and return a URL to CustomProperty data to.
|
2015-12-30 21:30:57 +08:00
|
|
|
func (c *Client) SetCustomPropertyRequest(remotePath string, body io.Reader) (err error) {
|
2015-12-07 12:01:03 +08:00
|
|
|
values := url.Values{}
|
|
|
|
values.Add("path", remotePath)
|
|
|
|
req, err := c.scopedRequest("PATCH", "/v1/disk/resources?"+values.Encode(), body)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := c.HTTPClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := CheckAPIError(resp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-12-30 21:30:57 +08:00
|
|
|
defer CheckClose(resp.Body, &err)
|
2015-12-07 12:01:03 +08:00
|
|
|
|
|
|
|
//If needed we can read response and check if custom_property is set.
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|