Files
aso/app/Services/PrimayaApi.php
2022-12-15 17:10:25 +07:00

124 lines
3.9 KiB
PHP

<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Request;
use Mockery\Generator\Parameter;
use Psy\CodeCleaner\FunctionContextPass;
use Termwind\Components\Dd;
class PrimayaApi
{
/**
* __construct
*
* @param string $KodeRS C,DE,...
* @return void
*/
public function __construct(string $KodeRS)
{
// TODO Feels Wrong
$endpointMaps = [
"C" => [
"base_url" => "http://tgr.primaya.id:1234",
"token" => "1|QGYpSbyi9snAj1bHl1lP6apLJxbl20gsAoPmu1oh",
],
"D" => [
"base_url" => "http://primaya-hospital.com:38588",
"token" => "1|nbVbBmNmm967qYs9dNA0JvFNGvArGFGwFHJ8C9nK",
],
"E" => [
"base_url" => "http://evasari.fortiddns.com:9280",
"token" => "1|qb17AM6BB5sw1a3vZ2BTfIHXbPisqLSBdhwZKGJv",
],
"F" => [
"base_url" => "http://mks.primaya.id:2588",
"token" => null,
],
"M" => [ // Bektim
"base_url" => 'http://101.255.124.84',
"token" => null,
],
"O" => [
"base_url" => "http://rsinco.fortiddns.com:88",
"token" => "1|7e64N6gfSxsBic7DgwVec6EKQAIAx9Dd7is7K5Db",
],
"P" => [
"base_url" => "http://bekut.primaya.id:88",
"token" => "1|N5s4oKJNRnrpA2lneFI5LBhGNq6xwioY6PKDIA10",
],
"Q" => [
"base_url" => "http://krw.primaya.id:4040",
"token" => "1|zyS7AbeqzwKavfXFu0ReQOn5npIjdzVqA0pMqaMt",
],
"N" => [
"base_url" => "http://pky.primaya.id:88",
"token" => "1|yiajZEyu7pBkJNacv60tmb6McimbakG5lGzhm1Oy",
],
"SG" => [
"base_url" => "http://smg.primaya.id:4040",
"token" => "1|2lXZqpzhofXA2IjPdL7z52iBRiqrK5Eio924hMxi",
],
"BW" => [
"base_url" => "http://bwp.primaya.id:4040",
"token" => "1|8I6mdDxSUO0019GbbVx6olcACjaklxLUgmg0zUKh",
],
"SK" => [
"base_url" => "http://skb.primaya.id:4040",
"token" => "1|nYXzAvDbTceumUIDCr9sqXzj2Hq1kvfjYWeVg60P",
],
"PK" => [
"base_url" => "http://pkt.primaya.id:4040",
"token" => "2|nvIdQ7gzJnB7xQhfdjxlkr3oRSqBIvBOunjj72QO",
],
"CK" => [
"base_url" => "http://103.154.92.150:4040",
"token" => "1|BEKJwPhrmyjGwYVbl6xARV2auLSMtgYJyP4E3Kgd",
],
"DE" => [
"base_url" => "http://202.148.23.68:38807",
"token" => "1|DgEL6wte9vmg5X74AUBPVlbMtTIbDqrrp990Kqrt",
],
];
$config = $endpointMaps[$KodeRS];
$this->base_url = !empty($config['base_url']) ? ($config['base_url'] . '/api') : null;
$this->headers = [
'Authorization' => 'Bearer ' . ($config['token'] ?? null)
];
}
public static function getBaseUrl()
{
return config('lms-api.base_url');
}
public static function getDefaultHeaders()
{
return ['id' => config('lms-api.auth_id')];
}
public function consultationPrice($LayananKodes = [], $timeout = 30)
{
$response = Http::timeout($timeout)
->withHeaders($this->headers)
->post(
$this->base_url . '/consultation-price',
empty($LayananKodes) ? null : $LayananKodes
)->json();
return $response;
}
public function doctors($page = 1)
{
$response = Http::withHeaders($this->headers)
->get($this->base_url . '/doctors' . '?page=' . $page)
->json();
return $response;
}
};