WakaTime API for PHP
This is a PHP package for WakaTime API. It offers all the methods from WakaTime API plus some additional methods for total hours logged.
- OAuth 2.0 authentication
Add to your composer.json
:
"mabasic/wakatime-php-api": "~1.0"
or type this from command line:
composer require "mabasic/wakatime-php-api=~1.0"
Then run composer dump-autoload
.
<?php
use GuzzleHttp\Client as Guzzle;
use Mabasic\WakaTime\WakaTime;
$wakatime = new WakaTime(new Guzzle);
$wakaTime->setApiKey($your_api_key_for_wakatime);
You can get your Api Key from your settings page.
Be sure to set your Api Key before using any of the methods because you will get an Exception.
$wakatime->currentUser()
See: https://wakatime.com/api#users-current for details.
$wakatime->dailySummary($startDate, $endDate, $project = null)
See: https://wakatime.com/api#summary-daily 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.
For testing purposes set these environment variables before running tests:
On windows use:
setx WAKATIME_API_KEY xyz
setx WAKATIME_PROJECT xyz
On Linux use:
export WAKATIME_API_KEY=xyz
export WAKATIME_PROJECT=xyz
Of course replace xyz
with correct values.