oc-adrema-plugin/support/Proxy.php

34 lines
718 B
PHP
Raw Normal View History

2024-02-03 22:36:56 +01:00
<?php
namespace Silva\Adrema\Support;
use Silva\Adrema\Models\Settings;
use Http;
2024-02-08 02:23:11 +01:00
use Illuminate\Http\JsonResponse;
2024-02-03 22:36:56 +01:00
class Proxy
{
public function run(string $url): ?array
{
2024-02-08 02:23:11 +01:00
$response = Http::acceptJson()->get($this->url($url));
2024-02-03 22:36:56 +01:00
if (!$response->ok()) {
return null;
}
return $response->json();
}
2024-02-08 02:23:11 +01:00
public function submit(string $url): JsonResponse
{
$response = Http::acceptJson()->post($this->url($url), request()->input());
return response()->json($response->json(), $response->status());
}
private function url(string $internal): string
{
return Settings::get('base_url') . str($internal)->start('/');
}
2024-02-03 22:36:56 +01:00
}