WakaTime API for PHP
This is a PHP package for WakaTime API. It supports resource endpoints from WakaTime API with additional helper methods for hours logged.
If you are using Laravel check out WakaTime Reports and Laravel.
If you find that some resource endpoints are missing feel free to send me a PR. (Be sure to include tests for your code)
Type this from command line:
composer require mabasic/wakatime-php-api
<?php
use GuzzleHttp\Client as Guzzle;
use Mabasic\WakaTime\WakaTime;
$wakatime = new WakaTime(new Guzzle, $your_api_key_for_wakatime);
You can get your Api Key from your settings page.
$wakatime->currentUser()
// or
$wakatime->users('username');
See: https://wakatime.com/developers/#users for details.
$wakatime->summaries($startDate, $endDate, $project = null)
See: https://wakatime.com/developers/#summaries for details.
$wakatime->stats($range, $project = null)
See: https://wakatime.com/developers/#stats for details.
$date = '01/22/2016';
$wakatime->heartbeats($date);
See: https://wakatime.com/developers#heartbeats for details.
$wakatime->getHoursLoggedFor($startDate, $endDate, $project = null)
Calculates hours logged for a specific period. You can optionally specify a project.
$startDate
must be lower than$endDate
Example:
$startDate = '11/21/2014';
$endDate = '12/21/2014';
$hours = $wakaTime->getHoursLoggedFor($startDate, $endDate);
public function getHoursLoggedForLast($period, $project = null)
Calculates hours logged in last xy days, months. You can optionally specify a project.
Example:
$hours = $wakaTime->getHoursLoggedForLast('7 days');
public function getHoursLoggedForToday($project = null)
Returns hours logged today. You can optionally specify a project.
public function getHoursLoggedForYesterday($project = null)
Returns hours logged yesterday. You can optionally specify a project.
public function getHoursLoggedForLast7Days($project = null)
Basic users can only see data for maximum 7 days. Become a Premium user to preserve all data history. You can still use any method as long as it is under 7 days.
public function getHoursLoggedForLast30Days($project = null)
Calculates hours logged for last 30 days in history. You can optionally specify a project.
public function getHoursLoggedForThisMonth($project = null)
Calculates hours logged for this month. You can optionally specify a project.
public function getHoursLoggedForLastMonth($project = null)
Calculates hours logged for last month. You can optionally specify a project.
Copy .env.example
file to .env
and set your api key and project name before running tests with:
vendor/bin/phpunit