113 lines
4.4 KiB
PHP
113 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Auth;
|
|
use Log;
|
|
|
|
class LambdaRequest
|
|
{
|
|
protected const REMOTE_ENV = 'production';
|
|
protected const LOCAL_URLS = [
|
|
'ums' => 'http://localhost:3010/dev/',
|
|
'mag' => 'http://localhost:3012/dev/',
|
|
'wall' => 'http://localhost:3011/dev/',
|
|
'metric' => 'http://localhost:3013/dev/',
|
|
'recognition' => 'http://localhost:3014/dev/',
|
|
'form' => 'http://localhost:3015/dev/',
|
|
'detailing' => 'http://localhost:3016/dev/',
|
|
'competition' => 'http://localhost:3017/dev/',
|
|
'communication' => 'http://localhost:3018/dev/',
|
|
'catalog' => 'http://localhost:3020/dev/',
|
|
];
|
|
protected const PROD_URL = 'https://rapportapi.click/';
|
|
|
|
protected static function genurl($service, $url) {
|
|
switch(true) {
|
|
case self::REMOTE_ENV != 'local' && $service == 'ums' && $url == 'hierarchy/get_all':
|
|
return 'https://ljtw6cnu6kzxm3s76upgsvmz5u0ufrep.lambda-url.ap-south-1.on.aws/';
|
|
break;
|
|
case self::REMOTE_ENV != 'local' && $service == 'metric' && $url == 'metric_report/view':
|
|
return 'https://zbmttswaqimy3nmo5wactmja3i0uosyv.lambda-url.ap-south-1.on.aws/';
|
|
break;
|
|
case self::REMOTE_ENV != 'local' && $service == 'form' && $url == 'survey/getformhistory':
|
|
return 'https://tvp2drn5c2jpf7dpxdwwykdez40ikfbz.lambda-url.ap-south-1.on.aws/';
|
|
break;
|
|
case self::REMOTE_ENV != 'local' && $service == 'form' && $url == 'formentity/getformhistory':
|
|
return 'https://sgrmuxa46z7xfouezyvg3tnhnq0yptjn.lambda-url.ap-south-1.on.aws/';
|
|
break;
|
|
case self::REMOTE_ENV != 'local' && $service == 'form' && $url == 'formentity/getforminfo':
|
|
return 'https://bopqsnxa2ssc2dqmrs26ekslhu0uqmzx.lambda-url.ap-south-1.on.aws/';
|
|
break;
|
|
case self::REMOTE_ENV != 'local' && $service == 'catalog' && $url == 'activity/nyexecutionfollowup':
|
|
return 'https://4sat7sjmmslqwq6nil2kxjxm6y0afoii.lambda-url.ap-south-1.on.aws/';
|
|
break;
|
|
case self::REMOTE_ENV == 'local':
|
|
return self::LOCAL_URLS[$service] . $url;
|
|
break;
|
|
default:
|
|
return self::PROD_URL . $service . '/' . $url;
|
|
break;
|
|
}
|
|
// if(self::REMOTE_ENV == 'local') {
|
|
// return self::LOCAL_URLS[$service] . $url;
|
|
// } else {
|
|
// return self::PROD_URL . $service . '/' . $url;
|
|
// }
|
|
}
|
|
|
|
public static function postrequest($service, $url, $params, $token = '') {
|
|
$params['application'] = 'rapport';
|
|
$fullurl = self::genurl($service, $url);
|
|
if($token == '') {
|
|
$response = Http::post($fullurl, $params);
|
|
} else {
|
|
$response = Http::withHeaders(['Authorization' => $token])->post($fullurl, $params);
|
|
}
|
|
$response = json_decode($response->getBody()->getContents());
|
|
return $response;
|
|
}
|
|
|
|
public static function getrequest($service, $url, $params, $token = '') {
|
|
$params['application'] = 'rapport';
|
|
$fullurl = self::genurl($service, $url);
|
|
if($token == '') {
|
|
$response = Http::get($fullurl, $params);
|
|
} else {
|
|
$response = Http::withHeaders(['Authorization' => $token])->get($fullurl, $params);
|
|
}
|
|
//$response = Http::get($fullurl, $params);
|
|
$response = json_decode($response->getBody()->getContents());
|
|
return $response;
|
|
}
|
|
|
|
public static function signedrequest($type, $service, $url, $data = [], $timeout = 30) {
|
|
$params['application'] = 'rapport';
|
|
$fullurl = self::genurl($service, $url);
|
|
// if($service == 'metric' && $url == 'metric_report/list') {
|
|
// $fullurl = 'https://osp5d7z3zwhuskxmd2gld46ba40rumsf.lambda-url.ap-south-1.on.aws/';
|
|
// $timeout = 600;
|
|
// }
|
|
// if($service == 'metric' && $url == 'metric_report/view') {
|
|
// $fullurl = 'https://zbmttswaqimy3nmo5wactmja3i0uosyv.lambda-url.ap-south-1.on.aws/';
|
|
// $timeout = 600;
|
|
// }
|
|
// if(self::REMOTE_ENV != 'local' && $service == 'form' && $url == 'survey/getformhistory') {
|
|
// $fullurl = 'https://tvp2drn5c2jpf7dpxdwwykdez40ikfbz.lambda-url.ap-south-1.on.aws/';
|
|
// $timeout = 600;
|
|
// }
|
|
// if(self::REMOTE_ENV != 'local' && $service == 'form' && $url == 'formentity/getformhistory') {
|
|
// $fullurl = 'https://sgrmuxa46z7xfouezyvg3tnhnq0yptjn.lambda-url.ap-south-1.on.aws/';
|
|
// $timeout = 600;
|
|
// }
|
|
|
|
if($type == 'post') {
|
|
$response = Http::timeout($timeout)->withHeaders(['Authorization' => Auth::user()->access_token])->post($fullurl, $data);
|
|
} else {
|
|
$response = Http::timeout($timeout)->withHeaders(['Authorization' => Auth::user()->access_token])->get($fullurl, $data);
|
|
}
|
|
$response = json_decode($response->getBody()->getContents());
|
|
return $response;
|
|
}
|
|
}
|