1
0
mirror of https://github.com/ovh/php-ovh.git synced 2023-11-05 03:20:26 +01:00
Go to file
Vincent Casse 4b0afa5684 Test old php versions
Signed-off-by: Vincent Casse <vincent.casse@corp.ovh.com>

Conflicts:
	.travis.yml
2016-02-01 11:49:38 +01:00
examples Add attached domain example 2016-01-21 17:03:06 +01:00
img Add new OVH logo 2014-10-09 18:38:00 +02:00
src Add default timeout on http client 2015-12-15 17:25:42 +01:00
tests Initial commit 2014-10-06 12:57:12 +02:00
.gitignore Improve the PHPUnit setup 2015-03-19 17:12:20 +01:00
.travis.yml Test old php versions 2016-02-01 11:49:38 +01:00
composer.json Improve the PHPUnit setup 2015-03-19 17:12:20 +01:00
CONTRIBUTING.rst Initial commit 2014-10-06 12:57:12 +02:00
Gruntfile.js Initial commit 2014-10-06 12:57:12 +02:00
LICENSE Update License copyright to the current year 2015-10-09 10:04:52 +02:00
MIGRATION.rst Initial commit 2014-10-06 12:57:12 +02:00
package.json change version number 2014-12-10 09:29:22 +01:00
phpunit.xml.dist Improve the PHPUnit setup 2015-03-19 17:12:20 +01:00
README.md Add attached domain example 2016-01-21 17:03:06 +01:00

PHP Wrapper for OVH APIs

This PHP package is a lightweight wrapper for OVH APIs. That's the easiest way to use OVH.com APIs in your PHP applications.

Build Status HHVM Status

<?php
/**
 * # Instantiate. Visit https://api.ovh.com/createToken/index.cgi?GET=/me
 * to get your credentials
 */
require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api;

$ovh = new Api( $applicationKey,
                $applicationSecret,
                $endpoint_name,
                $consumer_key);
echo "Welcome " . $ovh->get('/me')['firstname'];
?>

Quickstart

To download this wrapper and integrate it inside your PHP application, you can use Composer.

Add the repository in your composer.json file or, if you don't already have this file, create it at the root of your project with this content:

{
    "name": "Example Application",
    "description": "This is an example of OVH APIs wrapper usage",
    "require": {
        "ovh/ovh": "dev-master"
    }
}

Then, you can install OVH APIs wrapper and dependencies with:

php composer.phar install

This will install ovh/ovh to ./vendor, along with other dependencies including autoload.php.

OVH cookbook

Do you want to use OVH APIs? Maybe the script you want is already written in the example part of this repository!

How to login as a user?

To communicate with APIs, the SDK uses a token on each request to identify the user. This token is called Consumer Key. To have a validated Consumer Key, you need to redirect your user on specific authentication page. Once the user has logged in, the token is validated and user will be redirected on $redirection url.

<?php
require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api;

session_start();

// Informations about your application
$applicationKey = "your_app_key";
$applicationSecret = "your_app_secret";
$redirection = "http://your_url.ovh";

// Information about API and rights asked
$endpoint = 'ovh-eu';
$rights = array( (object) [
    'method'    => 'GET',
    'path'      => '/me*'
]);

// Get credentials
$conn = new Api($applicationKey, $applicationSecret, $endpoint);
$credentials = $conn->requestCredentials($rights, $redirection);

// Save consumer key and redirect to authentication page
$_SESSION['consumer_key'] = $credentials["consumerKey"];
header('location: '. $credentials["validationUrl"]);
...
?>

How to use OVH API to enable network burst on SBG1 servers?

<?php
require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api;

// Informations about your application
$applicationKey = "your_app_key";
$applicationSecret = "your_app_secret";
$consumer_key = "your_consumer_key";

// Information about API and rights asked
$endpoint = 'ovh-eu';

// Get servers list
$conn = new Api(    $applicationKey,
                    $applicationSecret,
                    $endpoint,
                    $consumer_key);
$servers = $conn->get('/dedicated/server/');

foreach ($servers as $server) {

    // Search servers inside SBG1
    $details = $conn->get('/dedicated/server/'. $server);
    if ($details['datacenter'] == 'sbg1') {

        // Activate burst on server
        $content = (object) array('status' => "active");
        $conn->put('/dedicated/server/'. $server . '/burst', $content);
        echo "We burst " . $server;
    }
}

?>

How to customize HTTP client configuration?

You can inject your own HTTP client with your specific configuration. For instance, you can edit user-agent and timeout for all your requests

<?php
require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api;
use GuzzleHttp\Client;

// Informations about your application
$applicationKey = "your_app_key";
$applicationSecret = "your_app_secret";
$consumer_key = "your_consumer_key";

// Information about API and rights asked
$endpoint = 'ovh-eu';

$client = new Client();
$client->setDefaultOption('timeout', 1);
$client->setDefaultOption('headers', array('User-Agent' => 'api_client') );

// Get servers list
$conn = new Api(    $applicationKey,
                    $applicationSecret,
                    $endpoint,
                    $consumer_key,
                    $client);
$webHosting = $conn->get('/hosting/web/');

foreach ($webHosting as $webHosting) {
        echo "One of our web hosting: " . $webHosting . "\n";

How to build the documentation?

Documentation is based on phpdocumentor. To install it with other quality tools, you can install local npm project in a clone a project

git clone https://github.com/ovh/php-ovh.git
cd php-ovh
php composer.phar install
npm install

To generate documentation, it's possible to use directly:

grunt default

Documentation is available in docs/ directory.

How to run tests?

Tests are based on phpunit. To install it with other quality tools, you can install local npm project in a clone a project

git https://github.com/ovh/php-ovh.git
cd php-ovh
php composer.phar install
npm install

Edit phpunit.xml file with your credentials to pass functionals tests. Then, you can run directly unit and functionals tests with grunt.

grunt

Supported APIs

OVH Europe

OVH North America

So you Start Europe

So you Start North America

Kimsufi Europe

Kimsufi North America

Runabove