<?php
 
$out = array();
$in  = array();
$in  = [
    "uid"=> "3119b744-42ad-4834-bb83-b737588754ca",
    "member_id"=> "1",
    "sessionid"=> "228C544A7E81E9E6E8B2C5A33A27FADD101881EDF33AA624FD4A1703F51AABB7",
    "page"=> 0,
    "limit"=> 100
];

$local_url = "http://10.0.0.248:3033/marketjobs";
$res = APIcall('GET', $local_url, $in);

var_dump($res);

//wrenchboard_api($in,$out);

 function wrenchboard_api($in, &$out = array(),$pathWay='') {
    $ret = 0;
    $local_url = "http://10.10.10.120:3033/marketjobs";
    $local_url = "http://10.0.0.248:3033/marketjobs";
    $url = $local_url ; // ."/".$urlPath; //"/generics";
    $data = $in;
    //$content = json_encode($data);
    $content ='?';

    foreach ($in as $key => $value) {
        $content .= "{$key}={$value}&";
    }

    //echo  urlencode($content);

    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_URL,$content);
    curl_setopt($curl, CURLOPT_HEADER, false);
    //curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type" => "application/json"));
   // curl_setopt($curl, CURLOPT_POST, true); // true to make POST
   // curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

    $json_response = curl_exec($curl);
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

    if ($status != 200) {
        echo ("Error: call to URL $url failed with status $status, response $json_response,  | curl_error " . curl_error($curl) . ", | curl_errno " . curl_errno($curl));
    }

    curl_close($curl);
    $response = json_decode($json_response, true);
    var_dump( $json_response );
    $out = $response;
    return $response["internal_return"] ?? -99;
}

$url = 'RequiredLink';
$data = [
    'collection'  => 'RequiredAPI'
];
  



 
function APIcall($method, $url, $data) {
  //  $curl = curl_init();
    $curl = curl_init($url);
    switch ($method) {
        case "POST":
            curl_setopt($curl, CURLOPT_POST, 1);
            if ($data)
                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
            break;
        case "PUT":
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
            if ($data)
                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
            break;
    }
    
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
        'APIKEY: RegisteredAPIkey',
        'Content-Type: application/json',
    ));
    
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    $result = curl_exec($curl);
     
    if(!$result) {
        echo("Connection failure!");
    }
    curl_close($curl);
    return $result;
}

