2015-12-07 05:01:03 +01:00
|
|
|
package src
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
2016-06-12 16:06:02 +02:00
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2015-12-07 05:01:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// PerformMkdir does the actual mkdir via PUT request.
|
|
|
|
func (c *Client) PerformMkdir(url string) (int, string, error) {
|
|
|
|
req, err := http.NewRequest("PUT", url, nil)
|
|
|
|
if err != nil {
|
|
|
|
return 0, "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
//set access token and headers
|
|
|
|
c.setRequestScope(req)
|
|
|
|
|
2016-02-15 17:43:18 +01:00
|
|
|
resp, err := c.HTTPClient.Do(req)
|
2015-12-07 05:01:03 +01:00
|
|
|
if err != nil {
|
|
|
|
return 0, "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.StatusCode != 201 {
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return 0, "", err
|
|
|
|
}
|
|
|
|
//third parameter is the json error response body
|
2016-06-12 16:06:02 +02:00
|
|
|
return resp.StatusCode, string(body[:]), errors.Errorf("create folder error [%d]: %s", resp.StatusCode, string(body[:]))
|
2015-12-07 05:01:03 +01:00
|
|
|
}
|
|
|
|
return resp.StatusCode, "", nil
|
|
|
|
}
|