Rapport-Laravel/app/Http/Requests/LambdaRequest.php

135 lines
5.7 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/',
'rcpa' => 'http://localhost:3022/dev/',
'contact' => 'http://localhost:3024/dev/',
'events' => 'http://localhost:3023/dev/',
'vgreet' => 'http://localhost:4003/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' && $service == 'form' && $url == 'quiz/getformhistory':
// return 'https://pc4gexzhd43hwms34p7vldwksm0zoehu.lambda-url.ap-south-1.on.aws/';
// break;
case self::REMOTE_ENV != 'local' && $service == 'magazine' && $url == 'magazine/magazine_export':
return 'https://bmilwmrobqef6z6pxmb7aa2tui0pcrca.lambda-url.ap-south-1.on.aws/';
break;
case self::REMOTE_ENV != 'local' && $service == 'magazine' && $url == 'mag_media/magazine_media_export':
return 'https://cxy7ji5de22bwmqypl67ftjczq0wfbig.lambda-url.ap-south-1.on.aws/';
break;
case self::REMOTE_ENV != 'local' && $service == 'form' && $url == 'formentity/submitmultipleform':
return 'https://rg33lkjoxoakmrkfpa46wermey0dksct.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 = '', $timeout = null) {
$params['application'] = 'rapport';
$fullurl = self::genurl($service, $url);
$useTimeout = $timeout !== null && (int) $timeout > 0;
if($token == '') {
$response = $useTimeout
? Http::timeout((int) $timeout)->get($fullurl, $params)
: Http::get($fullurl, $params);
} else {
$response = $useTimeout
? Http::timeout((int) $timeout)->withHeaders(['Authorization' => $token])->get($fullurl, $params)
: 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;
// }
//echo $fullurl; exit;
if($type == 'post') {
$response = Http::timeout($timeout)->withHeaders(['Authorization' => Auth::user()->access_token])->post($fullurl, $data);
} else {
//Log::debug(print_r([$fullurl, $data], true));
$response = Http::timeout($timeout)->withHeaders(['Authorization' => Auth::user()->access_token])->get($fullurl, $data);
}
$response = json_decode($response->getBody()->getContents());
return $response;
}
}