Git Product home page Git Product logo

digitalocean's Introduction

DigitalOcean PHP SDK + Command-line Interface

A DigitalOcean PHP SDK that also comes with a feature-complete command-line interface that uses the SDK. Full support for all DigitalOcean APIs.

Donate

Features

  • A single, simple PHP class for interfacing with the DigitalOcean API. An SDK the way mother nature intended.
  • Also comes with a complete, question/answer enabled command-line interface. Nothing to compile. Cross platform.
  • Has a liberal open source license. MIT or LGPL, your choice.
  • Designed for relatively painless integration into your project.
  • Sits on GitHub for all of that pull request and issue tracker goodness to easily submit changes and ideas respectively.

Getting Started

The easiest way to get started is to play with the command-line interface. The command-line interface is question/answer enabled, which means all you have to do is run:

php do.php

That will enter interactive mode and guide you through the entire process. The first time you run the tool, you can only 'setup' or use the Metadata API (i.e. this tool can be used on a Droplet). During setup, you will see a screen like this:

The configuration file 'config.dat' does not exist.  Entering interactive configuration mode.


Available access token types:

  application:  Standard DigitalOcation OAuth2 application login.
  personal:     A permanent access token you manually set up in your DigitalOcean account.

Access token type [application]:

If you choose 'application' (the default), you will be asked to copy a specific URL into your web browser to sign in and authorize and then paste the destination URL back into the tool. Configuration is a one-time process.

After setup, the world of DigitalOcean APIs opens up to you:

php do.php

Once you grow tired of manually entering information, you can pass in some or all of the answers to the questions on the command-line:

php do.php droplets list

php do.php droplets create

php do.php -s droplets create -name mydroplet -size s-1vcpu-1gb -backups N -ipv6 Y -private_network N -storage N -metadata '' -region nyc1 -image ubuntu-18-04-x64 -sshkey 123456 -sshkey 123457 -sshkey '' -tag '' -wait Y

The -s option suppresses normal output (except for fatal error conditions), which allows for the processed JSON result to be the only thing that is output.

When you set up/configure your Droplets, you might also find these related PHP-based tools useful:

Also, be sure to check out the full CubicleSoft product line. Who knows? You might find something interesting to use. I'm a fairly prolific software developer.

Using the SDK

While the command-line tool can do everything the SDK can do, a few people will probably want/need additional flexibility. For that, the SDK is available to program against. The SDK itself is located in 'support\sdk_digitalocean.php'. To get started, you will need to have a valid bearer token:

	require_once "support/sdk_digitalocean.php";

	$do = new DigitalOcean();
	// $do->SetDebug(true);  // Allows you to see raw debug output of various API calls.

	// Command-line interactive login:
	//   $result = $do->InteractiveLogin();
	//   if (!$result["success"])  CLI::DisplayError("An error occurred...", $result);
	//   $access_tokens = $do->GetAccessTokens();
	//   ...
	//   $do->AddAccessTokensUpdatedNotify("SaveAccessTokens");  // 'SaveAccessTokens' is the name of a callback function.
	// OR a personal access token:
	//   $access_tokens = $do->GetAccessTokens();
	//   $access_tokens["bearertoken"] = YOUR_PERSONAL_ACCESS_TOKEN
	$do->SetAccessTokens($access_tokens);

After you have set up your access token, you can start using the SDK with the various APIs:

	var_dump($do->AccountGetInfo());

	$options = array(
		"ssh_keys" => array("123456", "123457"),
		"backups" => false,
		"ipv6" => true,
		"private_networking" => false,
		"volumes" => array(),
		"user_data" => null
	);

	var_dump($do->DropletsCreate("awesome", "nyc1", "512mb", "ubuntu-16-04-x64", $options));

The command-line tool source code is an excellent source of example usage of the SDK.

SDK Variants

Not everyone uses flat class SDKs. That's okay. There's an automated flavor of this SDK for everyone:

You will, of course, have to adjust code accordingly.

DigitalOcean API Changelog

The API changes regularly. You can safely assume that both this SDK and command-line tool mirrors the stable API (i.e. not in a beta program) as per the most recent commit date in this repository when compared to the DigitalOcean API changelog:

https://developers.digitalocean.com/documentation/changelog/

digitalocean's People

Contributors

cubiclesoft avatar

Watchers

 avatar

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.