Example #1
1
 /**
  * Test Api::get
  */
 public function testApiGetWithParameters()
 {
     $this->setExpectedException('\\GuzzleHttp\\Exception\\ClientException', '400');
     $this->api->get('/me/accessRestriction/ip', ['foo' => 'bar']);
 }
Example #2
0
 /**
  * Get details for a sender
  *
  * @param string $sender Sender to get details
  *
  * @return mixed
  * @throws \GuzzleHttp\Exception\ClientException if http request returns an error
  */
 public function getSenderDetails($sender)
 {
     if (is_null($this->account)) {
         throw new \Ovh\Exceptions\InvalidParameterException("Please set account before using this function");
     }
     if (!isset($sender)) {
         throw new \Ovh\Exceptions\InvalidParameterException("Sender parameter is empty");
     }
     return $this->conn->get("/sms/" . $this->account . "/senders/{$sender}");
 }
// Informations about your web hosting and the attached domain (compulsory)
$domain = 'mydomain.ovh';
// Web hosting id (often domain ordered with it)
$domainToAttach = 'myotherdomaintoattach.ovh';
$path = 'otherFolder';
// Folder where website files are stored
// Informations about the attached domain (optional)
$cdn = 'none';
// Enable CDN on the attached domain. Can be NULL, 'none' or 'active'
$firewall = 'none';
// Enable HTTP firewall (block dangerous pattern requests with Apache mod_security). Can be NULL, 'active' or 'none'
$ownLog = 'myotherdomaintoattach.ovh';
// Separate logs by domain. Can be 'null' or domain offer you have at OVH
$http_client = new Client(['timeout' => 30, 'connect_timeout' => 5]);
// Create a new attached domain
$conn = new Api($applicationKey, $applicationSecret, $endpoint, $consumer_key, $http_client);
try {
    // This call will create a "task". The task is the status of the attached domain creation.
    // You can follow the task on /hosting/web/{serviceName}/tasks/{id}
    $task = $conn->post('/hosting/web/' . $domain . '/attachedDomain', array('domain' => $domainToAttach, 'path' => $path, 'cdn' => $cdn, 'firewall' => $firewall, 'ownLog' => $ownLog));
    echo "Task #" . $task['id'] . " is created" . PHP_EOL;
    // we check every 5 seconds if the task is done
    // When the task disappears, the task is done
    while (1) {
        try {
            $wait = $conn->get('/hosting/web/' . $domain . '/tasks/' . $task['id']);
            if (strcmp($wait['status'], 'error') === 0) {
                // The task is in error state. Please check your parameters, retry or contact support.
                echo "An error has occured during the task" . PHP_EOL;
                break;
            } elseif (strcmp($wait['status'], 'cancelled') === 0) {
Example #4
0
<?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';
// Information about your web hosting
$web_hosting = 'my_domain';
// Get servers list
$conn = new Api($applicationKey, $applicationSecret, $endpoint, $consumer_key);
$hosting = $conn->get('/hosting/web/' . $web_hosting);
print_r($conn->get('/hosting/web/offerCapabilities', array('offer' => $hosting['offer'])));
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';
// Informations about your web hosting and the attached domain (compulsory)
$domain = 'mydomain.ovh';
// Web hosting id (often domain order with it)
$domainToAttach = 'myotherdomaintoattach.ovh';
$http_client = new Client(['timeout' => 30, 'connect_timeout' => 5]);
// Create a new attached domain
$conn = new Api($applicationKey, $applicationSecret, $endpoint, $consumer_key, $http_client);
try {
    // This call will create a "task". The task is the status of the attached domain deletion.
    // You can follow the task on /hosting/web/{serviceName}/tasks/{id}
    $task = $conn->delete('/hosting/web/' . $domain . '/attachedDomain/' . $domainToDetach);
    echo "Task #" . $task['id'] . " is created" . PHP_EOL;
    // we check every 5 seconds if task is done
    // When the task disappears, the task is done
    while (1) {
        try {
            $wait = $conn->get('/hosting/web/' . $domain . '/tasks/' . $task['id']);
            if (strcmp($wait['status'], 'error') === 0) {
                // The task is in error state. Please check your parameters, retry or contact support.
                echo "An error has occured during the task" . PHP_EOL;
                break;
            } elseif (strcmp($wait['status'], 'cancelled') === 0) {
Example #6
0
 /**
  * Test invalid applicationKey
  */
 public function testInvalidApplicationKey()
 {
     $this->setExpectedException('\\GuzzleHttp\\Exception\\ClientException');
     $delay = 10;
     $mock = new Mock(["HTTP/1.1 401 Unauthorized\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: 37\r\n\r\n{\"message\":\"Invalid application key\"}"]);
     $this->client->getEmitter()->attach($mock);
     $property = self::getPrivateProperty('consumer_key');
     $api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client);
     $accessRules = array(json_decode(' { "method": "GET", "path": "/*" } '));
     $credentials = $api->requestCredentials($accessRules);
     $consumer_key = $property->getValue($api);
     $this->assertEquals($consumer_key, $credentials["consumerKey"]);
     $this->assertNotEquals($consumer_key, $this->consumer_key);
 }
Example #7
0
$consumer_key = "your_consumer_key";
// Information about API endpoint used
$endpoint = 'ovh-eu';
// Information about your domain and redirection
$domain = 'yourdomain.ovh';
$subDomain = 'www';
// Here, the redirection will come from www.yourdomain.com
$targetDomain = 'my_target.ovh';
$type = 'visible';
// can be "visible", "invisible", "visiblePermanent"
// Field to set in case of invisible redirection
$title = '';
$keywords = '';
$description = '';
// Get servers list
$conn = new Api($applicationKey, $applicationSecret, $endpoint, $consumer_key);
try {
    // check if dns record are available
    $recordIds = $conn->get('/domain/zone/' . $domain . '/record?subDomain=' . $subDomain);
    // If subdomain is not defined, we don't want to delete all A, AAAA and CNAME records
    if (isset($subDomain)) {
        foreach ($recordIds as $recordId) {
            $record = $conn->get('/domain/zone/' . $domain . '/record/' . $recordId);
            // If record include A, AAAA or CNAME for subdomain asked, we delete it
            if (in_array($record['fieldType'], array('A', 'AAAA', 'CNAME'))) {
                echo "We will delete field " . $record['fieldType'] . " for " . $record['subDomain'] . $record['zone'] . PHP_EOL;
                $conn->delete('/domain/zone/' . $domain . '/record/' . $recordId);
            }
        }
    }
    // Now, we are ready to create our new redirection
<?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';
// Information about your web hosting(compulsory)
$domain = 'mydomain.ovh';
// Web hosting id (often domain order with it)
$http_client = new Client(['timeout' => 30, 'connect_timeout' => 5]);
// Create a new attached domain
$conn = new Api($applicationKey, $applicationSecret, $endpoint, $consumer_key, $http_client);
try {
    $attachedDomainsIds = $conn->get('/hosting/web/' . $domain . '/attachedDomain');
    foreach ($attachedDomainsIds as $attachedDomainsId) {
        $attachedDomain = $conn->get('/hosting/web/' . $domain . '/attachedDomain/' . $attachedDomainsId);
        print_r($attachedDomain);
    }
} catch (Exception $ex) {
    print_r($ex->getMessage());
}
Example #9
0
 public function testGetConsumerKey()
 {
     $api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client);
     $this->assertEquals($this->consumer_key, $api->getConsumerKey());
 }
Example #10
0
$endpoint = "ovh-eu";
$ask1 = "mAcXugeOcn2gZBvyb76bKvN1y2gACqmz";
$csk1 = "VTYF8K727bsg42Qn5so76iYb3994jbjp";
$ovh1 = new Ovh\Api($apk1, $ask1, $endpoint, $csk1);
$me1 = $ovh1->get("/me");
$apk2 = "nP9Ij0PFvlZw0wV6";
$endpoint = "ovh-eu";
$ask2 = "GpwkoBOZijNgqYFygxyEg2zMSGg4X3pX";
$csk2 = "tGEmEglYpqu2xkdOTM563FAQ3Y9sPJys";
$ovh2 = new Api($apk2, $ask2, $endpoint, $csk2);
$me2 = $ovh2->get("/me");
$apk3 = "YDrgCr1VvT3LtVf8";
$endpoint = "ovh-eu";
$ask3 = "eKekzBFbKfWeh3gKB1Fb4n9zXa16D6D2";
$csk3 = "5tQNjCGSfYHdxetHfWORhOvGufGXlFBg";
$ovh3 = new Api($apk3, $ask3, $endpoint, $csk3);
$me3 = $ovh3->get("/me");
require_once dirname(__DIR__) . "/classe/user.php";
$user_cls = new user();
$user = $user_cls->info_user($login);
require_once dirname(__DIR__) . "/classe/general.php";
$gen_cls = new general();
require_once dirname(__DIR__) . "/classe/paypal.php";
require_once dirname(__DIR__) . "/classe/gestion/client.php";
$client_cls = new client();
require_once dirname(__DIR__) . "/classe/gestion/devis.php";
$devis_cls = new devis();
require_once dirname(__DIR__) . "/classe/gestion/facture.php";
$facture_cls = new facture();
require_once dirname(__DIR__) . "/classe/gestion/article.php";
$article_cls = new article();
Example #11
0
 /**
  * Test Api::get, should build valide signature
  */
 public function testApiGetWithQueryString()
 {
     $this->api->get('/me/api/credential', ['status' => 'pendingValidation']);
 }
Example #12
0
 public function call($method, $parameters = null)
 {
     $conn = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key);
     return $conn->get($method, $parameters);
 }