Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------
Expand Down
76 changes: 76 additions & 0 deletions src/Api/Domain.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/**
* This file is part of the DigitalOceanV2 library.
*
* (c) Antoine Corcy <contact@sbin.dk>
*
* 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 <yassir.hannoun@gmail.com>
*/
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);
}
}
36 changes: 36 additions & 0 deletions src/Api/Region.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* This file is part of the DigitalOceanV2 library.
*
* (c) Antoine Corcy <contact@sbin.dk>
*
* 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 <yassir.hannoun@gmail.com>
*/
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;
}
}
36 changes: 36 additions & 0 deletions src/Api/Size.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* This file is part of the DigitalOceanV2 library.
*
* (c) Antoine Corcy <contact@sbin.dk>
*
* 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 <yassir.hannoun@gmail.com>
*/
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;
}
}
29 changes: 28 additions & 1 deletion src/DigitalOceanV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <contact@sbin.dk>
Expand Down Expand Up @@ -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);
}
}
33 changes: 33 additions & 0 deletions src/Entity/Domain.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* This file is part of the DigitalOceanV2 library.
*
* (c) Antoine Corcy <contact@sbin.dk>
*
* 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 <yassir.hannoun@gmail.com>
*/
class Domain extends AbstractEntity
{
/**
* @var string
*/
public $name;

/**
* @var string
*/
public $ttl;

/**
* @var string
*/
public $zoneFile;
}
38 changes: 38 additions & 0 deletions src/Entity/Region.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* This file is part of the DigitalOceanV2 library.
*
* (c) Antoine Corcy <contact@sbin.dk>
*
* 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 <yassir.hannoun@gmail.com>
*/
class Region extends AbstractEntity
{
/**
* @var string
*/
public $slug;

/**
* @var string
*/
public $name;

/**
* @var boolean
*/
public $available;

/**
* @var Size[]
*/
public $sizes;
}
58 changes: 58 additions & 0 deletions src/Entity/Size.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* This file is part of the DigitalOceanV2 library.
*
* (c) Antoine Corcy <contact@sbin.dk>
*
* 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 <yassir.hannoun@gmail.com>
*/
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;
}