HEX
Server: Apache
System: Linux c265a.dattaweb.com 4.18.0-553.97.1.el8_10.x86_64 #1 SMP Mon Jan 26 05:26:16 EST 2026 x86_64
User: c2650654 (20026)
PHP: 8.3.31
Disabled: system, shell, exec, system_exec, shell_exec, mysql_pconnect, passthru, popen, proc_open, proc_close, proc_nice, proc_terminate, proc_get_status, escapeshellarg, escapeshellcmd, eval, dl, imap_mail, libvirt_connect, gnupg_init, unsetenv, apache_setenv, pcntl_exec, pcntl_alarm, pcntl_fork, pcntl_waitpid, pcntl_wait, pcntl_wifexited, pcntl_wifstopped, pcntl_wifsignaled, pcntl_wifcontinued, pcntl_wexitstatus, pcntl_wtermsig, pcntl_wstopsig, pcntl_signal, pcntl_signal_get_handler, pcntl_signal_dispatch, pcntl_get_last_error, pcntl_strerror, pcntl_sigprocmask, pcntl_sigwaitinfo, pcntl_sigtimedwait, pcntl_getpriority, pcntl_setpriority, pcntl_async_signals, opcache_get_status, opcache_reset, opcache_get_configuration
Upload Files
File: /home/c2650654/public_html/wp-content/plugins/skydropx/api/class-skydropx-api-connector.php
<?php


/**
 * Class API
 *
 * @package  Skydropx\Api
 */
namespace Skydropx\Api;

use Skydropx\Helper\Helper;

abstract class Skydropx_api_connector {
	/**
	 * Executes API Request
	 *
	 * @param string $method
	 * @param string $url
	 * @param array  $body
	 * @param array  $headers
	 * @return string
	 */
	protected function exec( string $method, string $url, array $body, array $headers ) {

		$args['timeout'] = 10;
		$args['method']  = $method;
		$args['headers'] = $headers;
		if ( strtoupper( $method ) === 'GET' ) {
			$args['body'] = $body;
		} else {
			$args['body'] = wp_json_encode( $body, JSON_UNESCAPED_UNICODE );
		}

		$request = wp_safe_remote_request( $url, $args );
		Helper::log( "==============================================>" );
		Helper::log( "Request >\nURL: " . $url . "\nHeader: " . wp_json_encode( $headers, JSON_UNESCAPED_UNICODE ) . "\nBody: " . wp_json_encode( $body, JSON_UNESCAPED_UNICODE ));

		if ( is_wp_error( $request ) ) {
			Helper::log( "ERROR" );
			Helper::log( $request );
			return false;
		}

		$response = wp_remote_retrieve_body( $request );
		Helper::log( "Response Code: " . $request["response"]["code"] . "\nBody: " . $response );

		if ( 200 === $request['response']['code'] ) {
			return json_decode( $response, true );
		} 
		return array( 'errors' => json_decode( $response, true ) );
	}

	/**
	 * Executes Post Request
	 *
	 * @param string $endpoint
	 * @param array  $body
	 * @param array  $headers
	 * @return string
	 */
	public function post( string $endpoint, array $body = array(), array $headers = array() ) {
		$url = $this->get_base_url() . $endpoint;
		return $this->exec( 'POST', esc_url($url), $body, $headers );
	}

	/**
	 * Executes Get Request
	 *
	 * @param string $endpoint
	 * @param array  $body
	 * @param array  $headers
	 * @return string
	 */
	public function get( string $endpoint, array $body = array(), array $headers = array() ) {
		$url = $this->get_base_url() . $endpoint;
		if ( ! empty( $body ) ) {
			$url .= '?' . http_build_query( $body );
		}
		return $this->exec( 'GET', esc_url($url), array(), $headers );
	}

	/**
	 * Executes Put Request
	 *
	 * @param string $endpoint
	 * @param array  $body
	 * @param array  $headers
	 * @return string
	 */
	public function put( string $endpoint, array $body = array(), array $headers = array() ) {
		$url = $this->get_base_url() . $endpoint;
		return $this->exec( 'PUT', esc_url($url), $body, $headers );
	}

	/**
	 * Executes Delete Request
	 *
	 * @param string $endpoint
	 * @param array  $body
	 * @param array  $headers
	 * @return string
	 */
	public function delete( string $endpoint, array $body = array(), array $headers = array() ) {
		$url = $this->get_base_url() . $endpoint;
		return $this->exec( 'DELETE', esc_url($url), $body, $headers );
	}

	/**
	 * Add Get Params to URL
	 *
	 * @param string $url
	 * @param array  $params
	 * @return string
	 */
	protected function add_params_to_url( $url, $params ) {
		if ( strpos( $url, '?' ) !== false ) {
			$url .= '&' . $params;
		} else {
			$url .= '?' . $params;
		}
		return esc_url($url);
	}

	/**
	 * Get API Base URL
	 *
	 * @return string
	 */
	abstract public function get_base_url();
}