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 | 0037e63 | 2015-01-19 11:15:58 -0700 | [diff] [blame] | 6 | "github.com/racker/perigee" |
| 7 | "github.com/rackspace/gophercloud" |
| 8 | ) |
| 9 | |
| 10 | // DeleteOptsBuilder allows extensions to add additional parameters to the Delete |
| 11 | // request. |
| 12 | type DeleteOptsBuilder interface { |
| 13 | ToCDNAssetDeleteParams() (string, error) |
| 14 | } |
| 15 | |
| 16 | // DeleteOpts is a structure that holds options for deleting CDN service assets. |
| 17 | type 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. |
| 26 | func (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 Perritt | c3bf9a7 | 2015-01-22 08:50:20 -0700 | [diff] [blame^] | 34 | // 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. |
| 38 | func 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 Perritt | 0037e63 | 2015-01-19 11:15:58 -0700 | [diff] [blame] | 46 | var res DeleteResult |
Jon Perritt | c3bf9a7 | 2015-01-22 08:50:20 -0700 | [diff] [blame^] | 47 | _, res.Err = perigee.Request("DELETE", url, perigee.Options{ |
Jon Perritt | 0037e63 | 2015-01-19 11:15:58 -0700 | [diff] [blame] | 48 | MoreHeaders: c.AuthenticatedHeaders(), |
| 49 | OkCodes: []int{202}, |
| 50 | }) |
| 51 | return res |
| 52 | } |