From 866a68bcc1f427e1f445514dcf748927f22f428d Mon Sep 17 00:00:00 2001 From: yassirh Date: Wed, 18 Jun 2014 00:09:38 +0200 Subject: [PATCH 1/3] Added domains functionalities --- README.md | 2 +- src/Api/Domain.php | 76 ++++++++++++++++++++++++++++++++++++++++++ src/DigitalOceanV2.php | 9 +++++ src/Entity/Domain.php | 33 ++++++++++++++++++ 4 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 src/Api/Domain.php create mode 100644 src/Entity/Domain.php diff --git a/README.md b/README.md index d62ab663..b47a3270 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ 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) 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/DigitalOceanV2.php b/src/DigitalOceanV2.php index 2424279d..366a75ec 100644 --- a/src/DigitalOceanV2.php +++ b/src/DigitalOceanV2.php @@ -13,6 +13,7 @@ use DigitalOceanV2\Api\Action; use DigitalOceanV2\Adapter\AdapterInterface; +use DigitalOceanV2\Api\Domain; use DigitalOceanV2\Api\Image; /** @@ -53,4 +54,12 @@ public function image() { return new Image($this->adapter); } + + /** + * @return Domain + */ + public function domain() + { + return new Domain($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; +} From 7d69289759a4e54f6869ec89f17bcd7174811e5b Mon Sep 17 00:00:00 2001 From: yassirh Date: Wed, 18 Jun 2014 23:01:18 +0200 Subject: [PATCH 2/3] Added sizes functionalities --- README.md | 1 + src/Api/Size.php | 36 ++++++++++++++++++++++++++ src/DigitalOceanV2.php | 11 +++++++- src/Entity/Size.php | 58 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/Api/Size.php create mode 100644 src/Entity/Size.php diff --git a/README.md b/README.md index b47a3270..91d10248 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ TODO - [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] [Sizes](https://github.com/digitaloceancloud/api-v2-docs#sizes) Installation ------------ 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 366a75ec..0b2235e1 100644 --- a/src/DigitalOceanV2.php +++ b/src/DigitalOceanV2.php @@ -11,10 +11,11 @@ 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\Size; /** * @author Antoine Corcy @@ -62,4 +63,12 @@ public function domain() { return new Domain($this->adapter); } + + /** + * @return Size + */ + public function size() + { + return new Size($this->adapter); + } } 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; +} From 3b9804af89a644a35984434908e58582ab7d7190 Mon Sep 17 00:00:00 2001 From: yassirh Date: Wed, 18 Jun 2014 23:15:16 +0200 Subject: [PATCH 3/3] added regions functionalities. --- README.md | 2 +- src/Api/Region.php | 36 ++++++++++++++++++++++++++++++++++++ src/DigitalOceanV2.php | 9 +++++++++ src/Entity/Region.php | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/Api/Region.php create mode 100644 src/Entity/Region.php diff --git a/README.md b/README.md index 91d10248..026dc54a 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ TODO - [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/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/DigitalOceanV2.php b/src/DigitalOceanV2.php index 0b2235e1..876b7f4e 100644 --- a/src/DigitalOceanV2.php +++ b/src/DigitalOceanV2.php @@ -15,6 +15,7 @@ use DigitalOceanV2\Api\Action; use DigitalOceanV2\Api\Domain; use DigitalOceanV2\Api\Image; +use DigitalOceanV2\Api\Region; use DigitalOceanV2\Api\Size; /** @@ -71,4 +72,12 @@ public function size() { return new Size($this->adapter); } + + /** + * @return Region + */ + public function region() + { + return new Region($this->adapter); + } } 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; +}