Files
karudhaas/app/Services/FeshunService.php
2021-01-04 14:48:36 +05:00

43 lines
1.4 KiB
PHP

<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Carbon;
class FeshunService extends Client
{
/**
* Scrap all the rss articles from Thiladhun
*
* @return array
*/
public function scrape(): array
{
$articles = Http::get("https://feshun.mv/wp-json/wp/v2/posts")->json();
$articlesitems = [];
foreach ($articles as $article) {
$articlesitems[] = [
'source' => 'Feshun',
'title' => $article["title"]["rendered"],
'og_title' => $article["title"]["rendered"],
'image' => Http::get("https://feshun.mv/wp-json/wp/v2/media?include=".$article["featured_media"])->json()[0]["guid"]["rendered"],
'content' => explode("<p>",$article["content"]["rendered"]),
'date' => Carbon::parse($article["date"])->format("Y-m-d H:i:s"),
'url' => $article["link"],
'author' => Http::get("https://feshun.mv/wp-json/wp/v2/users?include=".$article["author"])->json()[0]["name"],
'guid' => basename($article["link"]),
'topics' => [
[
"name" => "ވަކި މަޢުލޫއެއް ނޭންގެ",
"slug" => "no-specific-topic"
]
]
];
}
return $articlesitems;
}
}