File tree Expand file tree Collapse file tree 5 files changed +50
-0
lines changed
Expand file tree Collapse file tree 5 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -67,4 +67,9 @@ public function getEntities(): ?array
6767 {
6868 return (isset ($ this ->data ['entities ' ]) ? $ this ->data ['entities ' ] : null );
6969 }
70+
71+ public function getPublicMetrics (): ?UserPublicMetrics
72+ {
73+ return (isset ($ this ->data ['public_metrics ' ]) ? new UserPublicMetrics ($ this ->data ['public_metrics ' ]) : null );
74+ }
7075}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace UtxoOne \TwitterUltimatePhp \Models ;
4+
5+ class UserPublicMetrics
6+ {
7+ public function __construct (private array $ data )
8+ {
9+ }
10+
11+ public function getFollowersCount (): int
12+ {
13+ return $ this ->data ['followers_count ' ];
14+ }
15+
16+ public function getFollowingCount (): int
17+ {
18+ return $ this ->data ['following_count ' ];
19+ }
20+
21+ public function getTweetCount (): int
22+ {
23+ return $ this ->data ['tweet_count ' ];
24+ }
25+
26+ public function getListedCount (): int
27+ {
28+ return $ this ->data ['listed_count ' ];
29+ }
30+ }
Original file line number Diff line number Diff line change 33use UtxoOne \TwitterUltimatePhp \Clients \UserClient ;
44use UtxoOne \TwitterUltimatePhp \Models \Tweets ;
55use UtxoOne \TwitterUltimatePhp \Models \User ;
6+ use UtxoOne \TwitterUltimatePhp \Models \UserPublicMetrics ;
67use UtxoOne \TwitterUltimatePhp \Models \Users ;
78
89class UserClientTest extends BaseClientTest
@@ -172,4 +173,18 @@ public function testUnmute(): void
172173
173174 $ this ->assertArrayHasKey ('muting ' , $ response ->getData ());
174175 }
176+
177+ /** @group getPublicMetrics */
178+ public function testGetPublicMetrics (): void
179+ {
180+ $ client = new UserClient (bearerToken: $ _ENV ['TWITTER_BEARER_TOKEN ' ]);
181+
182+ $ publicMetrics = $ client ->getUserById ($ _ENV ['TWITTER_ADMIN_USER_ID ' ])->getPublicMetrics ();
183+
184+ $ this ->assertInstanceOf (UserPublicMetrics::class, $ publicMetrics );
185+ $ this ->assertIsInt ($ publicMetrics ->getFollowersCount ());
186+ $ this ->assertIsInt ($ publicMetrics ->getFollowingCount ());
187+ $ this ->assertIsInt ($ publicMetrics ->getTweetCount ());
188+ $ this ->assertIsInt ($ publicMetrics ->getListedCount ());
189+ }
175190}
You can’t perform that action at this time.
0 commit comments