diff --git a/readme.md b/readme.md
index 025d2cd..0e0413a 100644
--- a/readme.md
+++ b/readme.md
@@ -1,12 +1,65 @@
# Twitter API V2 for PHP
-![php](https://img.shields.io/badge/PHP-v7.4-828cb7.svg?style=flat-square)
-[![Badge Twitter](https://img.shields.io/endpoint?url=https%3A%2F%2Ftwbadges.glitch.me%2Fbadges%2Fv2)](https://developer.twitter.com/en/docs/twitter-api)
+![PHP](https://img.shields.io/badge/PHP-v7.4+-828cb7.svg?style=flat-square&logo=php)
+[![Badge Twitter](https://img.shields.io/badge/Twitter%20API-v2-828cb7.svg?style=flat-square&logo=twitter&color=1DA1F2)](https://developer.twitter.com/en/docs/twitter-api)
[![Run Tests](https://github.com/noweh/twitter-api-v2-php/actions/workflows/run-tests.yml/badge.svg)](https://github.com/noweh/twitter-api-v2-php/actions/workflows/run-tests.yml)
-[![MIT Licensed](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](licence.md)
+[![MIT Licensed](https://img.shields.io/github/license/noweh/twitter-api-v2-php)](licence.md)
+[![last version](https://img.shields.io/packagist/v/noweh/twitter-api-v2-php)](https://packagist.org/packages/noweh/twitter-api-v2-php)
+[![Downloads](https://img.shields.io/packagist/dt/noweh/twitter-api-v2-php)](https://packagist.org/packages/noweh/twitter-api-v2-php)
+[![twitter](https://img.shields.io/twitter/follow/Noweh95?style=social)](https://twitter.com/Noweh95)
Twitter API V2 is a PHP package which provides an easy and fast access to Twitter REST API for Version 2 endpoints.
+## Documentation
+
+* [Installation](#installation)
+* [Github Actions](#github-actions)
+* [How to use](#how-to-use)
+ - [Active your developer account](#active-your-developer-account)
+ - [Prepare settings](#prepare-settings)
+* [Tweets endpoints](#tweet-endpoints)
+ - [Timeline endpoints](#timeline-endpoints)
+ - [Retrieve the users which you've blocked](#retrieve-the-users-which-youve-blocked)
+ - [User/Follows endpoints](#userfollows-endpoints)
+ - [Find Recent Mentioning for a User](#find-recent-mentioning-for-a-user)
+ - [Find Recent Tweets for a User](#find-recent-tweets-for-a-user)
+ - [Reverse Chronological Timeline by user ID](#reverse-chronological-timeline-by-user-id)
+ - [Tweet/Likes endpoints](#tweetlikes-endpoints)
+ - [Tweets liked by a user](#tweets-liked-by-a-user)
+ - [Users who liked a tweet](#users-who-liked-a-tweet)
+ - [Tweet/Lookup endpoints](#tweetlikes-endpoints)
+ - [Search specific tweets](#search-specific-tweets)
+ - [Find all replies from a Tweet](#find-all-replies-from-a-tweet)
+ - [Tweet endpoints](#tweetlikes-endpoints)
+ - [Fetch a tweet by Id](#fetch-a-tweet-by-id)
+ - [Create a new Tweet](#create-a-new-tweet)
+ - [Tweet/Quotes endpoints](#tweetquotes-endpoints)
+ - [Returns Quote Tweets for a Tweet specified by the requested Tweet ID](#returns-quote-tweets-for-a-tweet-specified-by-the-requested-tweet-id)
+ - [Retweet endpoints](#retweet-endpoints)
+ - [Retweet a Tweet](#retweet-a-tweet)
+ - [Tweet/Replies endpoints](#tweetreplies-endpoints)
+ - [Hide a reply to a Tweet](#hide-a-reply-to-a-tweet)
+ - [Unhide a reply to a Tweet](#unhide-a-reply-to-a-tweet)
+ - [Tweet/Bookmarks endpoints](#tweetbookmarks-endpoints)
+ - [Lookup a user's Bookmarks](#lookup-a-users-bookmarks)
+* [Users endpoints](#users-endpoints)
+ - [User/Blocks endpoints](#userblocks-endpoints)
+ - [Retrieve the users which you've blocked](#retrieve-the-users-which-youve-blocked)
+ - [User/Follows endpoints](#userfollows-endpoints)
+ - [Retrieve the users which are following you](#retrieve-the-users-which-are-following-you)
+ - [Retrieve the users which you are following](#retrieve-the-users-which-you-are-following)
+ - [User/Lookup endpoints](#userlookup-endpoints)
+ - [Find Twitter Users](#find-twitter-users)
+ - [User/Mutes endpoints](#usermutes-endpoints)
+ - [Retrieve the users which you've muted](#retrieve-the-users-which-youve-muted)
+ - [Mute user by username or ID](#mute-user-by-username-or-id)
+ - [Unmute user by username or ID](#unmute-user-by-username-or-id)
+ - [User/Follows endpoints](#userfollows-endpoints)
+ - [Follow a user](#follow-a-user)
+ - [Unfollow a user](#unfollow-a-user)
+* [Contributing](#contributing)
+ - [To run test](#to-run-tests)
+ - [To run code analyzer](#to-run-code-analyzer)
## Installation
First, you need to add the component to your composer.json
@@ -44,13 +97,41 @@ Settings are expected as below:
$settings['bearer_token']
$client = new Client($settings);
+---
+## Tweets endpoints
-### To fetch a tweet by Id
+## Timeline endpoints
+
+### Find Recent Mentioning for a User
+Example:
+
+ $return = $client->timeline()->getRecentMentions($accountId)->performRequest();
+
+### Find Recent Tweets for a User
+Example:
+
+ $return = $client->timeline()->getRecentTweets($accountId)->performRequest();
+
+### Reverse Chronological Timeline by user ID
+Example:
+
+ $return = $client->timeline()->getReverseChronological()->performRequest();
+
+## Tweet/Likes endpoints
+
+### Tweets liked by a user
Example:
- $result = $client->tweet()->performRequest('GET', array( 'id' => $id));
+ $return = $client->tweetLikes()->addMaxResults($pageSize)->getLikedTweets($accountId)->performRequest();
-### To search specific tweets
+### Users who liked a tweet
+Example:
+
+ $return = $client->tweetLikes()->addMaxResults($pageSize)->getUsersWhoLiked($tweetId)->performRequest();
+
+## Tweet/Lookup endpoints
+
+### Search specific tweets
Example:
$return = $client->tweetLookup()
@@ -69,7 +150,90 @@ Example:
->performRequest()
;
-### To find Twitter Users
+ $client->tweetLookup()
+ ->addMaxResults($pageSize)
+ ->addFilterOnKeywordOrPhrase($keywordFilter)
+ ->addFilterOnLocales($localeFilter)
+ ->showUserDetails()
+ ->showMetrics()
+ ->performRequest()
+ ;
+
+### Find all replies from a Tweet
+
+ ->addFilterOnConversationId($tweetId);
+
+## Tweet endpoints
+
+### Fetch a tweet by Id
+Example:
+
+ $return = $client->tweet()->->fetch(1622477565565739010)->performRequest();
+
+### Create a new Tweet
+Example:
+
+ $return = $client->tweet()->create()->performRequest(['text' => 'Test Tweet... ']);
+
+## Tweet/Quotes endpoints
+
+### Returns Quote Tweets for a Tweet specified by the requested Tweet ID
+Example:
+
+ $return = $client->tweetQuotes()->getQuoteTweets($tweetId)->performRequest();
+
+## Retweet endpoints
+
+### Retweet a Tweet
+Example:
+
+ $return = $client->retweet()->performRequest(['tweetId' => $tweet_id]);
+
+## Tweet/Replies endpoints
+
+### Hide a reply to a Tweet
+Example:
+
+ $return = $client->->tweetReplies()->hideReply($tweetId)->performRequest(['hidden' => true]);
+
+### Unhide a reply to a Tweet
+Example:
+
+ $return = $client->->tweetReplies()->hideReply($tweetId)->performRequest(['hidden' => false]);
+
+## Tweet/Bookmarks endpoints
+
+### Lookup a user's Bookmarks
+Example:
+
+ $return = $client->tweetBookmarks()->lookup()->performRequest();
+
+---
+
+## Users endpoints
+
+## User/Blocks endpoints
+
+### Retrieve the users which you've blocked
+Example:
+
+ $return = $client->userBlocks()->lookup()->performRequest();
+
+## User/Follows endpoints
+
+### Retrieve the users which are following you
+Example:
+
+ $return = $client->userFollows()->getFollowers()->performRequest();
+
+### Retrieve the users which you are following
+Example:
+
+ $return = $client->userFollows()->getFollowing()->performRequest();
+
+## User/Lookup endpoints
+
+### Find Twitter Users
`findByIdOrUsername()` expects either an array, or a string.
You can specify the search mode as a second parameter (`Client::MODES['USERNAME']` OR `Client::MODES['ID']`)
@@ -81,21 +245,36 @@ Example:
->performRequest()
;
-### To find Recent Mentioning for a User
+## User/Mutes endpoints
+
+### Retrieve the users which you've muted
Example:
- $return = $client->timeline()->findRecentMentioningForUserId('1538300985570885636')->performRequest();
+ $return = $client->userMutes()->lookup()->performRequest();
-### To Post a new Tweet
+### Mute user by username or ID
Example:
- $return = $client->tweet()->performRequest('POST', ['text' => 'This is a test....']);
+ $return = $client->userMutes()->mute()->performRequest(['target_user_id' => $userId]);
-### To Retweet
+### Unmute user by username or ID
+Example:
+
+ $return = $client->userMutes()->unmute()->performRequest(['target_user_id' => $userId]);
+
+## User/Follows endpoints
+### Follow a user
Example:
-
- $return = $client->retweet()->performRequest('POST', ['tweet_id' => $tweet->id]);
+
+ $return = $client->userFollows()->follow()->performRequest(['target_user_id' => $userId]);
+
+### Unfollow a user
+Example:
+
+ $return = $client->userFollows()->unfollow($userId)->performRequest(['target_user_id' => self::$userId]);
+
+---
## Contributing
Fork/download the code and run
diff --git a/src/AbstractController.php b/src/AbstractController.php
index 5f74cf9..87b457c 100644
--- a/src/AbstractController.php
+++ b/src/AbstractController.php
@@ -159,7 +159,7 @@ public function setAuthMode(int $value): void
*/
private function extensionLoaded(string $ext): void
{
- if (! extension_loaded($ext)) {
+ if (!extension_loaded($ext)) {
throw new \Exception('PHP extension '.strtoupper($ext).' is not loaded.');
}
}
diff --git a/src/Timeline.php b/src/Timeline.php
index a841e49..b975b15 100644
--- a/src/Timeline.php
+++ b/src/Timeline.php
@@ -57,7 +57,7 @@ public function getReverseChronological(): Timeline
*/
protected function constructEndpoint(): string {
$endpoint = parent::constructEndpoint();
- if (! is_null($this->next_page_token)) {
+ if (!is_null($this->next_page_token)) {
$this->query_string['pagination_token'] = $this->next_page_token;
$endpoint .= '?' . http_build_query($this->query_string);
}
diff --git a/src/TweetBookmarks.php b/src/TweetBookmarks.php
index 8f9c9b5..18f4d50 100644
--- a/src/TweetBookmarks.php
+++ b/src/TweetBookmarks.php
@@ -8,8 +8,8 @@
* @see Bookmarks
* @author Martin Zeitler
*/
-class TweetBookmarks extends AbstractController {
-
+class TweetBookmarks extends AbstractController
+{
/**
* @param array $settings
* @throws \Exception
@@ -58,9 +58,10 @@ public function removeBookmark(int $target_tweet_id): TweetBookmarks
* @return string the URL for the request.
* @throws \Exception
*/
- protected function constructEndpoint(): string {
+ protected function constructEndpoint(): string
+ {
$endpoint = parent::constructEndpoint();
- if (! is_null($this->next_page_token)) {
+ if (!is_null($this->next_page_token)) {
$this->query_string['pagination_token'] = $this->next_page_token;
$endpoint .= '?' . http_build_query($this->query_string);
}
diff --git a/src/TweetLikes.php b/src/TweetLikes.php
index 07b9d98..08155cf 100644
--- a/src/TweetLikes.php
+++ b/src/TweetLikes.php
@@ -87,15 +87,16 @@ public function unlike(int $tweet_id): TweetLikes
* @return string the URL for the request.
* @throws \Exception
*/
- protected function constructEndpoint(): string {
- if (! empty($this->maxResults)) {
+ protected function constructEndpoint(): string
+ {
+ if (!empty($this->maxResults)) {
$this->query_string['max_results'] = $this->maxResults;
}
- if (! is_null($this->next_page_token)) {
+ if (!is_null($this->next_page_token)) {
$this->query_string['pagination_token'] = $this->next_page_token;
}
$endpoint = parent::constructEndpoint();
- if (sizeof($this->query_string) > 0) {
+ if (count($this->query_string) > 0) {
$endpoint .= '?' . http_build_query($this->query_string);
}
return $endpoint;
diff --git a/src/TweetQuotes.php b/src/TweetQuotes.php
index 1bffb61..482101b 100644
--- a/src/TweetQuotes.php
+++ b/src/TweetQuotes.php
@@ -7,8 +7,8 @@
* @see Quote Tweets
* @author Martin Zeitler
*/
-class TweetQuotes extends AbstractController {
-
+class TweetQuotes extends AbstractController
+{
/**
* @param array $settings
* @throws \Exception
diff --git a/src/TweetReplies.php b/src/TweetReplies.php
index f7c88a0..a5cc3e1 100644
--- a/src/TweetReplies.php
+++ b/src/TweetReplies.php
@@ -7,8 +7,8 @@
* @see Hide replies
* @author Martin Zeitler
*/
-class TweetReplies extends AbstractController {
-
+class TweetReplies extends AbstractController
+{
/**
* @param array $settings
* @throws \Exception
diff --git a/src/UserBlocks.php b/src/UserBlocks.php
index 886060a..6ca8543 100644
--- a/src/UserBlocks.php
+++ b/src/UserBlocks.php
@@ -7,8 +7,8 @@
* @see Blocks
* @author Martin Zeitler
*/
-class UserBlocks extends AbstractController {
-
+class UserBlocks extends AbstractController
+{
/**
* @param array $settings
* @throws \Exception
@@ -58,9 +58,10 @@ public function unblock(int $user_id): UserBlocks
* @return string the URL for the request.
* @throws \Exception
*/
- protected function constructEndpoint(): string {
+ protected function constructEndpoint(): string
+ {
$endpoint = parent::constructEndpoint();
- if (! is_null($this->next_page_token)) {
+ if (!is_null($this->next_page_token)) {
$this->query_string['pagination_token'] = $this->next_page_token;
$endpoint .= '?' . http_build_query($this->query_string);
}
diff --git a/src/UserFollows.php b/src/UserFollows.php
index e47e353..958dbb7 100644
--- a/src/UserFollows.php
+++ b/src/UserFollows.php
@@ -7,8 +7,8 @@
* @see Follows
* @author Martin Zeitler
*/
-class UserFollows extends AbstractController {
-
+class UserFollows extends AbstractController
+{
/**
* @param array $settings
* @throws \Exception
@@ -68,7 +68,8 @@ public function unfollow(int $target_user_id): UserFollows
* @return string the URL for the request.
* @throws \Exception
*/
- protected function constructEndpoint(): string {
+ protected function constructEndpoint(): string
+ {
$endpoint = parent::constructEndpoint();
if (! is_null($this->next_page_token)) {
$this->query_string['pagination_token'] = $this->next_page_token;
diff --git a/src/UserLookup.php b/src/UserLookup.php
index 4d8e5ae..b980472 100644
--- a/src/UserLookup.php
+++ b/src/UserLookup.php
@@ -40,7 +40,7 @@ public function findByIdOrUsername($idOrUsername): UserLookup
$this->idOrUsername = $idOrUsername;
if (is_int($this->idOrUsername) || (is_array($this->idOrUsername) && is_numeric($this->idOrUsername[0]))) {
$this->mode = self::MODES['ID'];
- } else if (is_string($this->idOrUsername) || (is_array($this->idOrUsername) && is_string($this->idOrUsername[0]))) {
+ } else if (is_string($this->idOrUsername) || is_string($this->idOrUsername[0])) {
$this->mode = self::MODES['USERNAME'];
}
return $this;
@@ -69,7 +69,7 @@ protected function constructEndpoint(): string
}
$endpoint .= implode(',', $this->idOrUsername);
// Pagination
- if (! is_null($this->next_page_token)) {
+ if (!is_null($this->next_page_token)) {
$endpoint .= '&pagination_token=' . $this->next_page_token;
}
} else {
@@ -79,7 +79,7 @@ protected function constructEndpoint(): string
$endpoint .= '/' . $this->idOrUsername;
// Pagination
- if (! is_null($this->next_page_token)) {
+ if (!is_null($this->next_page_token)) {
$endpoint .= '?pagination_token=' . $this->next_page_token;
}
}
diff --git a/src/UserMutes.php b/src/UserMutes.php
index bbcda38..102b1f5 100644
--- a/src/UserMutes.php
+++ b/src/UserMutes.php
@@ -7,8 +7,8 @@
* @see Mutes
* @author Martin Zeitler
*/
-class UserMutes extends AbstractController {
-
+class UserMutes extends AbstractController
+{
/**
* @param array $settings
* @throws \Exception
@@ -58,9 +58,10 @@ public function unmute(int $user_id): UserMutes
* @return string the URL for the request.
* @throws \Exception
*/
- protected function constructEndpoint(): string {
+ protected function constructEndpoint(): string
+ {
$endpoint = parent::constructEndpoint();
- if (! is_null($this->next_page_token)) {
+ if (!is_null($this->next_page_token)) {
$this->query_string['pagination_token'] = $this->next_page_token;
$endpoint .= '?' . http_build_query($this->query_string);
}