digitaloceanphp / client Goto Github PK
View Code? Open in Web Editor NEWDigitalOcean API v2 client for PHP
License: MIT License
DigitalOcean API v2 client for PHP
License: MIT License
Hi
I'm having a little bit of an issue, depending on how a Droplet is made (Private networking on or off) the returned Network Array will be slightly different.
I currently get the Droplet's Public IP as such:
$ip = $userAtom->networks[0]->ipAddress (For a Droplet with Private networking turned off)
&
$ip = $userAtom->networks[1]->ipAddress (For a Droplet with Private networking turned on)
This is causing me a headache, is there no way to get the Droplet's Public IP regardless of the Private networking status, with a single statement?
Just seems a little annoying that $userAtom->ipAddress does not work.
For instance:
using $userAtom->networks[1]. (with Private network off results in no IP being found).
in composer it says guzzle 5 but the adapter is not a guzzle 5 adaptor
All action objects, i.e. those returned by the
/v2/actions
,/v2/droplets/$ID/actions
and/v2/images/$ID/actions
endpoint now return aregion_slug
attribute, in addition to a region attribute. At 00:01 March 20, 2015 UTC, API v2 will start returning an embedded region object at the region attribute, not a slug.
Example
account(); // return the Account entity $userInformation = $account->getUserInformation(); # $digitalOcean and $digitalocean , Register at different letters O , very is not convenient when trying to run the first timeProbably API changed again.
Size objects now expose an available
boolean attribute, which represents whether new Droplets can be created with the size.
Source: https://developers.digitalocean.com/documentation/changelog/api-v2/sizes-available/
Related to: digitalocean/api-v2#126
The problem is in file DigitalOceanV2\Api\DomainRecord line 71
If i have a TXT record with double quotes, eg
"v=spf1 mx include:mailserver ?all"
the result is
{"name":"mydomain", "type":"TXT", "data":""v=spf1 mx include:mailserver ?all""}
Causing error 500
Adapter should be able to handle response better on errors. Right now we just throw a RuntimeException
..
would it be possible to update the data for a domain record,
i cant see it is in the code currently
$updated = $domainRecord->update('baz.dk', 123, 'new-name');
could this become
$updated = $domainRecord->updateData('baz.dk', 123, 'new-data');
Whereas the getAll() function is paginated:
$droplets = $this->adapter->get(sprintf('%s/droplets?per_page=%d', self::ENDPOINT, PHP_INT_MAX));
The getActions() function is not. I made it paginated for my local copy and it works, but just letting you know :)
API V2 now validates SSH key IDs and identifiers passed into the Droplet create call. In addition, API V2 now validates that requested features are available for a Droplet (backups, private networking, IPv6 and user data).
https://developers.digitalocean.com/documentation/changelog/api-v2/new-droplet-create-validations/
Got an error message:
Property "DigitalOceanV2\Entity\Droplet::createdAt" should exist.
Please remove this issue, i wanted to create it with guzzle instead.
See #32 (comment)
More info here
Fatal error: Class 'Buzz\Browser' not found in /home/isensela/public_html/app/Vendor/DigitalOceanV2/Adapter/BuzzAdapter.php on line 43
I've been trying this for several days off and on and can't get this to work. Passing ubuntu-14-04-x64
in the "image id" field will not work. I get invalid image errors. Using the BuzzAdapter.
I'm using 0.5.* dev version, because of the nextWindow error that's fixed in that version. Still I'm having problems running the droplet service
composer.json:
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.6.*",
"toin0u/digitalocean-v2": "0.5.*@dev",
"kriswallsmith/buzz": "~0.10",
"guzzle/guzzle": "~3.7",
"guzzlehttp/guzzle" : "~5.0"
},
The terrors:
CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException:
"Warning: Invalid argument supplied for foreach()" at
/var/www/chuck/symfony/vendor/toin0u/digitalocean-v2/src/Entity/AbstractEntity.php line 67
'2', 'Invalid argument supplied for foreach()',
'/var/www/chuck/symfony/vendor/toin0u/digitalocean-v2/src/Entity/AbstractEntity.php', '67',
array('parameters' => null))
in vendor/toin0u/digitalocean-v2/src/Entity/AbstractEntity.php at line 67
services.yml
parameters:
#digital ocean
do.class.factory: DigitalOceanV2\DigitalOceanV2
do.class.adapter: DigitalOceanV2\Adapter\GuzzleAdapter
services:
# digital ocean
do.adapter:
class: %do.class.adapter%
public: false
arguments: ["%digital_ocean_api%"]
do.factory:
class: %do.class.factory%
arguments: [@do.adapter]
and for the sake of simplicity;
<?php namespace Chuck\NorrisBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DropletController extends Controller
{
public function indexAction()
{
$droplet = $this->container->get( 'do.factory' )->droplet();
$droplets = $droplet->getAll();
return $this->render( 'NorrisBundle:Widget:index.html.twig', [
'droplets' => $droplets
] );
}
}
Does anybody know how to go from here, without having to hack around in this broken library?
See: #82 (comment)
The issue is with the create
method: #82 (comment)
Hi
How can i load this API in Codeigniter project
Thanks
I see you're using PHP_INT_MAX
for digital ocean's "per page" value in pagination. I don't think they will support a number that large, and even if they did, we'd likely run out of memory on our server trying to deal with a dataset that large all at once.
In the api, there is an option to call: /v2/images?type=application
This only requests the user images. This takes a lot less time then requesting all the images and filtering them.
This's an error message:
"Notice: Undefined property: stdClass::$v4 in
/vendor/toin0u/digitalocean-v2/src/Entity/Droplet.php line 92"
Note: new droplet create will response
{
.....
networks: null,
.....
}
"toin0u/digitalocean-v2": "master-dev" (0.1.0)
Attempted to pass user-data to no effect. sfo1 allows userdata, and all my other strings/booleans/integers pass
$userData ='test';
$droplet->create("test.com", "sfo1", "512mb", "ubuntu-14-04-x64", false, false, false, array(), $userData);
seeking a proper example to userdata API
Images objects now return a type
attribute, describing whether they are snapshots, backups or temporary images. For more information, see the images documentation.
Source: https://developers.digitalocean.com/documentation/changelog/api-v2/add-type-to-images/
Hi
$droplet123 = $droplet->getById(4124085);
{"status":false,"message":"Property "DigitalOceanV2\Entity\Droplet::nextBackupWindow" should exist.","data":""}
I use
"toin0u/digitalocean-v2": "0.5.@dev"
"kriswallsmith/buzz": "0.13.",
I am just asking: why not using a HTTP adapter library? @toin0u IIRC you pointed me to ivory http adapter, I was surprised when I saw it isn't used in the library.
Why does this library still break every time DigitalOcean adds a new property to their API? Is this library supposed to be used in production applications?
Property "DigitalOceanV2\Entity\Droplet::nextBackupWindow" should exist.
This code was working before, now I get an exception:
$oDropApi = $oDigitalOcean->droplet();
$droplets = $oDropApi->getAll();
Two new endpoints in API v2 report if droplets are running on the same physical hardware. They exist for an individual droplet or for an entire account.
Source: https://developers.digitalocean.com/documentation/changelog/api-v2/droplet-neighbors-report/
More info here
The way you are detecting these properties is extremely brittle and is breaking vital production projects.
When trying to create a new droplet an InvalidArgumentException
is thrown:
Property "DigitalOceanV2\Entity\Droplet::sizeSlug" should exist.
Code:
$droplet = $this->do->droplet()->create('droplet', 'lon1', '512mb', $image);
If I update line 151 of src/Entity/Droplet.php
from 'slug'
to 'size_slug'
this solves the issue.
Calling $droplets->getById(3110542) return InvalidArgumentException:
Property "DigitalOceanV2\Entity\Image::minDiskSize" should exist.
Here is an example:
$adapter = new BuzzAdapter(Yii::app()->params['DOAccessV2']);
$digitalOcean = new DigitalOceanV2($adapter);
$droplets = $digitalOcean->droplet(); // alias to Droplets class.
var_dump($droplets->getById(458652));
Hello,
When I try to get all images:
$image = $do->image();
$images = $image->getAll();
I get the following error:
Property "DigitalOceanV2\Entity\Image::images" should exist.
Do you know if the API itself has changed?
Thanks!
Has anyone had this issue?
Uncaught exception 'Buzz\Exception\RequestException' with message 'SSL certificate problem: unable to get local issuer certificate'
My test:
include "vendor/autoload.php";
use DigitalOceanV2\Adapter\BuzzAdapter;
use DigitalOceanV2\DigitalOceanV2;
$adapter = new BuzzAdapter('Personal Access Token');
$digitalocean = new DigitalOceanV2($adapter);
$a = $digitalocean->domain();
print_r($a->getAll());
Hi there,
I'm getting this when I am calling the getAll() function in the Image api:
Fatal error: Uncaught exception 'Buzz\Exception\ClientException' with message 'Operation timed out after 5000 milliseconds with 0 bytes received' in /var/www/wp-content/plugins/gravityforms-digitalocean/api/vendor/kriswallsmith/buzz/lib/Buzz/Client/Curl.php:29 Stack trace: #0 /var/www/wp-content/plugins/gravityforms-digitalocean/api/vendor/kriswallsmith/buzz/lib/Buzz/Browser.php(130): Buzz\Client\Curl->send(Object(Buzz\Message\Request), Object(Buzz\Message\Response)) #1 /var/www/wp-content/plugins/gravityforms-digitalocean/api/vendor/kriswallsmith/buzz/lib/Buzz/Browser.php(82): Buzz\Browser->send(Object(Buzz\Message\Request)) #2 /var/www/wp-content/plugins/gravityforms-digitalocean/api/vendor/kriswallsmith/buzz/lib/Buzz/Browser.php(31): Buzz\Browser->call('https://api.dig...', 'GET', Array) #3 /var/www/wp-content/plugins/gravityforms-digitalocean/api/src/Adapter/BuzzAdapter.php(53): Buzz\Browser->get('https://api.dig...') #4 /var/www/wp-content/plugins/gravityforms-digitalocean/api/src/Api/Image.php(27): DigitalOceanV2\Ad in /var/www/wp-content/plugins/gravityforms-digitalocean/api/vendor/kriswallsmith/buzz/lib/Buzz/Client/Curl.php on line 29
More info here
Hi. I would like to create droplets with the new user data, but I noticed that this library doesn't support it yet.
https://developers.digitalocean.com/#create-a-new-droplet
Could you add it? Thanks
It's not possible to create droplets with ssh key fingerprints instead of ids.
Also, I keep getting the following error: "[422] You specified invalid ssh key ids for Droplet creation. (unprocessable_entity)", not sure if it's DO's api or the client library.
Missing another property. Seriously.
Property "DigitalOceanV2\Entity\Droplet::size" should exist.
Hello,
I am using the very latest commit, but when I call the $image->getAll() function, I get the following error
Warning: array_map(): An error occurred while invoking the map callback in /var/www/wp-content/plugins/gravityforms-digitalocean/api/src/Api/Image.php on line 33 Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Property "DigitalOceanV2\Entity\Image::actionIds" should exist.' in /var/www/wp-content/plugins/gravityforms-digitalocean/api/src/Entity/AbstractEntity.php:49 Stack trace: #0 /var/www/wp-content/plugins/gravityforms-digitalocean/api/src/Entity/AbstractEntity.php(68): DigitalOceanV2\Entity\AbstractEntity->__set('actionIds', Array) #1 /var/www/wp-content/plugins/gravityforms-digitalocean/api/src/Entity/AbstractEntity.php(24): DigitalOceanV2\Entity\AbstractEntity->build(Object(stdClass)) #2 /var/www/wp-content/plugins/gravityforms-digitalocean/api/src/Api/Image.php(32): DigitalOceanV2\Entity\AbstractEntity->__construct(Object(stdClass)) #3 [internal function]: DigitalOceanV2\Api\Image->DigitalOceanV2\Api\{closure}(Object(stdClass)) #4 /var/www/wp-content/plugins/gravityforms-digitalocean/api/src/Api/Image.php(33): array_map(Object(Closure), Array) #5 /var/www/wp-content/plugins/gravityforms-digitalocean/functions/gravityforms-digitalocean-functions.php( in /var/www/wp-content/plugins/gravityforms-digitalocean/api/src/Entity/AbstractEntity.php on line 49
Just letting you know!
I checked the API here: https://developers.digitalocean.com/#images , and there is an
action_idsarray listed as part of the Image entity.
Thanks
The "2.0" version should be manually deleted from https://packagist.org/packages/toin0u/digitalocean-v2. I have no idea how it got there!
When I request a droplet (getAll or getByID), I get the the following error:
This is my code:
<?php
require 'vendor/autoload.php';
use DigitalOceanV2\Adapter\BuzzAdapter;
use DigitalOceanV2\DigitalOceanV2;
$adapter = new BuzzAdapter($token);
$digitalocean = new DigitalOceanV2($adapter);
$droplet = $digitalocean->droplet();
$droplet = $droplet->getAll();
Other requests work.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.