<?php

namespace App\Utilities;

class ApiCalls{
    
    public static function CurlGet($url){
        $baseUrl = "https://api.lupmis4luspa.org/api/";
        $curl = curl_init();

        curl_setopt_array($curl, array(
          CURLOPT_URL => $url,
          CURLOPT_RETURNTRANSFER => true,
          CURLOPT_ENCODING => '',
          CURLOPT_MAXREDIRS => 10,
          CURLOPT_TIMEOUT => 0,
          CURLOPT_FOLLOWLOCATION => true,
          CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
          CURLOPT_CUSTOMREQUEST => 'GET',
          CURLOPT_HTTPHEADER => array(),
        ));

        $response = curl_exec($curl);
        curl_close($curl);
        return $response;

    }
    public static function CurlPost($data, $url){
        $baseUrl = "https://api.lupmis4luspa.org/api/";
        $post_url = $baseUrl . $url;
        $curl = curl_init();
        curl_setopt_array($curl, array(
          CURLOPT_URL => $post_url,
          CURLOPT_RETURNTRANSFER => true,
          CURLOPT_ENCODING => '',
          CURLOPT_MAXREDIRS => 10,
          CURLOPT_TIMEOUT => 0,
          CURLOPT_FOLLOWLOCATION => true,
          CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
          CURLOPT_CUSTOMREQUEST => 'POST',
          CURLOPT_POSTFIELDS => $data,
          CURLOPT_HTTPHEADER => array(
            'Content-Type: application/json'
          ),
        )); 
        $response = curl_exec($curl);
        curl_close($curl);
        return $response;
    }
   
   
    public static function generatePassword($length = 10) {
        return bin2hex(random_bytes($length / 2));
    }

}
