-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |