blob: 5248ef20c12992ec8784f9151bbd968a994d4f82 [file] [log] [blame]
Jon Perritt0037e632015-01-19 11:15:58 -07001package serviceassets
2
3import (
Jon Perrittc3bf9a72015-01-22 08:50:20 -07004 "strings"
5
Jon Perritt0037e632015-01-19 11:15:58 -07006 "github.com/racker/perigee"
7 "github.com/rackspace/gophercloud"
8)
9
10// DeleteOptsBuilder allows extensions to add additional parameters to the Delete
11// request.
12type DeleteOptsBuilder interface {
13 ToCDNAssetDeleteParams() (string, error)
14}
15
16// DeleteOpts is a structure that holds options for deleting CDN service assets.
17type DeleteOpts struct {
18 // If all is set to true, specifies that the delete occurs against all of the
19 // assets for the service.
20 All bool `q:"all"`
21 // Specifies the relative URL of the asset to be deleted.
22 URL string `q:"url"`
23}
24
25// ToCDNAssetDeleteParams formats a DeleteOpts into a query string.
26func (opts DeleteOpts) ToCDNAssetDeleteParams() (string, error) {
27 q, err := gophercloud.BuildQueryString(opts)
28 if err != nil {
29 return "", err
30 }
31 return q.String(), nil
32}
33
Jon Perrittc3bf9a72015-01-22 08:50:20 -070034// Delete accepts a unique service ID or URL and deletes the CDN service asset associated with
35// it. For example, both "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" and
36// "https://global.cdn.api.rackspacecloud.com/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0"
37// are valid options for idOrURL.
38func Delete(c *gophercloud.ServiceClient, idOrURL string, opts DeleteOptsBuilder) DeleteResult {
39 var url string
40 if strings.Contains(idOrURL, "/") {
41 url = idOrURL
42 } else {
43 url = deleteURL(c, idOrURL)
44 }
45
Jon Perritt0037e632015-01-19 11:15:58 -070046 var res DeleteResult
Jon Perrittc3bf9a72015-01-22 08:50:20 -070047 _, res.Err = perigee.Request("DELETE", url, perigee.Options{
Jon Perritt0037e632015-01-19 11:15:58 -070048 MoreHeaders: c.AuthenticatedHeaders(),
49 OkCodes: []int{202},
50 })
51 return res
52}