Created
February 16, 2019 10:21
-
-
Save th3d0g/e06401a6a551fcad63cf9cb68f913e91 to your computer and use it in GitHub Desktop.
AWR API PHP
This file contains hidden or 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 | |
// AWR Functions ////////////// | |
function awr_get( $action, $params = [] ){ | |
$token = env('AWR_KEY'); | |
$awr_url = env('AWR_URL'); | |
$paramsString = ""; | |
if( count($params) > 0 ){ | |
// Note; encode params as PHP_QUERY_RFC1738 uses "+" as space, which is what AWR API expects. | |
$paramsString = "&" . http_build_query( $params, null, '&', PHP_QUERY_RFC1738); | |
} | |
$url = "https://api.awrcloud.com/v2/get.php?action={$action}&token={$token}{$paramsString}"; | |
$curl = curl_init(); | |
curl_setopt($curl,CURLOPT_URL, $url); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
$result = curl_exec($curl); | |
curl_close($curl); | |
return json_decode( $result, false ); | |
} | |
function awr_post( $action, $data ){ | |
$token = env('AWR_KEY'); | |
$projects = array(); | |
$prj1 = array("name" => "project1"); | |
$prj2 = array("name" => "project2"); | |
$prj3 = array("name" => "project3"); | |
$projects[] = $prj1; | |
$projects[] = $prj2; | |
$projects[] = $prj3; | |
$inputs = array("projects" => $projects); | |
$data = array('inputs' => json_encode($inputs)); | |
$url = "https://api.awrcloud.com/v2/get.php?action={$action}&token={$token}"; | |
$curl = curl_init(); | |
curl_setopt($curl,CURLOPT_URL, $url); | |
curl_setopt($curl,CURLOPT_POST, sizeof($data)); | |
curl_setopt($curl,CURLOPT_POSTFIELDS, $data); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
$result = curl_exec($curl); | |
curl_close($curl); | |
// return $result; | |
return json_decode( $result, false ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment