You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
rest-api/api.php

55 lines
1.4 KiB

<?php
class Redirect {
__construct($endpoint, $apiKey) {
$this->endpoint = $endpoint;
$this->apiKey = $apiKey;
}
function _call() {
$ch = curl_init($endpoint);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Accept: application/json',
'Content-Type: application/json',
"X-API-Key: $apikey",
],
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
curl_close($ch);
throw new Exception(curl_error($ch));
} else {
curl_close($ch);
print_r($httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return (object)[ 'status' => httpCode, 'response' => json_decode($response)];
}
function add($payload) {
$ch = curl_init($endpoint);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Accept: application/json',
'Content-Type: application/json',
"X-API-Key: $apikey",
],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
curl_close($ch);
throw new Exception(curl_error($ch));
} else {
curl_close($ch);
print_r($httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return (object)[ 'status' => httpCode, 'response' => json_decode($response)];
}
}
}