Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
<?php
declare(strict_types=1);
namespace App\Services\Analytics\Collectors\Followers;
use App\Dto\Analytics\AccountDailyObservation;
use App\Enums\Analytics\MetricPrecision;
use App\Enums\Analytics\ObservationProvenance;
use App\Exceptions\Analytics\AnalyticsCollectionException;
use App\Models\SocialAccount;
use App\Support\Analytics\AnalyticsAccessToken;
use App\Support\Analytics\MetaAnalyticsResponse;
use Carbon\CarbonImmutable;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
abstract class AbstractFollowerCollector
{
abstract public function collect(SocialAccount $account, CarbonImmutable $date): AccountDailyObservation;
protected function get(
SocialAccount $account,
string $url,
array $query = [],
bool $meta = false,
): Response {
$response = Http::acceptJson()
->withToken(AnalyticsAccessToken::for($account))
->timeout(120)
->get($url, $query);
if ($response->successful()) {
return $response;
}
if ($meta) {
return MetaAnalyticsResponse::successful($response, 'follower collection');
}
throw AnalyticsCollectionException::fromResponse($response, 'follower collection');
}
protected function observation(
CarbonImmutable $date,
mixed $value,
MetricPrecision $precision = MetricPrecision::Exact,
): AccountDailyObservation {
if (! is_numeric($value)) {
throw AnalyticsCollectionException::malformed('missing follower metric');
}
return new AccountDailyObservation(
date: $date,
followers: (int) $value,
provenance: ObservationProvenance::Actual,
precision: $precision,
providerObservedAt: CarbonImmutable::now('UTC'),
collectedAt: CarbonImmutable::now('UTC'),
);
}
}