MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/public_html/wp-content/plugins/imageseo/src/Services/Api/Proxy.php
<?php

namespace ImageSeoWP\Services\Api;

if (!defined('ABSPATH')) {
    exit;
}

class Proxy extends BaseClient
{
    /**
     * @param string     $path
     * @param array|null $query
     *
     * @return object|null
     */
    public function get($path, $query = null)
    {
        if (!imageseo_get_api_key()) {
            return null;
        }

        try {
            $url = IMAGESEO_API_URL . $path;

            if (null !== $query) {
                $url = add_query_arg($query, $url);
            }

            $response = wp_remote_get($url, [
                'headers' => $this->getHeaders(),
                'timeout' => 50,
            ]);
        } catch (\Exception $e) {
            return null;
        }

        $total = wp_remote_retrieve_header($response, 'X-Total');
        $body = json_decode(wp_remote_retrieve_body($response), true);

        if (!$total || empty($total)) {
            return $body;
        }

        return [
            'total' => $total,
            'items' => $body,
        ];
    }

    /**
     * @return array
     */
    public function callApi($method, $path, $query = [], $data = [])
    {
        switch ($method) {
            case 'GET':
                return $this->get($path, $query);
                break;
        }
    }
}