MOON
Server: Apache/2.2.34 (Unix) mod_ssl/2.2.34 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 FrontPage/5.0.2.2635
System: Linux server.asjudinet.com 2.6.32-042stab141.3 #1 SMP Fri Nov 15 22:45:34 MSK 2019 i686
User: asjudine (504)
PHP: 5.2.17
Disabled: NONE
Upload Files
File: /home/asjudine/public_html/client.php
<?php

    class Client extends Resource {

        private $url = 'https://www.elibom.com/';

        public function post($resource, $data) {
            $data_string = json_encode($data);

            $handler = curl_init($this->url . $resource);

            curl_setopt($handler, CURLOPT_POST, true);
            curl_setopt($handler, CURLOPT_RETURNTRANSFER, true); 
            curl_setopt($handler, CURLOPT_SSL_VERIFYPEER, false);

            $this->configureHeaders($handler, $data_string);

            curl_setopt($handler, CURLOPT_POSTFIELDS, $data_string);

            $response = curl_exec ($handler);
            $code = curl_getinfo($handler, CURLINFO_HTTP_CODE);
            if ($code != 200) {
                $errorMessage = $this->getErrorMessage($code, $resource);
                throw new Exception($errorMessage);
            }

            return json_decode($response);
        }

        public function get($resource, $data = '{}') {
            $data_string = json_encode($data);

            $handler = curl_init($this->url . $resource);

            //curl_setopt($handler, CURLOPT_GET, true);
            curl_setopt($handler, CURLOPT_CUSTOMREQUEST, "GET");
            curl_setopt($handler, CURLOPT_RETURNTRANSFER, true); 
            curl_setopt($handler, CURLOPT_SSL_VERIFYPEER, false);

            $this->configureHeaders($handler, $data_string);

            curl_setopt($handler, CURLOPT_POSTFIELDS, $data_string);

            $response = curl_exec ($handler);
            $code = curl_getinfo($handler, CURLINFO_HTTP_CODE);
            if ($code != 200) {
                $errorMessage = $this->getErrorMessage($code, $resource);
                throw new Exception($errorMessage);
            }

            return json_decode($response);
        }

        public function delete($resource, $data = '{}') {
            $data_string = json_encode($data);

            $handler = curl_init($this->url . $resource);

            curl_setopt($handler, CURLOPT_CUSTOMREQUEST, 'DELETE');
            curl_setopt($handler, CURLOPT_RETURNTRANSFER, true); 
            curl_setopt($handler, CURLOPT_SSL_VERIFYPEER, false);

            $this->configureHeaders($handler, $data_string);

            curl_setopt($handler, CURLOPT_POSTFIELDS, $data_string);

            $response = curl_exec ($handler);
            $code = curl_getinfo($handler, CURLINFO_HTTP_CODE);
            if ($code != 200) {
                $errorMessage = $this->getErrorMessage($code, $resource);
                throw new Exception($errorMessage);
            }

            return json_decode($response);
        }

        private function configureHeaders($handler, $data_string) {
            $auth_string = $this->user .":" . $this->token;
            $auth = base64_encode ($auth_string);
            curl_setopt($handler, CURLOPT_HTTPHEADER, array(
                'Authorization: Basic ' . $auth,
                'Content-Type: application/json',
                'Content-Length: ' . strlen($data_string),
                'X-API-Source: ' . 'php-1.0.5' 
                )
            );
        }

        private function getErrorMessage($code, $resource) {
            switch($code) {
                case 0 : {
                    return 'Server not found, check your internet connection or proxy configuration.';
                }
                case 401 : {
                    return 'Unauthorized resource [' . $resource . ']. Check your user credentials';
                }
                default : {
                    return 'Unexpected error [' . $resource . '] [code=' . $code . ']';
                }
            }
        }
    }

?>