Skip to content

mabasic/wakatime-php-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WakaTime PHP API

WakaTime API for PHP

Become a Patron

Overview

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)

Installation

Type this from command line:

composer require mabasic/wakatime-php-api

Usage

<?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.

Resource Endpoints

Users

$wakatime->currentUser()

// or

$wakatime->users('username');

See: https://wakatime.com/developers/#users for details.

Summaries

$wakatime->summaries($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.

Heartbeats

$date = '01/22/2016';

$wakatime->heartbeats($date);

See: https://wakatime.com/developers#heartbeats for details.

Helper methods aka Reports aka Shortcuts

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.


For developers only

Copy .env.example file to .env and set your api key and project name before running tests with:

vendor/bin/phpunit

Laravelista Sponsors & Backers

I would like to extend my thanks to the following sponsors & backers for funding my open-source journey. If you are interested in becoming a sponsor or backer, please visit the Laravelista Backers page.

Contributing

Thank you for considering contributing to WakaTime PHP API! The contribution guide can be found on the Laravelista website.

Code of Conduct

In order to ensure that the Laravelista community is welcoming to all, please review and abide by the Code of Conduct.

License

WakaTime PHP API is open-source software licensed under the MIT license.