Rss client
This commit is contained in:
25
app/Services/Client.php
Normal file
25
app/Services/Client.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class Client
|
||||
{
|
||||
/**
|
||||
* Get the Rss Feed given a url.
|
||||
*
|
||||
* @param mixed $url
|
||||
* @return array
|
||||
*/
|
||||
public function get($url) : array
|
||||
{
|
||||
$response = Http::get($url);
|
||||
|
||||
if(!$response->ok())
|
||||
{
|
||||
throw new \Exception("Error getting the rss feed");
|
||||
}
|
||||
|
||||
return json_decode(json_encode(simplexml_load_string($response->body())), true);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user