Skip to content

Commit 2cc3392

Browse files
committed
🐦 Twitter Timeline Methods and Tests
1 parent 7367589 commit 2cc3392

File tree

4 files changed

+100
-22
lines changed

4 files changed

+100
-22
lines changed

composer.lock

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Clients/TweetClient.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,40 @@ public function getRetweetedByUsers(string $id, ?int $maxResults = 100, ?string
6161
return new Users($response->getData());
6262
}
6363

64+
public function getTimeline(string $userId, ?int $maxResults = 100, ?string $paginationToken = null): Tweets
65+
{
66+
$response = $this->get('users/' . $userId . '/tweets', [
67+
'tweet.fields' => $this->tweetFields,
68+
'max_results' => $maxResults,
69+
'pagination_token' => $paginationToken,
70+
]);
71+
72+
return new Tweets($response->getData());
73+
}
74+
75+
public function getReverseTimeline(string $userId, ?int $maxResults = 100, ?string $paginationToken = null): Tweets
76+
{
77+
$response = $this->get('users/' . $userId . '/timelines/reverse_chronological', [
78+
'tweet.fields' => $this->tweetFields,
79+
'max_results' => $maxResults,
80+
'pagination_token' => $paginationToken,
81+
'tweet_mode' => 'extended',
82+
]);
83+
84+
return new Tweets($response->getData());
85+
}
86+
87+
public function getMentionTimeline(string $userId, ?int $maxResults = 100, ?string $paginationToken = null): Tweets
88+
{
89+
$response = $this->get('users/' . $userId . '/mentions', [
90+
'tweet.fields' => $this->tweetFields,
91+
'max_results' => $maxResults,
92+
'pagination_token' => $paginationToken,
93+
]);
94+
95+
return new Tweets($response->getData());
96+
}
97+
6498
public function tweet(string $text): Tweet
6599
{
66100
$response = $this->post('tweets', [

tests/Clients/TweetClientTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,50 @@ public function testGetTweets(): void
3333
$this->assertTweetFieldsAreSet($response->all()[1]);
3434
}
3535

36+
/** @group getTimeline */
37+
public function testGetTimeline(): void
38+
{
39+
$client = new TweetClient(bearerToken: $_ENV['TWITTER_BEARER_TOKEN']);
40+
41+
$response = $client->getTimeline('12', 10);
42+
43+
$this->assertInstanceOf(Tweets::class, $response);
44+
$this->assertCount(10, $response->all());
45+
$this->assertTweetFieldsAreSet($response->all()[0]);
46+
}
47+
48+
/** @group getReverseTimeline */
49+
public function testGetReverseTimeline(): void
50+
{
51+
$this->markTestIncomplete('Unsupported Authentication Type');
52+
53+
$client = new TweetClient(
54+
apiKey: $_ENV['TWITTER_API_KEY'],
55+
apiSecret: $_ENV['TWITTER_API_SECRET'],
56+
accessToken: $_ENV['TWITTER_ACCESS_TOKEN'],
57+
accessSecret: $_ENV['TWITTER_ACCESS_SECRET'],
58+
bearerToken: $_ENV['TWITTER_BEARER_TOKEN'],
59+
);
60+
61+
$response = $client->getReverseTimeline($_ENV['TWITTER_ADMIN_USER_ID'], 10);
62+
63+
$this->assertInstanceOf(Tweets::class, $response);
64+
$this->assertCount(10, $response->all());
65+
$this->assertTweetFieldsAreSet($response->all()[0]);
66+
}
67+
68+
/** @group getMentionTimeline */
69+
public function testGetMentionTimeline(): void
70+
{
71+
$client = new TweetClient(bearerToken: $_ENV['TWITTER_BEARER_TOKEN']);
72+
73+
$response = $client->getMentionTimeline('12', 10);
74+
75+
$this->assertInstanceOf(Tweets::class, $response);
76+
$this->assertCount(10, $response->all());
77+
$this->assertTweetFieldsAreSet($response->all()[0]);
78+
}
79+
3680
/** @group getQuoteTweets */
3781
public function testGetQuoteTweets(): void
3882
{

tests/Clients/UserClientTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ public function testGetUserByUsername(): void
1313
{
1414
$client = new UserClient(bearerToken: $_ENV['TWITTER_BEARER_TOKEN']);
1515

16-
$response = $client->getUserByUsername('utxoone');
16+
$response = $client->getUserByUsername('utxo_one');
1717

1818
$this->assertInstanceOf(User::class, $response);
19-
$this->assertSame('utxoONE', $response->getUsername());
19+
$this->assertSame('utxo_one', $response->getUsername());
2020
}
2121

2222
/** @group getUserById */
@@ -27,7 +27,7 @@ public function testGetUserById(): void
2727
$response = $client->getUserById($_ENV['TWITTER_ADMIN_USER_ID']);
2828

2929
$this->assertInstanceOf(User::class, $response);
30-
$this->assertSame('utxoONE', $response->getUsername());
30+
$this->assertSame('utxo_one', $response->getUsername());
3131
$this->assertFalse($response->isProtected());
3232
$this->assertFalse($response->isVerified());
3333
$this->assertSame('2022-08-14T21:32:08.000Z', $response->getCreatedAt());

0 commit comments

Comments
 (0)