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
|
|
|
)
|
|
|
|
|
|
|
|
// PerformDelete does the actual delete via DELETE request.
|
|
|
|
func (c *Client) PerformDelete(url string) error {
|
|
|
|
req, err := http.NewRequest("DELETE", url, nil)
|
|
|
|
if err != nil {
|
|
|
|
return 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 err
|
|
|
|
}
|
|
|
|
|
|
|
|
//204 - resource deleted.
|
|
|
|
//202 - folder not empty, content will be deleted soon (async delete).
|
|
|
|
if resp.StatusCode != 204 && resp.StatusCode != 202 {
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-06-12 16:06:02 +02:00
|
|
|
return errors.Errorf("delete error [%d]: %s", resp.StatusCode, string(body[:]))
|
2015-12-07 05:01:03 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|