diff --git a/README.md b/README.md index d62ab663..026dc54a 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,14 @@ TODO - [x] [Actions](https://github.com/digitaloceancloud/api-v2-docs#actions) - [ ] [Domain records](https://github.com/digitaloceancloud/api-v2-docs#domain-records) -- [ ] [Domains](https://github.com/digitaloceancloud/api-v2-docs#domains) +- [x] [Domains](https://github.com/digitaloceancloud/api-v2-docs#domains) - [ ] [Droplet actions](https://github.com/digitaloceancloud/api-v2-docs#droplet-actions) - [ ] [Droplets](https://github.com/digitaloceancloud/api-v2-docs#droplets) - [x] [Image actions](https://github.com/digitaloceancloud/api-v2-docs#image-actions) - [x] [Images](https://github.com/digitaloceancloud/api-v2-docs#images) - [ ] [Keys](https://github.com/digitaloceancloud/api-v2-docs#keys) -- [ ] [Regions](https://github.com/digitaloceancloud/api-v2-docs#regions) +- [x] [Regions](https://github.com/digitaloceancloud/api-v2-docs#regions) +- [x] [Sizes](https://github.com/digitaloceancloud/api-v2-docs#sizes) Installation ------------ diff --git a/src/Api/Domain.php b/src/Api/Domain.php new file mode 100644 index 00000000..13aeb330 --- /dev/null +++ b/src/Api/Domain.php @@ -0,0 +1,76 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace DigitalOceanV2\Api; + +use DigitalOceanV2\Entity\Domain as DomainEntity; + +/** + * @author Yassir Hannoun + */ +class Domain extends AbstractApi +{ + /** + * @return DomainEntity[] + */ + public function getAll() + { + $domains = $this->adapter->get(sprintf("%s/domains", self::ENDPOINT)); + $domains = json_decode($domains); + + $results = array(); + foreach ($domains->domains as $domain) { + $results[] = new DomainEntity($domain); + } + + return $results; + } + + /** + * @param string $domainName + * @throws \RuntimeException + * @return DomainEntity + */ + public function getByName($domainName) + { + $domain = $this->adapter->get(sprintf("%s/domains/%s", self::ENDPOINT, $domainName)); + $domain = json_decode($domain); + + return new DomainEntity($domain->domain); + } + + /** + * @param string $name + * @param string $ipAddress + * @throws \RuntimeException + * @return DomainEntity + */ + public function create($name, $ipAddress) + { + $headers = array('Content-Type: application/json'); + $content = sprintf('{"name":"%s", "ip_address":"%s"}', $name, $ipAddress); + + $domain = $this->adapter->post(sprintf("%s/domains/", self::ENDPOINT), $headers, $content); + $domain = json_decode($domain); + + return new DomainEntity($domain->domain); + } + + /** + * @param integer $domain + * @throws \RuntimeException + */ + public function delete($domain) + { + $headers = array('Content-Type: application/x-www-form-urlencoded'); + $this->adapter->delete(sprintf("%s/domains/%s", self::ENDPOINT, $domain), $headers); + } +} diff --git a/src/Api/Region.php b/src/Api/Region.php new file mode 100644 index 00000000..02c74c8f --- /dev/null +++ b/src/Api/Region.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace DigitalOceanV2\Api; + +use DigitalOceanV2\Entity\Region as RegionEntity; + +/** + * @author Yassir Hannoun + */ +class Region extends AbstractApi +{ + /** + * @return RegionEntity[] + */ + public function getAll() + { + $regions = $this->adapter->get(sprintf("%s/regions", self::ENDPOINT)); + $regions = json_decode($regions); + + $results = array(); + foreach ($regions->regions as $region) { + $results[] = new RegionEntity($region); + } + + return $results; + } +} diff --git a/src/Api/Size.php b/src/Api/Size.php new file mode 100644 index 00000000..899019a1 --- /dev/null +++ b/src/Api/Size.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace DigitalOceanV2\Api; + +use DigitalOceanV2\Entity\Size as SizeEntity; + +/** + * @author Yassir Hannoun + */ +class Size extends AbstractApi +{ + /** + * @return SizeEntity[] + */ + public function getAll() + { + $sizes = $this->adapter->get(sprintf("%s/sizes", self::ENDPOINT)); + $sizes = json_decode($sizes); + + $results = array(); + foreach ($sizes->sizes as $size) { + $results[] = new SizeEntity($size); + } + + return $results; + } +} diff --git a/src/DigitalOceanV2.php b/src/DigitalOceanV2.php index 2424279d..876b7f4e 100644 --- a/src/DigitalOceanV2.php +++ b/src/DigitalOceanV2.php @@ -11,9 +11,12 @@ namespace DigitalOceanV2; -use DigitalOceanV2\Api\Action; use DigitalOceanV2\Adapter\AdapterInterface; +use DigitalOceanV2\Api\Action; +use DigitalOceanV2\Api\Domain; use DigitalOceanV2\Api\Image; +use DigitalOceanV2\Api\Region; +use DigitalOceanV2\Api\Size; /** * @author Antoine Corcy @@ -53,4 +56,28 @@ public function image() { return new Image($this->adapter); } + + /** + * @return Domain + */ + public function domain() + { + return new Domain($this->adapter); + } + + /** + * @return Size + */ + public function size() + { + return new Size($this->adapter); + } + + /** + * @return Region + */ + public function region() + { + return new Region($this->adapter); + } } diff --git a/src/Entity/Domain.php b/src/Entity/Domain.php new file mode 100644 index 00000000..028e802b --- /dev/null +++ b/src/Entity/Domain.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace DigitalOceanV2\Entity; + +/** + * @author Yassir Hannoun + */ +class Domain extends AbstractEntity +{ + /** + * @var string + */ + public $name; + + /** + * @var string + */ + public $ttl; + + /** + * @var string + */ + public $zoneFile; +} diff --git a/src/Entity/Region.php b/src/Entity/Region.php new file mode 100644 index 00000000..fbef24ff --- /dev/null +++ b/src/Entity/Region.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace DigitalOceanV2\Entity; + +/** + * @author Yassir Hannoun + */ +class Region extends AbstractEntity +{ + /** + * @var string + */ + public $slug; + + /** + * @var string + */ + public $name; + + /** + * @var boolean + */ + public $available; + + /** + * @var Size[] + */ + public $sizes; +} diff --git a/src/Entity/Size.php b/src/Entity/Size.php new file mode 100644 index 00000000..b1c34229 --- /dev/null +++ b/src/Entity/Size.php @@ -0,0 +1,58 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace DigitalOceanV2\Entity; + +/** + * @author Yassir Hannoun + */ +class Size extends AbstractEntity +{ + /** + * @var string + */ + public $slug; + + /** + * @var integer + */ + public $memory; + + /** + * @var integer + */ + public $vcpus; + + /** + * @var integer + */ + public $disk; + + /** + * @var integer + */ + public $transfer; + + /** + * @var integer + */ + public $priceMonthly; + + /** + * @var integer + */ + public $priceHourly; + + /** + * @var array + */ + public $regions; +}