This application connects to a fictional social media network. One endpoint registers a token and the other endpoint fetches posts made by fictional users across a 6 month period.
You should be running PHP 8.0+, the latest version of composer and available to use command line on your machine for any commands listed below. How you run PHP is up to you!
guzzlehttp/guzzle
- to make API callssymfony/cache
- not to disturb the API muchvlucas/phpdotenv
- to keep some config data out of files
1. Setup .env file: Copy /.env.example
to /.env
. Add required settings there. Finding out the required settings is part of the assignment.
2. Run docker-compose:
To build the container to run the assignment in, run command docker-compose up --build
. This will create container php_assignment
in Docker project supermetrics
.
The container will be listening on port 7777
on your localhost
.
Note: Locally changed files will not be updated to the Docker container automatically as mirroring is not enabled. This means you will need to run docker-compose
again to update the files inside the container.
Application can be reached from the localhost: http://localhost:7777 - shows the main page.
Run tests:
-
Connect to container: Connect to container by running command
docker exec -it php_assignment /bin/bash
. -
Change path: Previous command should take you to path
/app
, but make sure of that by running commandcd /app
. -
Run tests: Run the tests with command
./vendor/bin/phpunit
.
This application is using two custom API endpoints
POST: https://api.supermetrics.com/assignment/register
This endpoint registers a token for use against the second endpoint
PARAMS:
client_id: ju16a6m81mhid5ue1z3v2g0uh
email: [email protected]
name: Your Name
RETURNS:
sl_token: This token string should be used in the subsequent query. Please note that this token will only last 1 hour from when the REGISTER call happens. You will need to register and fetch a new token as you need it.
client_id: returned for informational purposes only
email: returned for informational purposes only
GET: https://api.supermetrics.com/assignment/posts
This endpoint fetches posts along a number of pages using the registered token.
PARAMS:
sl_token: Token from the register call
page: integer page number of posts (1-10)
RETURNS:
page: What page was requested or retrieved
posts: 100 posts per page