Skip to content

Commit b59f28d

Browse files
committed
WIP
1 parent 365440f commit b59f28d

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CodebarAg\LaravelInstagram\Requests;
6+
7+
use CodebarAg\LaravelInstagram\Actions\InstagramHandler;
8+
use CodebarAg\LaravelInstagram\Responses\CreateMediaCollectionFromResponse;
9+
use Illuminate\Support\Collection;
10+
use Saloon\Enums\Method;
11+
use Saloon\Http\Request;
12+
use Saloon\Http\Response;
13+
use Saloon\Traits\Plugins\AcceptsJson;
14+
15+
class GetInstagramBusinessDiscoveryMedia extends Request
16+
{
17+
use AcceptsJson;
18+
19+
protected Method $method = Method::GET;
20+
21+
public function __construct(
22+
protected string $username,
23+
protected bool $withChildren = true,
24+
protected mixed $user_id = null,
25+
) {}
26+
27+
/**
28+
* @throws \Exception
29+
*/
30+
public function resolveEndpoint(): string
31+
{
32+
$user_id = $this->user_id;
33+
34+
if (empty($user_id)) {
35+
$user_id = InstagramHandler::user()->user_id;
36+
}
37+
38+
return $user_id;
39+
}
40+
41+
public function defaultQuery(): array
42+
{
43+
$fields = collect([
44+
'followers_count',
45+
'media_count',
46+
]);
47+
48+
$mediaFields = collect([
49+
'id',
50+
'caption',
51+
'media_type',
52+
'media_url',
53+
'permalink',
54+
'thumbnail_url',
55+
'timestamp',
56+
'username',
57+
]);
58+
59+
$childFields = collect([
60+
'id',
61+
'media_type',
62+
'media_url',
63+
'permalink',
64+
'timestamp',
65+
'username',
66+
]);
67+
68+
if ($this->withChildren) {
69+
$mediaFields->add('children{'.$childFields->join(',').'}');
70+
}
71+
72+
$fields->add('media{'.$mediaFields->join(',').'}');
73+
74+
return [
75+
'fields' => sprintf(
76+
'business_discovery.username(%s){%s}',
77+
$this->username,
78+
$fields->join(',')
79+
),
80+
];
81+
}
82+
83+
public function createDtoFromResponse(Response $response): mixed
84+
{
85+
return $response->json();
86+
// return CreateMediaCollectionFromResponse::fromResponse($response);
87+
}
88+
}

0 commit comments

Comments
 (0)