WakaTime PHP API
WakaTime API for PHP
This is a PHP package for WakaTime API. It offers all the methods from WakaTime API with additional methods for total hours logged.
If you are using Laravel check out WakaTime Reports and Laravel on my blog.
Planned Features
- OAuth 2.0 authentication
Installation
Add to your composer.json
:
"mabasic/wakatime-php-api": "~1.0"
and run composer update
or type this from command line:
composer require "mabasic/wakatime-php-api=~1.0"
Usage
<?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.
Methods
Official methods
currentUser
$wakatime->currentUser()
See: https://wakatime.com/developers/#users for details.
dailySummary
$wakatime->dailySummary($startDate, $endDate, $project = null)
See: https://wakatime.com/developers/#summaries for details.
stats
$wakatime->stats($range, $project = null)
See: https://wakatime.com/developers/#stats for details.
Additional methods
getHoursLoggedFor
$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);
getHoursLoggedForLast
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');
getHoursLoggedForToday
public function getHoursLoggedForToday($project = null)
Returns hours logged today. You can optionally specify a project.
getHoursLoggedForYesterday
public function getHoursLoggedForYesterday($project = null)
Returns hours logged yesterday. You can optionally specify a project.
getHoursLoggedForLast7Days
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.
getHoursLoggedForLast30Days
public function getHoursLoggedForLast30Days($project = null)
Calculates hours logged for last 30 days in history. You can optionally specify a project.
getHoursLoggedForThisMonth
public function getHoursLoggedForThisMonth($project = null)
Calculates hours logged for this month. You can optionally specify a project.
getHoursLoggedForLastMonth
public function getHoursLoggedForLastMonth($project = null)
Calculates hours logged for last month. You can optionally specify a project.
Testing instructions
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.