Jon Perritt | 0037e63 | 2015-01-19 11:15:58 -0700 | [diff] [blame] | 1 | package serviceassets |
| 2 | |
| 3 | import ( |
Jon Perritt | c3bf9a7 | 2015-01-22 08:50:20 -0700 | [diff] [blame] | 4 | "strings" |
| 5 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 6 | "github.com/gophercloud/gophercloud" |
Jon Perritt | 0037e63 | 2015-01-19 11:15:58 -0700 | [diff] [blame] | 7 | ) |
| 8 | |
| 9 | // DeleteOptsBuilder allows extensions to add additional parameters to the Delete |
| 10 | // request. |
| 11 | type DeleteOptsBuilder interface { |
| 12 | ToCDNAssetDeleteParams() (string, error) |
| 13 | } |
| 14 | |
| 15 | // DeleteOpts is a structure that holds options for deleting CDN service assets. |
| 16 | type 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. |
| 25 | func (opts DeleteOpts) ToCDNAssetDeleteParams() (string, error) { |
| 26 | q, err := gophercloud.BuildQueryString(opts) |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 27 | return q.String(), err |
Jon Perritt | 0037e63 | 2015-01-19 11:15:58 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Jon Perritt | c3bf9a7 | 2015-01-22 08:50:20 -0700 | [diff] [blame] | 30 | // 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. |
| 34 | func Delete(c *gophercloud.ServiceClient, idOrURL string, opts DeleteOptsBuilder) DeleteResult { |
| 35 | var url string |
| 36 | if strings.Contains(idOrURL, "/") { |
| 37 | url = idOrURL |
| 38 | } else { |
| 39 | url = deleteURL(c, idOrURL) |
| 40 | } |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 41 | var r DeleteResult |
| 42 | if opts != nil { |
| 43 | q, err := opts.ToCDNAssetDeleteParams() |
| 44 | if err != nil { |
| 45 | r.Err = err |
| 46 | return r |
| 47 | } |
| 48 | url += q |
| 49 | } |
| 50 | _, r.Err = c.Delete(url, nil) |
| 51 | return r |
Jon Perritt | 0037e63 | 2015-01-19 11:15:58 -0700 | [diff] [blame] | 52 | } |