A simple Laravel application that calculates the reach of a specific tweet. A user can enter the URL of a tweet. The application will lookup the people who retweeted the tweet using the Twitter API. The application then sums up the amount of followers each user has that has retweeted the tweet. These results are cached for two hours.
So:
- Input: URL of individual Tweet (string).
- Output: calculated reach of Tweet (integer).
- Cache lifetime: 120 minutes.
- Definitions:
- Reach: actual (!= potential) size of audience for Tweet, i.e. being the sum of all followers for everyone who retweeted the Tweet.
- Tweet URL: URI with the Twitter status ID in it.
A php artisan tweet:reach {url}
command to compute a Tweet's reach. Properly shows human input error's.
A small web tool calculate a Tweet's reach. Default, success and error state.
Basic tests as proof of concept. Including model factories in /database/factories/
.
- By design, the Twitter API v1.1 only returns up to 100 user IDs who retweeted a Tweet, see the API docs. There is no way around this for now. One could make a web scraper or some other convoluted way of solving the problem at hand, but not this time :)
Out of scope:
- Contracts/interfaces.
- Hitting the API rate limiter.
- 100% code coverage.
- DDD's domain research.
A selection of useful php artisan ...
commands.
Command | Description |
---|---|
ide-helper:generate |
Re-generate IDE documentation. |
tweet:reach {tweetUrl} |
Compute the reach of a Tweet by providing a Tweet URL. |
- PHP
>= 7.2.0
- Local:
php artisan serve
to start localhost:8000- On macOS, install Valet, run
valet link twitter-reach-calculator
from/public
and open twitter-reach-calculator.dev. Usevalet secure twitter-reach-calculator
to secure with TLS.
The Laravel Debugbar is installed for development environments.
Auto enabled when APP_DEBUG=true
.
Debugbar::info($object);
Debugbar::error('Error!');
Debugbar::warning('Watch out…');
Debugbar::addMessage('Another message', 'mylabel');
Kint is installed for easy debugging when in CLI with Kint::dump($var);
.
I suggest using Jetbrain's PHPStorm. IDE config files are present in the repo to ease setting up your development environment and to ensure consistent code style and conventions.
Laravel follows the PSR-2
coding standard and the PSR-4
autoloading standard. We use a custom code style, i.e. some small modifications of PSR-2. Please adhere to .editorconfig
and the IDE settings defined in /.idea
folder (set PHPStorm code style to 'Project').
Please adhere to Gitflow branching conventions.
Please use the publish-subscribe (pub-sub) pattern. It allows a high cohesion and low coupling.
- Dick de Leeuw, leeuw.studio