Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
RhysLees committed Jan 31, 2025
1 parent 365440f commit b59f28d
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions src/Requests/GetInstagramBusinessDiscoveryMedia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

declare(strict_types=1);

namespace CodebarAg\LaravelInstagram\Requests;

use CodebarAg\LaravelInstagram\Actions\InstagramHandler;
use CodebarAg\LaravelInstagram\Responses\CreateMediaCollectionFromResponse;
use Illuminate\Support\Collection;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\Traits\Plugins\AcceptsJson;

class GetInstagramBusinessDiscoveryMedia extends Request
{
use AcceptsJson;

protected Method $method = Method::GET;

public function __construct(
protected string $username,
protected bool $withChildren = true,
protected mixed $user_id = null,
) {}

/**
* @throws \Exception
*/
public function resolveEndpoint(): string
{
$user_id = $this->user_id;

if (empty($user_id)) {
$user_id = InstagramHandler::user()->user_id;
}

return $user_id;
}

public function defaultQuery(): array
{
$fields = collect([
'followers_count',
'media_count',
]);

$mediaFields = collect([
'id',
'caption',
'media_type',
'media_url',
'permalink',
'thumbnail_url',
'timestamp',
'username',
]);

$childFields = collect([
'id',
'media_type',
'media_url',
'permalink',
'timestamp',
'username',
]);

if ($this->withChildren) {
$mediaFields->add('children{'.$childFields->join(',').'}');
}

$fields->add('media{'.$mediaFields->join(',').'}');

return [
'fields' => sprintf(
'business_discovery.username(%s){%s}',
$this->username,
$fields->join(',')
),
];
}

public function createDtoFromResponse(Response $response): mixed
{
return $response->json();
// return CreateMediaCollectionFromResponse::fromResponse($response);
}
}

0 comments on commit b59f28d

Please sign in to comment.