Giter VIP home page Giter VIP logo

client's Introduction

DigitalOcean PHP API Client

We present a modern DigitalOcean API v2 client for PHP.

Banner

Build Status StyleCI Status Software License Packagist Downloads Latest Version

Check out the change log, releases, security policy, license, code of conduct, and contribution guidelines.

Installation

This version supports PHP 7.4-8.3. To get started, simply require the project using Composer. You will also need to install packages that "provide" psr/http-client-implementation and psr/http-factory-implementation.

Standard Installation

$ composer require "toin0u/digitalocean-v2:^4.9" \
  "guzzlehttp/guzzle:^7.8" "http-interop/http-factory-guzzle:^1.2"

Framework Integration

Laravel:

$ composer require "graham-campbell/digitalocean:^10.3"

We are decoupled from any HTTP messaging client by using PSR-7, PSR-17, PSR-18, and HTTPlug. You can visit HTTPlug for library users to get more information about installing HTTPlug related packages. The framework integration graham-campbell/gitlab is by Graham Campbell and dunglas/digital-ocean-bundle is by Kévin Dunglas.

Upgrading

If you are upgrading from version 2.3 to 3.0, or from 3.2 to 4.0, you can check out our upgrading guide. We highly recommend upgrading as soon as possible.

Examples

As of version 3.0, we will will automatically discover an HTTP client to use, from what you have available. Simply create a new DigitalOcean client, provide your access token, then you're good to go:

<?php

require_once 'vendor/autoload.php';

// create a new DigitalOcean client
$client = new DigitalOceanV2\Client();

// authenticate the client with your access token which can be
// generated at https://cloud.digitalocean.com/settings/applications
$client->authenticate('your_access_token');

Version 3.0 also has a built-in paginator, and can be used on any of the APIs which return collections. By default, the pager will internally attempt to fetch 100 entries in each request, however this can be configured by passing a 2nd parameter to the constructor. We have included an example below which will fetch all droplets:

// create a new result pager
$pager = new DigitalOceanV2\ResultPager($client);

// get all droplets as an array
$droplets = $pager->fetchAll($client->droplet(), 'getAll');

// get all droplets as a Generator which lazily yields
// new results as they become available
$droplets = $pager->fetchAllLazy($client->droplet(), 'getAll');

Account

// return the account api
$account = $client->account();

// return the Account entity
$userInformation = $account->getUserInformation();

Action

// return the action api
$action  = $client->action();

// return a collection of Action entity
$actions = $action->getAll();

// return the Action entity 123
$action123 = $action->getById(123);

App

// return the app api
$app = $client->app();

// return a collection of Apps
$apps = $app->getAll();

// return the App entity 123
$app123 = $app->getById(123);

// create a new App
$spec = [
    "name" => "sample-golang",
    "services" => [
        [
            "name" => "web",
            "github" => [
              "repo" => "digitalocean/sample-golang",
              "branch" => "branch"
            ],
            "run_command" => "bin/sample-golang",
            "environment_slug" => "go",
            "instance_size_slug" => "basic-xxs",
            "instance_count" => 2,
            "routes" => [
                [
                    "path" => "/"
                ]
            ]
        ]
    ],
    "region" => "ams"
];
$app = $app->create($spec);

// update an App with App entity 123
$app = $app->update(123, $spec);

// delete an App with App entity 123
$app->remove(123);

// retrieve App deployments with App entity 123
$deployments = $app->getAppDeployments(123);

// return an App deployment with App entity 123, deployment ID of 456
$deployment = $app->getAppDeployment(123,456);

// create an App deployment with App entity 123
$deployment = $app->createAppDeployment(123);

// cancel an App deployment
$deployment = $app->cancelAppDeployment(123,456);

// retrieve deployment logs by component for entity 123, deployment ID of 456, component name of "test_component"
$logs = $app->getDeploymentLogs(123,456,"test_component");

// retrieve aggregate deployment logs for entity 123, deployment ID of 456
$logs = $app->getAggregateDeploymentLogs(123,456);

// retrieve App regions
$regions = $app->getRegions();

// retrieve App tiers
$tiers = $app->getTiers();

// return an App tier by slug with slug name of "test_slug"
$tier = $app->getTierBySlug("test_slug");

// retrieve App instance sizes
$instance_sizes = $app->getInstanceSizes();

// return App instance size by slug with slug name of "test_slug"
$instance_size = $app->getInstanceSizeBySlug("test_slug");

Database

// return the database api
$database = $client->database();

// return a collection of DatabaseCluster entity
$clusters = $database->getAllClusters();

// return a collection of DatabaseCluster entity filtered by 'tag-name'
$clusters = $database->getAllClusters('tag-name');

// return the DatabaseCluster entity '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$myCluster = $database->getClusterById('405427f6-393a-4744-817a-2ec6c1b2e2c2');

// return the created DatabaseCluster entity
$createdCluster = $database->createCluster('my-redis-cluster', 'redis', 'db-s-1vcpu-1gb', 'fra1', 1);

// return the created DatabaseCluster entity with optional parameters
$anotherCluster = $database->createCluster('my-redis-cluster', 'redis', 'db-s-1vcpu-1gb', 'fra1', 1, "5", ['tag-1', 'tag-2'], 'daf994c2-1a34-4a94-beca-f43d09f63eb6');

// resize database cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$database->resize('405427f6-393a-4744-817a-2ec6c1b2e2c2', 'db-s-1vcpu-2gb', 2);

// migrate database cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2' to the 'lon1' region
$database->migrate('405427f6-393a-4744-817a-2ec6c1b2e2c2', 'lon1');

// remove database cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$database->remove('405427f6-393a-4744-817a-2ec6c1b2e2c2');

// return the DatabaseRules entity of cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$rules = $database->getFirewallRules('405427f6-393a-4744-817a-2ec6c1b2e2c2')

// update firewall rules of cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$database->updateFirewallRules('405427f6-393a-4744-817a-2ec6c1b2e2c2', [
    ["type" => 'ip_addr', "value" => '192.168.1.1'],
    ["type" => 'droplet', "value" => '163973392'],
]);

// update maintenance window of cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$database->updateMaintenanceWindow('405427f6-393a-4744-817a-2ec6c1b2e2c2', 'thursday', "21:00");

// return a collection of DatabaseBackup entity of cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$backups = $database->getBackups('405427f6-393a-4744-817a-2ec6c1b2e2c2');

// create a new database cluster based on the 'origin-cluster' cluster backup and return a DatabaseCluster entity for the newly created cluster
$restored = $database->createClusterFromBackup('cluster-from-backup', ["database_name" => 'origin-cluster', "backup_created_at" => '2020-09-14T08:11:29Z'], 'mysql', 'db-s-1vcpu-1gb', 'fra1', 1, null, ['tag-1', 'tag-2']);

// return a collection of DatabaseReplica entity for cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$replicas = $database->getAllReplicas('405427f6-393a-4744-817a-2ec6c1b2e2c2');

// return the DatabaseReplica enitity named 'my-replica' of cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$replica = $database->getReplicaByName('405427f6-393a-4744-817a-2ec6c1b2e2c2', 'my-replica');

// return the created DatabaseReplica entity of cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$createdReplica = $database->createReplica('405427f6-393a-4744-817a-2ec6c1b2e2c2', 'my-replica', 'db-s-1vcpu-1gb');

// remove replica named 'my-replica' of cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$database->removeReplica('405427f6-393a-4744-817a-2ec6c1b2e2c2', 'my-replica');

// return a collection of DatabaseUser entity for cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$users = $database->getAllUsers('405427f6-393a-4744-817a-2ec6c1b2e2c2');

// return the DatabaseUser entity named 'my-user' of cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$user = $database->getUserByName('405427f6-393a-4744-817a-2ec6c1b2e2c2', 'my-user');

// return the created DatabaseUser entity named 'my-user' of cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$createdUser = $database->createUser('405427f6-393a-4744-817a-2ec6c1b2e2c2', 'my-user');

// return the created DatabaseUser entity named 'my-user' of cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2' with optional mysql auth plugin
$createdUser2 = $database->createUser('405427f6-393a-4744-817a-2ec6c1b2e2c2', 'my-user-2', 'mysql_native_password');

// return the updated DatabaseUser entity named 'my-user' of cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$updatedUser = $database->updateUserMysqlAuthMethod('405427f6-393a-4744-817a-2ec6c1b2e2c2', 'my-user-2', 'caching_sha2_password');

// remove user named 'my-user' of cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$database->removeUser('405427f6-393a-4744-817a-2ec6c1b2e2c2', 'my-user');

// return a collection of Database entity of cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$dbs = $database->getAllDatabases('405427f6-393a-4744-817a-2ec6c1b2e2c2');

// return the Database entity named 'my-database' of cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$db = $database->getDatabaseByName('405427f6-393a-4744-817a-2ec6c1b2e2c2', 'my-database');

// return the created Database entity named 'my-database' of cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$createdDb = $database->createDatabase('405427f6-393a-4744-817a-2ec6c1b2e2c2', 'my-database');

// remove the database named 'my-database' of cluster '405427f6-393a-4744-817a-2ec6c1b2e2c2'
$database->removeDatabase('405427f6-393a-4744-817a-2ec6c1b2e2c2', 'my-database');


// ** Only for PostgreSQL Database Clusters ** //

// return a collection of DatabasePool entity of cluster 'cd2184a9-8f05-49f4-9700-293efb81c7fd'
$pools = $database->getAllConnectionPools('cd2184a9-8f05-49f4-9700-293efb81c7fd');

// return the DatabasePool entity named 'my-pool' of cluster 'cd2184a9-8f05-49f4-9700-293efb81c7fd'
$pool = $database->getConnectionPoolByName('cd2184a9-8f05-49f4-9700-293efb81c7fd', 'my-pool');

// return the created DatabasePool entity for cluster 'cd2184a9-8f05-49f4-9700-293efb81c7fd'
$createdPool = $database->createConnectionPool('cd2184a9-8f05-49f4-9700-293efb81c7fd', 'my-pool', 'transaction', 1, 'defaultdb', 'doadmin');

// remove pool named 'my-pool' of cluster 'cd2184a9-8f05-49f4-9700-293efb81c7fd'
$pools = $database->removeConnectionPool('cd2184a9-8f05-49f4-9700-293efb81c7fd', 'my-pool');


// ** Only for Redis Database Clusters ** //

// return an object with a 'evictionPolicy' key for cluster '3a9e419c-e38e-40ef-8f56-09b4254b80e2'
$policy = $database->getEvictionPolicy('3a9e419c-e38e-40ef-8f56-09b4254b80e2');

// update eviction policy for cluster '3a9e419c-e38e-40ef-8f56-09b4254b80e2'
$database->updateEvictionPolicy('3a9e419c-e38e-40ef-8f56-09b4254b80e2', 'allkeys_random');


// ** Only for MySQL Database Clusters ** //

// return an object with a 'sqlMode' key for cluster 'd448b69d-3d06-411a-8ac7-c16132ba0f1e'
$mode = $database->getSqlMode('d448b69d-3d06-411a-8ac7-c16132ba0f1e');

// update sql mode for cluster 'd448b69d-3d06-411a-8ac7-c16132ba0f1e'
$database->updateSqlMode('d448b69d-3d06-411a-8ac7-c16132ba0f1e', 'ANSI,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE');

CDN Endpoint

// return the cdn endpoint api
$cdnEndpoint = $client->cdnEndpoint();

// return a collection of CdnEndpoint entity
$cdnEndpoints = $cdnEndpoint->getAll();

// return the CdnEndpoint entity '8d077fd4-e67e-409c-b927-aa92dfaf0e69'
$cdnEndpoint8d077fd4 = $cdnEndpoint->getById('8d077fd4-e67e-409c-b927-aa92dfaf0e69');

// return the created CdnEndpoint with origin 'fake-cdn.nyc3.digitaloceanspaces.com', ttl 1800, certificate id '892071a0-bb95-49bc-8021-3afd67a210bf' and custom domain 'fake-cdn.example.com'
$created = $cdnEndpoint->create('fake-cdn.nyc3.digitaloceanspaces.com', 1800, '892071a0-bb95-49bc-8021-3afd67a210bf', 'fake-cdn.example.com');

// return the CdnEndpoint with id '8d077fd4-e67e-409c-b927-aa92dfaf0e69' updated with ttl 3600, certificate id '08dad2a2-a588-4558-976a-18fc36076520' and custom domain 'fake-cdn-2.example.com'
$updated = $cdnEndpoint->update('8d077fd4-e67e-409c-b927-aa92dfaf0e69', 3600, '08dad2a2-a588-4558-976a-18fc36076520', 'fake-cdn-2.example.com');

// remove the cdnEndpoint identified by '8d077fd4-e67e-409c-b927-aa92dfaf0e69'
$cdnEndpoint->remove('8d077fd4-e67e-409c-b927-aa92dfaf0e69');

// purge the cache of cdnEndpoint identified by '8d077fd4-e67e-409c-b927-aa92dfaf0e69'
$cdnEndpoint->purgeCache('8d077fd4-e67e-409c-b927-aa92dfaf0e69');

// purge the following files in the cache of cdnEndpoint identified by '8d077fd4-e67e-409c-b927-aa92dfaf0e69'
$cdnEndpoint->purgeCache('8d077fd4-e67e-409c-b927-aa92dfaf0e69', ["assets/img/hero.png", "assets/css/*"]);

Domain

// return the domain api
$domain = $client->domain();

// return a collection of Domain entity
$domains = $domain->getAll();

// return the Domain entity 'foo.dk'
$domainFooDk = $domain->getByName('foo.dk');

// return the created Domain named 'bar.dk' and pointed to ip '127.0.0.1'
$created = $domain->create('bar.dk', '127.0.0.1');

// remove the domain named 'baz.dk'
$domain->remove('baz.dk');

Domain Record

// return the domain record api
$domainRecord = $client->domainRecord();

// return a collection of DomainRecord entity of the domain 'foo.dk'
$domainRecords = $domainRecord->getAll('foo.dk');

// return the DomainRecord entity 123 of the domain 'foo.dk'
$domainRecord123 = $domainRecord->getById('foo.dk', 123);

// return the created DomainRecord entity of the domain 'bar.dk'
$created = $domainRecord->create('bar.dk', 'AAAA', 'bar-name', '2001:db8::ff00:42:8329');

// return the DomainRecord entity 123 of the domain 'baz.dk' updated with new-name, new-data, priority 1, port 2, weight 3, flags 0, tag issue (name, data, priority, port, weight, flags and tag are nullable)
$updated = $domainRecord->update('baz.dk', 123, 'new-name', 'new-data', 1, 2, 3, 0, 'issue');

// remove domain record 123 of the domain 'qmx.dk'
$domainRecord->remove('qmx.dk', 123);

Droplet

// return the droplet api
$droplet = $client->droplet();

// return a collection of Droplet entity
$droplets = $droplet->getAll();

// return a collection of Droplet neighbor to Droplet entity 123
$droplets = $droplet->getNeighborsById(123);

// return a collection of Droplet that are running on the same physical hardware
$neighbors = $droplet->getAllNeighbors();

// return the Droplet entity 123
$droplet123 = $droplet->getById(123);

// create and return the created Droplet entity
$created = $droplet->create('the-name', 'nyc1', '512mb', 449676388);

// create and return the created Droplet entity using an image slug
$created = $droplet->create('the-name', 'nyc1', '512mb', 'ubuntu-14-04-x64');

// remove the droplet 123
$droplet->remove(123);

// remove all droplets with a given tag
$droplet->removeTagged('awesome');

// return a collection of Kernel entity
$kernels = $droplet->getAvailableKernels(123);

// return a collection of Image entity
$images = $droplet->getSnapshots(123);

// return a collection of Image entity
$backups = $droplet->getBackups(123);

// return a collection of Action entity of the droplet 123
$actions = $droplet->getActions(123);

// return the Action entity 456 of the droplet 123
$action123 = $droplet->getActionById(123, 456);

// reboot droplet 123 and return the Action entity
$rebooted = $droplet->reboot(123);

// power cycle droplet 123 and return the Action entity
$powerCycled = $droplet->powerCycle(123);

// shutdown droplet 123 and return the Action entity
$shutdown = $droplet->shutdown(123);

// power off droplet 123 and return the Action entity
$powerOff = $droplet->powerOff(123);

// power on droplet 123 and return the Action entity
$powerOn = $droplet->powerOn(123);

// reset password droplet 123 and return the Action entity
$passwordReseted = $droplet->passwordReset(123);

// resize droplet 123 with the image 789 and return the Action entity
$resized = $droplet->resize(123, 789);

// restore droplet 123 with the image 789 and return the Action entity
$restored = $droplet->restore(123, 789);

// rebuild droplet 123 with image 789 and return the Action entity
$rebuilt = $droplet->rebuild(123, 789);

// rename droplet 123 to 'new-name' and return the Action entity
$renamed = $droplet->rename(123, 'new-name');

// take a snapshot of droplet 123 and name it 'my-snapshot'. Returns the an Action entity
$snapshot = $droplet->snapshot(123, 'my-snapshot');

// change kernel to droplet 123 with kernel 321 and return the Action entity
$kernelChanged = $droplet->changeKernel(123, 321);

// enable IPv6 to droplet 123 and return the Action entity
$ipv6Enabled = $droplet->enableIpv6(123);

// disable backups to droplet 123 and return the Action entity
$backupsDisabled = $droplet->disableBackups(123);

// enable private networking to droplet 123 and return the Action entity
$privateNetworkingEnabled = $droplet->enablePrivateNetworking(123);

Firewall

// return the firewall api
$firewall = $client->firewall();

// return the Firewall entity 'abc-123'
$firewall_abc123 = $firewall->getById('abc-123');

// create a firewall with some defaults, assign it to a droplet, and return the Firewall entity
$inboundRules = [
    ['protocol' => 'tcp', 'ports' => '22', 'sources' => ['addresses' => ['0.0.0.0/0', '::/0']]],
    ['protocol' => 'tcp', 'ports' => 'all', 'sources' => ['addresses' => ['0.0.0.0/0', '::/0']]],
    ['protocol' => 'udp', 'ports' => 'all', 'sources' => ['addresses' => ['0.0.0.0/0', '::/0']]],
    ['protocol' => 'icmp', 'sources' => ['addresses' => ['0.0.0.0/0', '::/0']]],
];
$outboundRules = [
    ['protocol' => 'tcp', 'ports' => 'all', 'destinations' => ['addresses' => ['0.0.0.0/0', '::/0']]],
    ['protocol' => 'udp', 'ports' => 'all', 'destinations' => ['addresses' => ['0.0.0.0/0', '::/0']]],
    ['protocol' => 'icmp', 'destinations' => ['addresses' => ['0.0.0.0/0', '::/0']]],
];

$dropletId = 123;
$firewall = $firewall->create(
    strval($dropletId) . '-firewall', $inboundRules, $outboundRules, [$dropletId]
);

// Add inbound rule to firewall id abc-123 from an array of address sources.
$firewallId = 'abc-123';
$type = 'inbound_rules';
$protocol = 'tcp';
$ports = '22';
$addresses = ['0.0.0.0/0', '::/0'];

if ($type == 'inbound_rules') {
    $locations = 'sources'
} elseif($type == 'outbound_rules'){
    $locations = 'destinations';
}

$rules[$type] = [
    ['protocol' => $protocol, 'ports' => $ports, $locations => ['addresses' => $addresses])
);
$firewall->addRules($firewallId, $rules);

// remove above rule
$firewall->removeRules($firewallId, $rules)

// remove firewall id 123-abc
$firewall->remove('123-abc');

Image

// return the image api
$image = $client->image();

// return a collection of Image entity
$images = $image->getAll();

// return a collection of distribution Image entity
$images = $image->getAll(['type' => 'distribution']);

// return a collection of application Image entity
$images = $image->getAll(['type' => 'application']);

// return a collection of private Image entity
$images = $image->getAll(['private' => true]);

// return a collection of private application Image entity
$images = $image->getAll(['type' => 'application', 'private' => true]);

// return the Image entity 123
$image123 = $image->getById(123);

// return the Image entity with the given image slug
$imageFoobar = $image->getBySlug('foobar');

// return the updated Image entity
$updatedImage = $image->update(123, 'new-name');

// remove the image 123
$image->remove(123);

// return the Action entity of the transferred image 123 to the given region slug
$transferredImage = $image->transfer(123, 'region-slug');

// return the Action entity 456 of the image 123
$actionImage = $image->getAction(123, 456);

Key

// return the key api
$key = $client->key();

// return a collection of Key entity
$keys = $key->getAll();

// return the Key entity 123
$key123 = $key->getById(123);

// return the Key entity with the given fingerprint
$key = $key->getByFingerprint('f5:de:eb:64:2d:6a:b6:d5:bb:06:47:7f:04:4b:f8:e2');

// return the created Key entity
$createdKey = $key->create('my-key', 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDPrtBjQaNBwDSV3ePC86zaEWu0....');

// return the updated Key entity
$updatedKey = $key->update(123, 'new-key-name');

// return void if removed successfully
$key->remove(123);

Load Balancer

// return the load balancer api
$loadBalancer = $client->loadbalancer();

//returns a collection of Load Balancer entities
$loadBalancers = $loadBalancer->getAll();

//return a Load Balancer entity by id
$myLoadBalancer = $loadBalancer->getById('506f78a4-e098-11e5-ad9f-000f53306ae1');

/**
* updates an existing load balancer, the method will except a LoadBalancer
* entity or a load balancer representation in array form, the digitial
* Ocean API requires a full representation of your load
* balancer, any attribute that is missing will
* be reset to it's default setting.
*/
$myUpdatedLoadBalancer = $loadBalancer->update('506f78a4-e098-11e5-ad9f-000f53306ae1', $myLoadBalancer);

//create a standard load balancer that listens on port 80 and 443 with ssl passthrough enabled
$myNewLoadBalancer = $loadBalancer->create('my-new-load-balancer', 'nyc1');

Monitoring

// return the monitoring api
$monitoring = $client->monitoring();

// return a collection of alerts
$alerts = $monitoring->getAlerts();

// return alert uuid 123e4567-e89b-12d3-a456-426655440000
$alert = $monitoring->getAlert('123e4567-e89b-12d3-a456-426655440000');

// return inbound bandwidth metrics on the public interface of droplet id 123 from the past hour
$bandwidth = $monitoring->getDropletBandwidth(
    '123', 
    time() - 3600, 
    time(),
)->data;

// return outbound droplet bandwidth metrics on the private interface of droplet id 123 from the past hour
$bandwidth = $monitoring->getDropletBandwidth(
    '123', 
    time() - 3600, 
    time(),
    'outbound',
    'private'
)->data;

// Get current available storage for droplet id 123
$freeStorage = $monitoring->getDropletFilesystemFree(
    '123',
    time(),
    time()
)->data;

Project Resources

// return the project resources api
$projectResources = $client->projectResource();

// return the resources of the specified project
$projectResource = $projectResources->getProjectResources('1a111a1a-1aa1-1a1a-11a1-1111a11a11a1');

// assign a list of resources to the specified project
$projectResource = $projectResources->assignResources('1a111a1a-1aa1-1a1a-11a1-1111a11a11a1', ['do:droplet:123456789']);

// return the resources of the default project
$projectResource = $projectResources->getDefaultProjectResources();

// assign a list of resources to the default project
$projectResource = $projectResources->assignResourcesToDefaultProject(['do:droplet:123456789']);

Region

// return the region api
$region = $client->region();

// return a collection of Region entity
$regions = $region->getAll();

Size

// return the size api
$size = $client->size();

// return a collection of Size entity
$sizes = $size->getAll();

Tag

// return the tag api
$tag = $client->tag();

// return a collection of Tag entity
$tags = $tag->getAll();

// return a Tag entity by name
$tag = $tag->getByName();

// create a tag
$tag = $tag->create('awesome');

// tag resources
$tag->tagResources('awesome', [["resource_id" => "9569411", "resource_type" => "droplet"]]);

// untag resources
$tag->untagResources('awesome', [["resource_id" => "9569411", "resource_type" => "droplet"]]);

// remove tag
$tag->remove('awesome');

Volume

// return the volume api
$volume = $client->volume();

// returns the all volumes
$volumes = $volume->getAll();

// returns the all volumes by region
$volumes = $volume->getAll('nyc1');

// returns volumes by name and region
$volumes = $volume->getByNameAndRegion('example', 'nyc1');

// returns a volume by id
$myvolume = $volume->getById('506f78a4-e098-11e5-ad9f-000f53306ae1');

// returns a volumes snapshots by volume id
$mySnapshots = $volume->getSnapshots('506f78a4-e098-11e5-ad9f-000f53306ae1');

// creates a volume
$myvolume = $volume->create('example', 'Block store for examples', 10, 'nyc1');

// removes a volume by id
$volume->remove('506f78a4-e098-11e5-ad9f-000f53306ae1');

// removes a volume by name and region
$volume->remove('example', 'nyc1');

// attach a volume to a Droplet
$volume->attach('506f78a4-e098-11e5-ad9f-000f53306ae1', 123, 'nyc1');

// detach a volume from a Droplet
$volume->detach('506f78a4-e098-11e5-ad9f-000f53306ae1', 123, 'nyc1');

// resize a volume
$volume->resize('506f78a4-e098-11e5-ad9f-000f53306ae1', 20, 'nyc1');

// take a snapshot of volume and name it 'my-snapshot'. Returns the Snapshot entity
$snapshot = $volume->snapshot('506f78a4-e098-11e5-ad9f-000f53306ae1', 'my-snapshot');

// get a volume action by its id
$volume->getActionById(123, '506f78a4-e098-11e5-ad9f-000f53306ae1');

// get all actions related to a volume
$volume->getActions('506f78a4-e098-11e5-ad9f-000f53306ae1');

VPC

// return the VPC api
vpc = $client->vpc();

// returns the all VPCs
vpcs = $vpc->getAll();

Contributing

We will gladly receive issue reports and review and accept pull requests, in accordance with our code of conduct and contribution guidelines!

$ make install
$ make test

Security

If you discover a security vulnerability within this package, please send an email to [email protected]. All security vulnerabilities will be promptly addressed. You may view our full security policy here.

License

DigitalOcean PHP API Client is licensed under The MIT License (MIT).

client's People

Contributors

alrik11es avatar babarinde avatar bambamboole avatar borales avatar browner12 avatar cherny-sh avatar dunglas avatar fideloper avatar grahamcampbell avatar hexogen avatar i0 avatar jeremykendall avatar lewissmallwood avatar liverbool avatar malc0mn avatar marcvdm avatar mbardelmeijer avatar nicolasbeauvais avatar owenconti avatar roydejong avatar saverio avatar sdwru avatar shihjay2 avatar spicybeefnoodle avatar teevio avatar toin0u avatar tspencer244 avatar webignition avatar yassirh avatar zspine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

client's Issues

SSL

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());

Issues with sshkey

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.

Droplet->getActions() not paginated

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 :)

$image->getAll() error

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_ids
array listed as part of the Image entity.

Thanks

getById 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));

Feature request: all user images

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.

codeigniter

Hi

How can i load this API in Codeigniter project

Thanks

droplet->getById

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.
",

Pagination

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.

Can't request droplets

When I request a droplet (getAll or getByID), I get the the following error:
knipsel
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.

delete this

Please remove this issue, i wanted to create it with guzzle instead.

Cannot use image "slugs" when creating servers

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.

So Broken.

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.

[BUG] Notice error on create new Droplet.

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)

user-data API

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

Library is broken again.

Missing another property. Seriously.

Property "DigitalOceanV2\Entity\Droplet::size" should exist.

Class Browser does not exist

Fatal error: Class 'Buzz\Browser' not found in /home/isensela/public_html/app/Vendor/DigitalOceanV2/Adapter/BuzzAdapter.php on line 43

AbstractEntity - Invalid argument supplied for foreach

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?

Image error

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

Adding guzzle 5

in composer it says guzzle 5 but the adapter is not a guzzle 5 adaptor

domain record update data (not only name)

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');

Why not a http adapter library?

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.

Please correct readme

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 time

Property "DigitalOceanV2\Entity\Droplet::sizeSlug" should exist.

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.

Getting droplet IP the right way?

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).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.