Files
Chamilo/vendor/culqi/culqi-php/lib/Culqi/Client.php
T
Xes 73154ae174
Behat tests 1.11.x 🐞 / PHP 7.4 Test on ubuntu-latest (push) Canceled after 0s
PHP-CS-Fixer / composer_install (7.4) (push) Canceled after 0s
Chamilo 1.11.40 (ZIP oficial v1.11.40)
Fuente: https://github.com/chamilo/chamilo-lms/releases/download/v1.11.40/chamilo-1.11.40.zip
sha256: 1cf4bf2cc7bae1ef1a1eff643235db1d552f78ddf4b6dd1e2d2dac9868679439
Snapshot independiente (rama huerfana); diffable vs 1.11.38. vendor incluido.
2026-08-06 17:59:45 +02:00

52 lines
1.9 KiB
PHP

<?php
namespace Culqi;
use Culqi\Error as Errors;
/**
* Class Client
*
* @package Culqi
*/
class Client {
public function request($method, $url, $api_key, $data = NULL) {
try {
$url_params = is_array($data) ? '?' . http_build_query($data) : '';
$headers= array("Authorization" => "Bearer ".$api_key, "Content-Type" => "application/json", "Accept" => "application/json");
$options = array(
'timeout' => 120
);
if($method == "GET") {
$response = \Requests::get(Culqi::BASE_URL. $url . $url_params, $headers, $options);
} else if($method == "POST") {
$response = \Requests::post(Culqi::BASE_URL . $url, $headers, json_encode($data), $options);
} else if($method == "PATCH") {
$response = \Requests::patch(Culqi::BASE_URL . $url, $headers, json_encode($data), $options);
} else if($method == "DELETE") {
$response = \Requests::delete(Culqi::BASE_URL. $url . $url_params, $headers, $options);
}
} catch (\Exception $e) {
throw new Errors\UnableToConnect();
}
if ($response->status_code >= 200 && $response->status_code <= 206) {
return json_decode($response->body);
}
if ($response->status_code == 400) {
throw new Errors\UnhandledError($response->body, $response->status_code);
}
if ($response->status_code == 401) {
throw new Errors\AuthenticationError();
}
if ($response->status_code == 404) {
throw new Errors\NotFound();
}
if ($response->status_code == 403) {
throw new Errors\InvalidApiKey();
}
if ($response->status_code == 405) {
throw new Errors\MethodNotAllowed();
}
throw new Errors\UnhandledError($response->body, $response->status_code);
}
}