Skip to content

Laravel based Twitter reach calculator.

Notifications You must be signed in to change notification settings

leeuwd/twitter-reach-calculator

Repository files navigation

Twitter reach calculator

Task description

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.

Deliverable

CLI

A php artisan tweet:reach {url} command to compute a Tweet's reach. Properly shows human input error's.

CLI

Web UI

A small web tool calculate a Tweet's reach. Default, success and error state.

Web

Unit test

Basic tests as proof of concept. Including model factories in /database/factories/.

Unit tests

Limitation

  • 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.

Commands

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.

Sysops

Requirements

  • PHP >= 7.2.0

Environments

Debugbar

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

Kint is installed for easy debugging when in CLI with Kint::dump($var);.

IDE

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.

Conventions

Code style

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').

Branching

Please adhere to Gitflow branching conventions.

Javascript pattern

Please use the publish-subscribe (pub-sub) pattern. It allows a high cohesion and low coupling.

Attribution

Author

Dependencies

About

Laravel based Twitter reach calculator.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published