I have this PHP class for an API:
class Integra {
public function __construct()
{
$this->api_key = 'API-XXXXXXX';
$this->api_salt = '';
}
public function build_query($type, $data = array())
{
//$salted = hash_hmac('md5', $this->api_key, $this->api_salt);
//$data['api_key'] = $salted;
//$data['key'] = $this->api_key;
$params = $data;
$data_string = json_encode($params);
$ch = curl_init('http://domain.com/api.php');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json')
);
$response = curl_exec($ch);
curl_close($ch);
$response = json_decode($response);
return $response;
}
}
so this is posting data to the relevant page/function.
I want to be able to return the data as objects, i have tried the following on the page that the data is being posted to but nothing is being returned.
What have i done wrong?
<?php
return array('status' => 'test', 'reason' => 'test2');
?>
Here is how i call the class and function:
$Integra = new Integra();
$output = $Integra->build_query('check_system.php');
echo $output->reason;
echo $output->status;