A DigitalOcean API bridge for Laravel

Overview

Laravel DigitalOcean

Laravel DigitalOcean was created by, and is maintained by Graham Campbell, and is a DigitalOcean PHP API Client bridge for Laravel. It utilises my Laravel Manager package. Feel free to check out the change log, releases, security policy, license, code of conduct, and contribution guidelines.

Banner

Promo Banner

Build Status StyleCI Status Software License Packagist Downloads Latest Version

Installation

Laravel DigitalOcean requires PHP 7.2-8.0. This particular version supports Laravel 6-8.

DigitalOcean L5.1 L5.2 L5.3 L5.4 L5.5 L5.6 L5.7 L5.8 L6 L7 L8
2.2
3.2
4.0
5.4
6.0
7.3
8.3

To get the latest version, simply require the project using Composer. You will need to install any packages that "provide" psr/http-client-implementation and psr/http-factory-implementation. Most users will want:

For example, to use Guzzle 7:

$ composer require "graham-campbell/digitalocean:^8.3" "guzzlehttp/guzzle:^7.2" "http-interop/http-factory-guzzle:^1.0"

Once installed, if you are not using automatic package discovery, then you need to register the GrahamCampbell\DigitalOcean\DigitalOceanServiceProvider service provider in your config/app.php.

You can also optionally alias our facade:

        'DigitalOcean' => GrahamCampbell\DigitalOcean\Facades\DigitalOcean::class,

Configuration

Laravel DigitalOcean requires connection configuration.

To get started, you'll need to publish all vendor assets:

$ php artisan vendor:publish

This will create a config/digitalocean.php file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases.

There are two config options:

Default Connection Name

This option ('default') is where you may specify which of the connections below you wish to use as your default connection for all work. Of course, you may use many connections at once using the manager class. The default value for this setting is 'main'.

DigitalOcean Connections

This option ('connections') is where each of the connections are setup for your application. Example configuration has been included, but you may add as many connections as you would like. Note that the 2 supported authentication methods are: "none" and "token".

Usage

DigitalOceanManager

This is the class of most interest. It is bound to the ioc container as 'digitalocean' and can be accessed using the Facades\DigitalOcean facade. This class implements the ManagerInterface by extending AbstractManager. The interface and abstract class are both part of my Laravel Manager package, so you may want to go and checkout the docs for how to use the manager class over at that repo. Note that the connection class returned will always be an instance of DigitalOceanV2\Client.

Facades\DigitalOcean

This facade will dynamically pass static method calls to the 'digitalocean' object in the ioc container which by default is the DigitalOceanManager class.

DigitalOceanServiceProvider

This class contains no public methods of interest. This class should be added to the providers array in config/app.php. This class will setup ioc bindings.

Real Examples

Here you can see an example of just how simple this package is to use. Out of the box, the default adapter is main. After you enter your authentication details in the config file, it will just work:

use GrahamCampbell\DigitalOcean\Facades\DigitalOcean;
// you can alias this in config/app.php if you like

DigitalOcean::droplet()->powerOn(12345);
// we're done here - how easy was that, it just works!

DigitalOcean::size()->getAll();
// this example is simple, and there are far more methods available

The digitalocean manager will behave like it is a DigitalOceanV2\Client class. If you want to call specific connections, you can do with the connection method:

use GrahamCampbell\DigitalOcean\Facades\DigitalOcean;

// select the your_connection_name connection, then get going
DigitalOcean::connection('your_connection_name')->droplet()->getById(12345);

With that in mind, note that:

use GrahamCampbell\DigitalOcean\Facades\DigitalOcean;

// writing this:
DigitalOcean::connection('main')->region()->getAll();

// is identical to writing this:
DigitalOcean::region()->getAll();

// and is also identical to writing this:
DigitalOcean::connection()->region()->getAll();

// this is because the main connection is configured to be the default
DigitalOcean::getDefaultConnection(); // this will return main

// we can change the default connection
DigitalOcean::setDefaultConnection('alternative'); // the default is now alternative

If you prefer to use dependency injection over facades like me, then you can easily inject the manager like so:

use GrahamCampbell\DigitalOcean\DigitalOceanManager;
use Illuminate\Support\Facades\App; // you probably have this aliased already

class Foo
{
    protected $digitalocean;

    public function __construct(DigitalOceanManager $digitalocean)
    {
        $this->digitalocean = $digitalocean;
    }

    public function bar()
    {
        $this->digitalocean->region()->getAll();
    }
}

App::make('Foo')->bar();

For more information on how to use the DigitalOceanV2\Client class we are calling behind the scenes here, check out the docs at https://github.com/DigitalOceanPHP/Client/tree/4.3.0#examples, and the manager class at https://github.com/GrahamCampbell/Laravel-Manager#usage.

Further Information

There are other classes in this package that are not documented here. This is because they are not intended for public use and are used internally by this package.

Security

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

License

Laravel DigitalOcean is licensed under The MIT License (MIT).

For Enterprise

Available as part of the Tidelift Subscription

The maintainers of graham-campbell/digitalocean and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

Comments
  • phpstorm does not recognize facade, even with ide-helper

    phpstorm does not recognize facade, even with ide-helper

    hi there. i installed the ide-helper and tried stuff like that:

    https://stackoverflow.com/a/51849199/1092858

    but i am not able to make phpstorm recognize commands like this:

    DigitalOcean::droplet()->getAll()

    "droplet" and all other commands are unknown. any idea ?

    thanks!

    opened by michabbb 9
  • Dynamically set the API access token

    Dynamically set the API access token

    I have the bridge working beautifully with my static token setting as described in your setup documentation (using guzzle5). Everything works as expected but I would like to be able to set the token 'on the fly' if you will.

    Can you explain how I can override the token?

    opened by 06chaynes 6
  • Help needed. Dynamic API token

    Help needed. Dynamic API token

    So far I have this put in a InitializeDO method. Not sure if it's the right way but it works just fine. Correct me if there's a better way to set the API token dynamically.

    $this->adapter = new Adapters\ConnectionFactory();
    $config = [
    	'driver'  => 'guzzlehttp',
    	'token'   => Auth::user()->do_api_token
    ];
    $this->adapter->make($config);
    $this->dof = new DigitalOceanFactory($this->adapter);
    $this->dof->make($config);
    $this->do = $this->dof->make($config);
    

    The problem is that I can't access the user(Auth::user()) in the consturctor of the controller, so I'm calling InitializeDO in each one of my methods(index, show, edit, etc.). I don't think this is the best approach. And here comes my question, how can I write this, so it's called just once and working with $this->do afterwards?

    opened by BKirev 5
  • Installed

    Installed

    Hey,

    I was hope you could give me some pointers on how to get this working? So far I have go this installed and added a token. How do I say list the droplets on my account or see if its even corrected to my the API successfully?

    Cheers.

    opened by JBird608 5
  • Add option for UserData on droplet()->create

    Add option for UserData on droplet()->create

    It would be great if you (or someone else more knowledgable than myself) could add in the ability to pass UserData on new droplet creation.

    This would likely need some conditional checking before running the call as UserData is only available on selected OSs in certain locations. More at https://developers.digitalocean.com/#create-a-new-droplet

    opened by mrailton 4
  • TTL not set while creating domain record

    TTL not set while creating domain record

    Hi Graham I have been trying set TTL on the domain record create and update methods but no luck.

    The toin0u library did not state it either // 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');

    kindly assist

    opened by aadags 3
  • Unable to configure

    Unable to configure

    Hi,

    I installed the package as per the instructions with guzzlehttp. I have put my DO token in config/digitalocean.php but no matter which connection I try to use, I always get Connection {connection_name} is not configured. Please guide me as to where am I going wrong. Thanks!

    opened by radua 2
  • Laravel 5.7 Call to a member function getBody() on null

    Laravel 5.7 Call to a member function getBody() on null

        "graham-campbell/digitalocean": "^5.1",
        "guzzlehttp/guzzle": "^6.3",
        "kriswallsmith/buzz": "^0.17.2"
    

    when calling any function for example DigitalOcean::size()->getAll();

    Issue with C:\xampp\htdocs\front\myadmin\vendor\toin0u\digitalocean-v2\src\Adapter\GuzzleHttpAdapter.php

    Line 132: $body = (string) $this->response->getBody();

    Any ideas

    opened by AndreFabris 2
  • Not compatible Laravel 5.6

    Not compatible Laravel 5.6

    The package is not compatible with laravel 5.6.x

    Problem 1
        - Conclusion: don't install graham-campbell/digitalocean v4.0.1
        - Conclusion: don't install graham-campbell/digitalocean v4.0.0
        - Conclusion: remove laravel/framework v5.6.1
        - Installation request for graham-campbell/digitalocean ^4.0 -> satisfiable by graham-campbell/digitalocean[4.0.x-dev, v4.0.0, v4.0.1].
        - Conclusion: don't install laravel/framework v5.6.1
        - graham-campbell/digitalocean 4.0.x-dev requires illuminate/support 5.1.*|5.2.*|5.3.*|5.4.*|5.5.* -> satisfiable by illuminate/support[5.1.x-dev, 5.2.x-dev, 5.3.x-dev, 5.4.x-dev, 5.5.x-dev, v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7, v5.3.0, v5.3.16, v5.3.23, v5.3.4, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9, v5.5.0, v5.5.16, v5.5.17, v5.5.2, v5.5.28, v5.5.33, v5.5.34].
        - don't install illuminate/support 5.1.x-dev|don't install laravel/framework v5.6.1
        - don't install illuminate/support 5.2.x-dev|don't install laravel/framework v5.6.1
        - don't install illuminate/support 5.3.x-dev|don't install laravel/framework v5.6.1
        - don't install illuminate/support 5.4.x-dev|don't install laravel/framework v5.6.1
        - don't install illuminate/support 5.5.x-dev|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.1|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.13|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.16|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.2|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.20|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.22|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.25|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.28|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.30|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.31|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.41|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.6|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.8|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.0|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.19|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.21|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.24|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.25|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.26|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.27|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.28|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.31|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.32|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.37|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.43|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.45|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.6|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.7|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.3.0|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.3.16|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.3.23|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.3.4|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.4.0|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.4.13|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.4.17|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.4.19|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.4.27|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.4.36|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.4.9|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.5.0|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.5.16|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.5.17|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.5.2|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.5.28|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.5.33|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.5.34|don't install laravel/framework v5.6.1
        - Installation request for laravel/framework (locked at v5.6.1, required as 5.6.*) -> satisfiable by laravel/framework[v5.6.1].
    
    

    #17

    opened by danieluyo 2
  • Getting a single Droplet?

    Getting a single Droplet?

    Isn't there a method for getting just a single droplet for the specific ID? Like:

        public function power($droplet_id) {
    
            dd(DigitalOcean::droplet($droplet_id));
            return redirect()->back();
        }
    
    opened by itzshahay 2
  • Issues running publish:config

    Issues running publish:config

    when I try and run (using Laravel 5)

    php artisan publish:config graham-campbell/digitalocean

    I get an error:

    exception 'BadMethodCallException' with message 'Call to undefined method [package]' in /home/vagrant/code/l5try/vendor/laravel/framework/src/Illuminate/Support/ServiceProvider.php:140 Stack trace:

    I'm just trying to confirm if this is something I did wrong or if it's because L5 is still in flux.

    Thanks

    opened by snappyio 2
Releases(v9.0.0)
Owner
Graham Campbell
OSS Maintainer | Laravel | StyleCI
Graham Campbell
PHP 5.3+ library which helps you to interact with the DigitalOcean API

DigitalOcean The version 2 of the API will be available soon ! Please visit DigitalOceanV2 and contribute :) This PHP 5.3+ library helps you to intera

Antoine Kirk 156 Jul 30, 2022
A GitHub API bridge for Laravel

Laravel GitHub Laravel GitHub was created by, and is maintained by Graham Campbell, and is a PHP GitHub API bridge for Laravel. It utilises my Laravel

Graham Campbell 547 Dec 30, 2022
[DEPRECATED] A Pusher Channels bridge for Laravel

DEPRECATED Laravel now has built-in support for Pusher Channels. This is now the recommended approach to integrate Channels into a Laravel project. Cu

Pusher 406 Dec 28, 2022
This package is a simple API laravel wrapper for Pokemontcg with a sleek Model design for API routes and authentication.

This package is a simple API laravel wrapper for Pokemontcg with a sleek Model design for API routes and authentication.

Daniel Henze 3 Aug 29, 2022
API SDK for OpenTrade Commerce API: Taobao, Alibaba, JD, 1688, Aliexpress, Ebay.

OtapiPhpClient Create Client $client = new OtClient($key, $secret, $lang); key (Access Key) secret (Secret for access key) language (2 symbol lang id

OpenTrade Commerce 5 Sep 20, 2022
Fanmade project using Twitter API and Marvel API.

Project Marvel Memories A fanmade project in PHP using API Twitter V2, Marvel API and Github action scheduler. What about? Posts a random cover with d

Julien SCHMITT 15 Dec 17, 2022
Nexmo REST API client for PHP. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.

Client Library for PHP Support Notice This library and it's associated packages, nexmo/client and nexmo/client-core have transitioned into a "Maintena

Nexmo 75 Sep 23, 2022
API client for ThePay - payment gate API

This is the official highly compatible public package of The Pay SDK which interacts with The Pay's REST API. To get started see examples below.

ThePay.cz s.r.o. 3 Oct 27, 2022
Code Quiz MonoRepo (API, API Client, App)

Code Quiz Welcome to the Code Quiz Open Source project from How To Code Well. This is an Open Source project that includes an API and an App for the d

How To Code Well 2 Nov 20, 2022
OpenAI API Client is a component-oriented, extensible client library for the OpenAI API. It's designed to be faster and more memory efficient than traditional PHP libraries.

OpenAI API Client in PHP (community-maintained) This library is a component-oriented, extensible client library for the OpenAI API. It's designed to b

Mounir R'Quiba 6 Jun 14, 2023
A simple API documentation package for Laravel using OpenAPI and Redoc

Laravel Redoc Easily publish your API documentation using your OpenAPI document in your Laravel Application. Installation You can install this package

Steve McDougall 15 Dec 27, 2022
Integrate RajaOngkir API with laravel

Baca ini dalam bahasa: Indonesia This is my package laravel-rajaongkir Installation You can install the package via composer: composer require kodepin

Kode Pintar 6 Aug 11, 2022
🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.

Telegram Bot API - PHP SDK Telegram Bot PHP SDK lets you develop Telegram Bots in PHP easily! Supports Laravel out of the box. Telegram Bot API is an

Irfaq Syed 2.5k Jan 6, 2023
Twitch Helix API PHP Wrapper for Laravel

Laravel Twitch PHP Twitch Helix API Wrapper for Laravel 5+ ⚠️ Changes on May 01, 2020 Since May 01, 2020, Twitch requires all requests to contain a va

Roman Zipp 87 Dec 7, 2022
Spikkl API client for Laravel

Spikkl for Laravel Spikkl-php-laravel-client incorporates the Spikkl API into your Laravel or Lumen project. Requirements Get yourself a free Spikkl a

Spikkl 0 Jul 17, 2022
Twitter API for Laravel 5.5+, 6.x, 7.x & 8.x

Twitter for PHP Twitter API for Laravel 6.x, 7.x, 8.x (and new versions as they are released). Also supports other frameworks via PHP-DI (or feel free

null 879 Dec 17, 2022
MobilePay API for Laravel 9.x

MobilePay for PHP MobilePay API for Laravel 9.x Installation You can install the package via composer: composer require robert-hansen/mobilepay-php Yo

Robert 4 Nov 15, 2022
Laravel 8.x package wrapper library for Metatrader 5 Web API

Laravel 8.x package wrapper library for Metatrader 5 Web API

Ali A. Dhillon 10 Nov 13, 2022
PHP library for the Stripe API.

Stripe PHP bindings The Stripe PHP library provides convenient access to the Stripe API from applications written in the PHP language. It includes a p

Stripe 3.3k Jan 5, 2023