<?php

namespace App\Traits;
use GuzzleHttp\Client;


Trait Apitraits
{
    
    
    public function call_api($locatorID=null,$api_url=null)
    {
        $client = new Client();
        $response = $client->request('GET', $api_url.$locatorID,[ 'headers' => [
            'Accept'     => 'application/json',
            'Authorization'  => getenv('API_KEY')]
        ]);
    	$statusCode = $response->getStatusCode();
        $body = $response->getBody()->getContents();
        return $locationDetailAPIdata = json_decode($body,true);
    }


    public function call_api_page($api_url,$locatorID=null,$page=1)
    {
        
        $query_param = array(
            'keyword' => $locatorID,
            'page' => empty($page) ? 1 : $page
        );
        //print_r($query_param);
        
        $client = new Client();
        $response = $client->request('GET', $api_url,[ 'headers' => [
            'Accept'     => 'application/json',
            'Authorization'  => getenv('API_KEY')],
            'query'   => $query_param
        ]);
    	$statusCode = $response->getStatusCode();
        $body = $response->getBody()->getContents();
        return $locationDetailAPIdata = json_decode($body,true);
    }

}