blob: 80c908fd9d92b218ab9bebdbfdbbdaf0d6d5ae9f [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 Perritt27249f42016-02-18 10:35:59 -06006 "github.com/gophercloud/gophercloud"
Jon Perritt0037e632015-01-19 11:15:58 -07007)
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)
Jon Perrittdb0ae142016-03-13 00:33:41 -060027 return q.String(), err
Jon Perritt0037e632015-01-19 11:15:58 -070028}
29
Jon Perrittc3bf9a72015-01-22 08:50:20 -070030// Delete accepts a unique service ID or URL and deletes the CDN service asset associated with
31// it. For example, both "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" and
32// "https://global.cdn.api.rackspacecloud.com/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0"
33// are valid options for idOrURL.
Jon Perritt3860b512016-03-29 12:01:48 -050034func Delete(c *gophercloud.ServiceClient, idOrURL string, opts DeleteOptsBuilder) (r DeleteResult) {
Jon Perrittc3bf9a72015-01-22 08:50:20 -070035 var url string
36 if strings.Contains(idOrURL, "/") {
37 url = idOrURL
38 } else {
39 url = deleteURL(c, idOrURL)
40 }
Jon Perrittdb0ae142016-03-13 00:33:41 -060041 if opts != nil {
42 q, err := opts.ToCDNAssetDeleteParams()
43 if err != nil {
44 r.Err = err
Jon Perritt3860b512016-03-29 12:01:48 -050045 return
Jon Perrittdb0ae142016-03-13 00:33:41 -060046 }
47 url += q
48 }
49 _, r.Err = c.Delete(url, nil)
jrperritt29ae6b32016-04-13 12:59:37 -050050 return
Jon Perritt0037e632015-01-19 11:15:58 -070051}