Skip to content

Commit d9dd9d4

Browse files
authored
Merge pull request #18 from utxo-one/dev-Media
Add includes to getters
2 parents 717d44e + 948f755 commit d9dd9d4

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

src/Clients/TweetClient.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public function getTweet(string $id): Tweet
1212
{
1313
$response = $this->get('tweets/' . $id, [
1414
'tweet.fields' => $this->tweetFields,
15+
'expansions' => $this->expansions,
16+
'media.fields' => $this->mediaFields,
1517
]);
1618

1719
return new Tweet($response->getData());

src/Models/BaseModel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ class BaseModel
66
{
77
public array $data;
88
public array $meta;
9+
public array $includes;
910

1011
public function __construct(public array $response)
1112
{
1213
$this->data = (!isset($response['data'])) ? $this->data = $response : $this->data = $response['data'];
1314
$this->meta = ($response['meta'] ?? []);
15+
$this->includes = ($response['includes'] ?? []);
1416
}
1517
}

src/Models/Tweet.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,15 @@ public function getAttachments(): ?array
8888
{
8989
return (isset($this->data['attachments']) ? $this->data['attachments'] : null);
9090
}
91+
92+
public function getMedia(): ?array
93+
{
94+
return (isset($this->includes['media']) ? $this->includes['media'] : null);
95+
}
96+
97+
public function getIncludes(): ?array
98+
{
99+
return (isset($this->includes) && !empty($this->includes) ? $this->includes : null);
100+
}
101+
91102
}

tests/Clients/BaseClientTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22

33
use PHPUnit\Framework\TestCase;
4-
use UtxoOne\TwitterUltimatePhp\Client\Client;
54
use UtxoOne\TwitterUltimatePhp\Models\Tweet;
65
use UtxoOne\TwitterUltimatePhp\Models\Tweets;
76

tests/Clients/TweetClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function testGetTweet(): void
1212
{
1313
$client = new TweetClient(bearerToken: $_ENV['TWITTER_BEARER_TOKEN']);
1414

15-
$response = $client->getTweet('1564986319981498368');
15+
$response = $client->getTweet('1589452392348930048');
1616

1717
$this->assertInstanceOf(Tweet::class, $response);
1818
$this->assertSame('1564986319981498368', $response->getId());

0 commit comments

Comments
 (0)