su-secret-santa/app/Services/PostService.php

27 lines
618 B
PHP
Executable File

<?php
namespace App\Services;
class PostService
{
public static function getPostData(string $url): mixed
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Accept: application/json'
]);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($response !== false && $httpCode === 200) {
return json_decode($response, true);
}
return false;
}
}