Upload files to 'src'

This commit is contained in:
nikkel 2020-03-20 01:46:16 +07:00
parent 01f23590e4
commit 35cef4dbaf

45
src/Client.php Normal file
View File

@ -0,0 +1,45 @@
<?php
namespace Postman;
class Client
{
public function __construct($host, $serverKey)
{
$this->host = $host;
$this->serverKey = $serverKey;
}
public function makeRequest($controller, $action, $parameters)
{
$url = sprintf('%s/api/v1/%s/%s', $this->host, $controller, $action);
// Headers
$headers = [
'x-server-api-key' => $this->serverKey,
'content-type' => 'application/json',
];
// Make the body
$json = json_encode($parameters);
// Make the request
$response = \Requests::post($url, $headers, $json);
if ($response->status_code === 200) {
$json = json_decode($response->body);
if ($json->status == 'success') {
return $json->data;
} else {
if (isset($json->data->code)) {
throw new Error(sprintf('[%s] %s', $json->data->code, $json->data->message));
} else {
throw new Error($json->data->message);
}
}
}
throw new Error('Couldnt send message to API');
}
}