blob: 0a5b0737a2bf1058a5c52c381a75d70e2df02440 [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/rackspace/gophercloud"
7)
8
9// DeleteOptsBuilder allows extensions to add additional parameters to the Delete
10// request.
11type DeleteOptsBuilder interface {
12 ToCDNAssetDeleteParams() (string, error)
13}
14
15// DeleteOpts is a structure that holds options for deleting CDN service assets.
16type DeleteOpts struct {
17 // If all is set to true, specifies that the delete occurs against all of the
18 // assets for the service.
19 All bool `q:"all"`
20 // Specifies the relative URL of the asset to be deleted.
21 URL string `q:"url"`
22}
23
24// ToCDNAssetDeleteParams formats a DeleteOpts into a query string.
25func (opts DeleteOpts) ToCDNAssetDeleteParams() (string, error) {
26 q, err := gophercloud.BuildQueryString(opts)
27 if err != nil {
28 return "", err
29 }
30 return q.String(), nil
31}
32
Jon Perrittc3bf9a72015-01-22 08:50:20 -070033// Delete accepts a unique service ID or URL and deletes the CDN service asset associated with
34// it. For example, both "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" and
35// "https://global.cdn.api.rackspacecloud.com/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0"
36// are valid options for idOrURL.
37func Delete(c *gophercloud.ServiceClient, idOrURL string, opts DeleteOptsBuilder) DeleteResult {
38 var url string
39 if strings.Contains(idOrURL, "/") {
40 url = idOrURL
41 } else {
42 url = deleteURL(c, idOrURL)
43 }
44
Jon Perritt0037e632015-01-19 11:15:58 -070045 var res DeleteResult
Jamie Hannafordc530ba12015-03-23 17:50:46 +010046 _, res.Err = c.Request("DELETE", url, gophercloud.RequestOpts{})
Jon Perritt0037e632015-01-19 11:15:58 -070047 return res
48}