mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-21 13:34:08 +00:00
37 lines
909 B
PHP
37 lines
909 B
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Orders\Services;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
class FetchesDataFromYDPortal
|
|
{
|
|
|
|
/**
|
|
* @param string $url
|
|
* @param string $method
|
|
* @param $body
|
|
* @return \Psr\Http\Message\ResponseInterface
|
|
*/
|
|
public function clientRequest(string $url, string $method, $body){
|
|
|
|
$client = new \GuzzleHttp\Client();
|
|
|
|
$body['apicode'] = env('YD_API_CODE');
|
|
|
|
$request = $client->requestAsync($method, $url, ['query' => $body]);
|
|
|
|
return $request->wait();
|
|
}
|
|
|
|
/**
|
|
* @param ResponseInterface $request
|
|
* @return mixed
|
|
*/
|
|
public function getResponseBody(ResponseInterface $request){
|
|
$content = $request->getBody()->getContents();
|
|
$content = str_replace("\r",'', $content);
|
|
$content = str_replace("\n",'', $content);
|
|
return json_decode($content);
|
|
}
|
|
} |