|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2012-2014 Rackspace US, Inc. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +namespace OpenCloud\CDN; |
| 19 | + |
| 20 | +use OpenCloud\Common\Service\CatalogService; |
| 21 | +use OpenCloud\Common\Http\Message\Formatter; |
| 22 | +use OpenCloud\CDN\Resource\Service as ServiceResource; |
| 23 | +use OpenCloud\CDN\Resource\Flavor; |
| 24 | + |
| 25 | +/** |
| 26 | + * The CDN class represents the OpenStack Poppy service. |
| 27 | + * |
| 28 | + * Poppy is a service that abstracts various CDN providers APIs |
| 29 | + */ |
| 30 | +class Service extends CatalogService |
| 31 | +{ |
| 32 | + const SUPPORTED_VERSION = 'v1.0'; |
| 33 | + const DEFAULT_TYPE = 'cdn'; |
| 34 | + const DEFAULT_NAME = 'rackCDN'; |
| 35 | + |
| 36 | + protected $regionless = true; |
| 37 | + |
| 38 | + /** |
| 39 | + * Returns a Service object associated with this CDN service |
| 40 | + * |
| 41 | + * @param string $id ID of service to retrieve |
| 42 | + * @return \OpenCloud\CDN\Resource\Service object |
| 43 | + */ |
| 44 | + public function service($id = null) |
| 45 | + { |
| 46 | + return $this->resource('Service', $id); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Creates a new Service and returns it. |
| 51 | + * |
| 52 | + * @param array $params Service creation parameters. @see https://github.com/rackspace/php-opencloud/blob/master/docs/userguide/CDN/USERGUIDE.md#create-a-service |
| 53 | + * @return \OpenCloud\CDN\Resource\Service Object representing created service |
| 54 | + */ |
| 55 | + public function createService(array $params = array()) |
| 56 | + { |
| 57 | + $service = $this->service(); |
| 58 | + $service->create($params); |
| 59 | + return $service; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Returns a Service object associated with this CDN service |
| 64 | + * |
| 65 | + * @param string $id ID of service to retrieve |
| 66 | + * @return \OpenCloud\CDN\Resource\Service object |
| 67 | + */ |
| 68 | + public function getService($id) |
| 69 | + { |
| 70 | + return $this->service($id); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Returns a list of services you created |
| 75 | + * |
| 76 | + * @param array $params |
| 77 | + * @return \OpenCloud\Common\Collection\PaginatedIterator |
| 78 | + */ |
| 79 | + public function listServices(array $params = array()) |
| 80 | + { |
| 81 | + $url = clone $this->getUrl(); |
| 82 | + $url->addPath(ServiceResource::resourceName())->setQuery($params); |
| 83 | + |
| 84 | + return $this->resourceList('Service', $url); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Returns a Flavor object associated with this CDN service |
| 89 | + * |
| 90 | + * @param string $id ID of flavor to retrieve |
| 91 | + * @return \OpenCloud\CDN\Resource\Flavor object |
| 92 | + */ |
| 93 | + public function flavor($id = null) |
| 94 | + { |
| 95 | + return $this->resource('Flavor', $id); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Creates a new Flavor and returns it. |
| 100 | + * |
| 101 | + * @param array $params Flavor creation parameters. @see https://github.com/rackspace/php-opencloud/blob/master/docs/userguide/CDN/USERGUIDE.md#create-a-flavor |
| 102 | + * @return \OpenCloud\CDN\Resource\Flavor Object representing created flavor |
| 103 | + */ |
| 104 | + public function createFlavor(array $params = array()) |
| 105 | + { |
| 106 | + $flavor = $this->flavor(); |
| 107 | + $flavor->create($params); |
| 108 | + return $flavor; |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * Returns a Flavor object associated with this CDN service |
| 113 | + * |
| 114 | + * @param string $id ID of flavor to retrieve |
| 115 | + * @return \OpenCloud\CDN\Resource\Flavor object |
| 116 | + */ |
| 117 | + public function getFlavor($id) |
| 118 | + { |
| 119 | + return $this->flavor($id); |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * Returns a list of flavors you created |
| 124 | + * |
| 125 | + * @param array $params |
| 126 | + * @return \OpenCloud\Common\Collection\PaginatedIterator |
| 127 | + */ |
| 128 | + public function listFlavors(array $params = array()) |
| 129 | + { |
| 130 | + $url = clone $this->getUrl(); |
| 131 | + $url->addPath(Flavor::resourceName())->setQuery($params); |
| 132 | + |
| 133 | + return $this->resourceList('Flavor', $url); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * Return namespaces. |
| 138 | + * |
| 139 | + * @return array |
| 140 | + */ |
| 141 | + public function namespaces() |
| 142 | + { |
| 143 | + return array(); |
| 144 | + } |
| 145 | +} |
0 commit comments