danvin-test/twitter-activity

Simple PHP Twitter User Activity Checker

1.1 2018-06-08 17:22 UTC

This package is not auto-updated.

Last update: 2024-05-05 04:43:00 UTC


README

This small web app takes user's twitter screen name as a parameter and return a JSON-encoded array containing "hour -> tweets count" for a given user, to determine what hour of the day they are most active. It also provides demonstration of the Silex's routing.

Requirements

  1. PHP 7.1.3 or later
  2. Enabled PHP CURL module
  3. Enabled mod_rewrite module (only for usage on webserver)

Installation

  1. Install Composer

     curl -s https://getcomposer.org/installer | php
    
  2. Execute

     php composer.phar create-project danvin-test/twitter-activity project_name
    

Configuration

Twitter API Credentials

Edit config.json, located in the root folder of the project, to set up your Twitter API credentials.

Notable mention: This web app uses statuses/user_timeline Twitter API. Advanced configuration available in the config.json, under twitterRequestSettings section.

.htaccess

If your site is not at the webroot level you will have to uncomment the RewriteBase statement and adjust the path to point to your directory, relative from the webroot. More information available at the Silex Webserver Configuration page

Usage

The application has 3 endpoints:

  1. "/" - will respond with "Try /hello/:name" as text
  2. "/hello/Daniel" - will respond with “Hello Daniel” as text
  3. "/histogram/Ferrari" - will respond with a JSON-encoded array displaying the number of tweets per hour of the day. Most active hours will be presented at the top of the array.

CLI

php index.php GET /                            
php index.php GET /hello/Daniel
php index.php GET /histogram/Ferrari

WebServer

http://localhost/
http://localhost/hello/daniel
http://localhost/histogram/Ferrari

Running the tests

  1. Make sure you have PHPUnit installed.

  2. To execute the tests, navigate into your project's folder and run

     phpunit
    

Built With

  1. Silex
  2. twitter-api-php