Created
April 1, 2018 11:43
-
-
Save freretuc/bb98f3339ccae5ac91aaea04473df4db to your computer and use it in GitHub Desktop.
OVH API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$ovh = array(); | |
$ovh['api_url'] = "eu.api.ovh.com"; | |
$ovh['app_key'] = "__APP_KEY__"; | |
$ovh['app_secret'] = "__APP_SECRET__"; | |
$ovh['consumer_key'] = "__CONSUMER_KEY__"; | |
function ovh_time(){ | |
global $ovh; | |
$curl = curl_init(); | |
curl_setopt_array($curl, array( | |
CURLOPT_RETURNTRANSFER => 1, | |
CURLOPT_URL => 'https://' . $ovh['api_url'] . '/1.0/auth/time' | |
)); | |
$output = curl_exec($curl); | |
curl_close($curl); | |
return $output; | |
} | |
function ovh_get($url) { | |
global $ovh; | |
$api_time = ovh_time(); | |
$api_data = NULL; | |
$api_method = "GET"; | |
$api_url = 'https://' . $ovh['api_url'] .'/1.0' . $url; | |
$api_signature = '$1$'.sha1($ovh['app_secret'] . '+' . $ovh['consumer_key'] . '+' . $api_method . '+' . $api_url . '+' . $api_data . '+' . $api_time); | |
$headers = array(); | |
$headers[] = 'Content-Type:'.'application/json; charset=utf-8'; | |
$headers[] = 'X-Ovh-Application:' . $ovh['app_key'] ; | |
$headers[] = 'X-Ovh-Timestamp:' . $api_time; | |
$headers[] = 'X-Ovh-Signature:' . $api_signature; | |
$headers[] = 'X-Ovh-Consumer:' . $ovh['consumer_key']; | |
return ovh_curl($api_url, $headers, $api_method, $api_data); | |
} | |
function ovh_post($url, $data) { | |
global $ovh; | |
$api_time = ovh_time(); | |
$api_data = json_encode($data); | |
$api_method = "POST"; | |
$api_url = 'https://' . $ovh['api_url'] .'/1.0' . $url; | |
$api_signature = '$1$'.sha1($ovh['app_secret'] . '+' . $ovh['consumer_key'] . '+' . $api_method . '+' . $api_url . '+' . $api_data . '+' . $api_time); | |
$headers = array(); | |
$headers[] = 'Content-Type:'.'application/json; charset=utf-8'; | |
$headers[] = 'X-Ovh-Application:' . $ovh['app_key'] ; | |
$headers[] = 'X-Ovh-Timestamp:' . $api_time; | |
$headers[] = 'X-Ovh-Signature:' . $api_signature; | |
$headers[] = 'X-Ovh-Consumer:' . $ovh['consumer_key']; | |
return ovh_curl($api_url, $headers, $api_method, $api_data); | |
} | |
function ovh_curl($url, $headers, $method, $data) { | |
$curl = curl_init(); | |
curl_setopt_array($curl, array( | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_URL => $url, | |
CURLOPT_HTTPHEADER => $headers, | |
CURLOPT_CUSTOMREQUEST => $method, | |
CURLOPT_POSTFIELDS => $data | |
)); | |
$result = curl_exec($curl); | |
$result = json_decode($result, true); | |
curl_close($curl); | |
return $result; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment