All Projects → ovh → Php Ovh

ovh / Php Ovh

Licence: other
Lightweight PHP wrapper for OVH APIs. That's the easiest way to use OVH.com APIs in your PHP applications.

Projects that are alternatives of or similar to Php Ovh

Twitch Python
Object-oriented Twitch API for Python developers
Stars: ✭ 138 (-40%)
Mutual labels:  api-wrapper
Redd
Redd is a batteries-included API wrapper for reddit.
Stars: ✭ 180 (-21.74%)
Mutual labels:  api-wrapper
Discogs
A Ruby wrapper of the Discogs.com API
Stars: ✭ 195 (-15.22%)
Mutual labels:  api-wrapper
Census Data Downloader
Download U.S. census data and reformat it for humans
Stars: ✭ 149 (-35.22%)
Mutual labels:  api-wrapper
Coingecko Api
A Node.js wrapper for the CoinGecko API with no dependencies.
Stars: ✭ 159 (-30.87%)
Mutual labels:  api-wrapper
Graphql2rest
GraphQL to REST converter: automatically generate a RESTful API from your existing GraphQL API
Stars: ✭ 181 (-21.3%)
Mutual labels:  api-wrapper
Basic Shopify Api
A simple API wrapper for Shopify using Guzzle for REST and GraphQL
Stars: ✭ 137 (-40.43%)
Mutual labels:  api-wrapper
Taxize
A taxonomic toolbelt for R
Stars: ✭ 209 (-9.13%)
Mutual labels:  api-wrapper
Nipyapi
A convenient Python wrapper for Apache NiFi
Stars: ✭ 169 (-26.52%)
Mutual labels:  api-wrapper
Github4s
A GitHub API wrapper written in Scala
Stars: ✭ 194 (-15.65%)
Mutual labels:  api-wrapper
Pinterest Api Php
A PHP wrapper for the official Pinterest API. 📌
Stars: ✭ 151 (-34.35%)
Mutual labels:  api-wrapper
Jda
Java wrapper for the popular chat & VOIP service: Discord https://discord.com
Stars: ✭ 2,598 (+1029.57%)
Mutual labels:  api-wrapper
Riot Api Java
Riot Games API Java Library
Stars: ✭ 184 (-20%)
Mutual labels:  api-wrapper
Mega.py
Python library for the https://mega.nz/ API.
Stars: ✭ 145 (-36.96%)
Mutual labels:  api-wrapper
Binance
A .NET Standard Binance API library.
Stars: ✭ 199 (-13.48%)
Mutual labels:  api-wrapper
Rcrossref
R client for various CrossRef APIs
Stars: ✭ 137 (-40.43%)
Mutual labels:  api-wrapper
Pybliometrics
Python-based API-Wrapper to access Scopus
Stars: ✭ 181 (-21.3%)
Mutual labels:  api-wrapper
Python Ovh
Thin wrapper around OVH's APIs. Handles all the hard work including credential creation and requests signing.
Stars: ✭ 213 (-7.39%)
Mutual labels:  api-wrapper
Python Onedrive
Obsolete python/cli module for MS SkyDrive/OneDrive's old API, do not use for new projects
Stars: ✭ 202 (-12.17%)
Mutual labels:  api-wrapper
Virustotal Api
Virus Total Public/Private/Intel API
Stars: ✭ 189 (-17.83%)
Mutual labels:  api-wrapper

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,
                $consumer_key);
echo "Welcome " . $ovh->get('/me')['firstname'];
?>

Quickstart

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

Quick integration with the following command:

composer require ovh/ovh

Or 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 print API error details?

Under the hood, php-ovh uses GuzzlePHP 6 by default to issue API requests. If everything goes well, it will return the response directly as shown in the examples above. If there is an error like a missing endpoint or object (404), an authentication or authorization error (401 or 403) or a parameter error, the Guzzle will raise a GuzzleHttp\Exception\ClientException exception. For server-side errors (5xx), it will raise a GuzzleHttp\Exception\ServerException exception.

You can get the error details with a code like:

<?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,
                $consumer_key);

try {
    echo "Welcome " . $ovh->get('/me')['firstname'];
} catch (GuzzleHttp\Exception\ClientException $e) {
    $response = $e->getResponse();
    $responseBodyAsString = $response->getBody()->getContents();
    echo $responseBodyAsString;
}
?>

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

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

vendor/bin/phing phpdocs

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
vendor/bin/phpunit tests/ApiTest.php

To run functionals tests, you need to provide valid API credentials, that you can provide them via environment:

APP_KEY=xxx APP_SECRET=xxx CONSUMER=xxx ENDPOINT=xxx vendor/bin/phpunit tests/ApiFunctionalTest.php

Supported APIs

OVH Europe

OVH US

OVH North America

So you Start Europe

So you Start North America

Kimsufi Europe

Kimsufi North America

Runabove

Related links

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].