Skip to content

Commit 7367589

Browse files
committed
🦾 Max Results, Meta Details & BaseModel Refactor
1 parent dd65337 commit 7367589

19 files changed

+161
-98
lines changed

‎src/Clients/ListClient.php‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,64 +25,78 @@ public function getList(string $id): TwitterList
2525
return new TwitterList($response->getData());
2626
}
2727

28-
public function getUserOwnedLists(string $id): TwitterLists
28+
public function getUserOwnedLists(string $id, ?int $maxResults = 100, ?string $paginationToken = null): TwitterLists
2929
{
3030
$response = $this->get('users/' . $id . '/owned_lists', [
3131
'list.fields' => $this->listFields,
32+
'max_results' => $maxResults,
33+
'pagination_token' => $paginationToken,
3234
]);
3335

3436
return new TwitterLists($response->getData());
3537
}
3638

37-
public function getListTweets(string $id): Tweets
39+
public function getListTweets(string $id, ?int $maxResults = 100, ?string $paginationToken = null): Tweets
3840
{
3941
$response = $this->get('lists/' . $id . '/tweets', [
4042
'tweet.fields' => $this->tweetFields,
43+
'max_results' => $maxResults,
44+
'pagination_token' => $paginationToken,
4145
]);
4246

4347
return new Tweets($response->getData());
4448
}
4549

46-
public function getListMembers(string $id): Users
50+
public function getListMembers(string $id, ?int $maxResults = 100, ?string $paginationToken = null): Users
4751
{
4852
$response = $this->get('lists/' . $id . '/members', [
4953
'user.fields' => $this->userFields,
54+
'max_results' => $maxResults,
55+
'pagination_token' => $paginationToken,
5056
]);
5157

5258
return new Users($response->getData());
5359
}
5460

55-
public function getUserMemberships(string $id): TwitterLists
61+
public function getUserMemberships(string $id, ?int $maxResults = 100, ?string $paginationToken = null): TwitterLists
5662
{
5763
$response = $this->get('users/' . $id . '/list_memberships', [
5864
'list.fields' => $this->listFields,
65+
'max_results' => $maxResults,
66+
'pagination_token' => $paginationToken,
5967
]);
6068

6169
return new TwitterLists($response->getData());
6270
}
6371

64-
public function getListFollowers(string $id): Users
72+
public function getListFollowers(string $id, ?int $maxResults = 100, ?string $paginationToken = null): Users
6573
{
6674
$response = $this->get('lists/' . $id . '/followers', [
6775
'user.fields' => $this->userFields,
76+
'max_results' => $maxResults,
77+
'pagination_token' => $paginationToken,
6878
]);
6979

7080
return new Users($response->getData());
7181
}
7282

73-
public function getUserFollowedLists(string $id): TwitterLists
83+
public function getUserFollowedLists(string $id, ?int $maxResults = 100, ?string $paginationToken = null): TwitterLists
7484
{
7585
$response = $this->get('users/' . $id . '/followed_lists', [
7686
'list.fields' => $this->listFields,
87+
'max_results' => $maxResults,
88+
'pagination_token' => $paginationToken,
7789
]);
7890

7991
return new TwitterLists($response->getData());
8092
}
8193

82-
public function getUserPinnedLists(string $id): TwitterLists
94+
public function getUserPinnedLists(string $id, ?int $maxResults = 100, ?string $paginationToken = null): TwitterLists
8395
{
8496
$response = $this->get('users/' . $id . '/pinned_lists', [
8597
'list.fields' => $this->listFields,
98+
'max_results' => $maxResults,
99+
'pagination_token' => $paginationToken,
86100
]);
87101

88102
return new TwitterLists($response->getData());

‎src/Clients/MuteClient.php‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎src/Clients/SpaceClient.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ public function getSpace(string $id): Space
1616
return new Space($response->getData());
1717
}
1818

19-
public function getSpaces(array $ids): Spaces
19+
public function getSpaces(array $ids, ?int $maxResults = 100, ?string $paginationToken = null): Spaces
2020
{
2121
$response = $this->get('spaces', [
2222
'space.fields' => $this->spaceFields,
23+
'max_results' => $maxResults,
24+
'pagination_token' => $paginationToken,
2325
'ids' => implode(',', $ids),
2426
]);
2527

‎src/Clients/TweetClient.php‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,45 @@ public function getTweet(string $id): Tweet
1717
return new Tweet($response->getData());
1818
}
1919

20-
public function getTweets(array $tweetIds): Tweets
20+
public function getTweets(array $tweetIds, ?int $maxResults = 100, ?string $paginationToken = null): Tweets
2121
{
2222
$response = $this->get('tweets', [
2323
'tweet.fields' => $this->tweetFields,
24+
'pagination_token' => $paginationToken,
2425
'ids' => implode(',', $tweetIds),
2526
]);
2627

2728
return new Tweets($response->getData());
2829
}
2930

30-
public function getQuoteTweets(string $id): Tweets
31+
public function getQuoteTweets(string $id, ?int $maxResults = 100, ?string $paginationToken = null): Tweets
3132
{
3233
$response = $this->get('tweets/' . $id . '/quote_tweets', [
3334
'tweet.fields' => $this->tweetFields,
35+
'max_results' => $maxResults,
36+
'pagination_token' => $paginationToken,
3437
]);
3538

3639
return new Tweets($response->getData());
3740
}
3841

39-
public function getLikingUsers(string $id): Users
42+
public function getLikingUsers(string $id, ?int $maxResults = 100, ?string $paginationToken = null): Users
4043
{
4144
$response = $this->get('tweets/' . $id . '/liking_users', [
4245
'user.fields' => $this->userFields,
46+
'max_results' => $maxResults,
47+
'pagination_token' => $paginationToken,
4348
]);
4449

4550
return new Users($response->getData());
4651
}
4752

48-
public function getRetweetedByUsers(string $id): Users
53+
public function getRetweetedByUsers(string $id, ?int $maxResults = 100, ?string $paginationToken = null): Users
4954
{
5055
$response = $this->get('tweets/' . $id . '/retweeted_by', [
5156
'user.fields' => $this->userFields,
57+
'max_results' => $maxResults,
58+
'pagination_token' => $paginationToken,
5259
]);
5360

5461
return new Users($response->getData());

‎src/Clients/UserClient.php‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,34 @@ public function getUserById(string $id): User
2626
return new User($response->getData());
2727
}
2828

29-
public function getLikedTweets(string $id): Tweets
29+
public function getLikedTweets(string $id, ?int $maxResults = 100, ?string $paginationToken = null): Tweets
3030
{
3131
$response = $this->get('users/' . $id . '/liked_tweets', [
3232
'tweet.fields' => $this->tweetFields,
33+
'max_results' => $maxResults,
34+
'pagination_token' => $paginationToken,
3335
]);
3436

3537
return new Tweets($response->getData());
3638
}
3739

38-
public function getFollowers(string $id): Users
40+
public function getFollowers(string $id, ?int $maxResults = 100, ?string $paginationToken = null): Users
3941
{
4042
$response = $this->get('users/' . $id . '/followers', [
4143
'user.fields' => $this->userFields,
44+
'max_results' => $maxResults,
45+
'pagination_token' => $paginationToken,
4246
]);
4347

4448
return new Users($response->getData());
4549
}
4650

47-
public function getFollowing(string $id): Users
51+
public function getFollowing(string $id, ?int $maxResults = 100, ?string $paginationToken = null): Users
4852
{
4953
$response = $this->get('users/' . $id . '/following', [
5054
'user.fields' => $this->userFields,
55+
'max_results' => $maxResults,
56+
'pagination_token' => $paginationToken,
5157
]);
5258

5359
return new Users($response->getData());
@@ -65,14 +71,16 @@ public function follow(string $authUserId, string $userId)
6571
public function unfollow(string $authUserId, string $userId)
6672
{
6773
$response = $this->delete('users/' . $authUserId . '/following/' . $userId, []);
68-
74+
6975
return $response;
7076
}
7177

72-
public function getBlocks(string $id): Users
78+
public function getBlocks(string $id, ?int $maxResults = 100, ?string $paginationToken = null): Users
7379
{
7480
$response = $this->get('users/' . $id . '/blocking', [
7581
'user.fields' => $this->userFields,
82+
'max_results' => $maxResults,
83+
'pagination_token' => $paginationToken,
7684
]);
7785

7886
return new Users($response->getData());
@@ -90,7 +98,7 @@ public function block(string $authUserId, string $userId)
9098
public function unblock(string $authUserId, string $userId)
9199
{
92100
$response = $this->delete('users/' . $authUserId . '/blocking/' . $userId, []);
93-
101+
94102
return $response;
95103
}
96104

@@ -106,7 +114,7 @@ public function mute(string $authUserId, string $userId)
106114
public function unmute(string $authUserId, string $userId)
107115
{
108116
$response = $this->delete('users/' . $authUserId . '/muting/' . $userId, []);
109-
117+
110118
return $response;
111119
}
112120
}

‎src/Models/BaseModel.php‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace UtxoOne\TwitterUltimatePhp\Models;
4+
5+
class BaseModel
6+
{
7+
public array $data;
8+
public array $meta;
9+
10+
public function __construct(public array $response)
11+
{
12+
$this->data = (!isset($response['data'])) ? $this->data = $response : $this->data = $response['data'];
13+
$this->meta = ($response['meta'] ?? []);
14+
}
15+
}

‎src/Models/Space.php‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
namespace UtxoOne\TwitterUltimatePhp\Models;
44

5-
class Space
5+
class Space extends BaseModel
66
{
7-
public function __construct(private array $data)
8-
{
9-
}
10-
117
public function getId(): string
128
{
139
return $this->data['id'];

‎src/Models/Spaces.php‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
namespace UtxoOne\TwitterUltimatePhp\Models;
44

5-
class Spaces
5+
class Spaces extends BaseModel
66
{
7-
public function __construct(private array $data)
8-
{
9-
}
10-
117
public function all(): array
128
{
139
$spaces = [];
@@ -18,4 +14,14 @@ public function all(): array
1814

1915
return $spaces;
2016
}
17+
18+
public function getPaginationToken(): ?string
19+
{
20+
return $this->meta['next_token'];
21+
}
22+
23+
public function getResultCount(): int
24+
{
25+
return $this->meta['result_count'];
26+
}
2127
}

‎src/Models/Tweet.php‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
namespace UtxoOne\TwitterUltimatePhp\Models;
44

5-
class Tweet
5+
class Tweet extends BaseModel
66
{
7-
public function __construct(private array $data)
8-
{
9-
}
10-
117
public function getId(): string
128
{
139
return $this->data['id'];

‎src/Models/Tweets.php‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44

55
class Tweets
66
{
7-
public function __construct(private array $data)
7+
public array $data;
8+
public array $meta;
9+
10+
public function __construct(public array $response)
811
{
12+
$this->data = $response['data'];
13+
$this->meta = ($response['meta'] ?? []);
914
}
1015

1116
public function all(): array
@@ -18,4 +23,14 @@ public function all(): array
1823

1924
return $tweets;
2025
}
26+
27+
public function getPaginationToken(): ?string
28+
{
29+
return $this->meta['next_token'];
30+
}
31+
32+
public function getResultCount(): int
33+
{
34+
return $this->meta['result_count'];
35+
}
2136
}

0 commit comments

Comments
 (0)