diff --git a/README.md b/README.md index a70a637..8add952 100644 --- a/README.md +++ b/README.md @@ -16,19 +16,19 @@ If you are using [Laravel](http://laravel.com/) check out [WakaTime Reports and Add to your `composer.json`: -``` +```php "mabasic/wakatime-php-api": "~1.0" ``` -and run `composer update` or type this from command line: +and run `composer update` or type this from command line: -``` +```php composer require "mabasic/wakatime-php-api=~1.0" ``` ## Usage -``` +```php setApiKey($your_api_key_for_wakatime); ``` You can get your Api Key from your [settings page](https://wakatime.com/settings). - + > Be sure to set your Api Key before using any of the methods because you will get an Exception. - + ## Methods ### Official methods #### currentUser -``` +```php $wakatime->currentUser() ``` @@ -56,28 +56,36 @@ See: https://wakatime.com/api#users-current for details. #### dailySummary -``` +```php $wakatime->dailySummary($startDate, $endDate, $project = null) ``` See: https://wakatime.com/api#summary-daily for details. +#### stats + +```php +$wakatime->stats($range, $project = null) +``` + +See: https://wakatime.com/developers#stats for details. + ### Additional methods #### getHoursLoggedFor -``` +```php $wakatime->getHoursLoggedFor($startDate, $endDate, $project = null) ``` -Calculates hours logged for a specific period. +Calculates hours logged for a specific period. _You can optionally specify a project._ > `$startDate` must be lower than `$endDate` **Example:** -``` +```php $startDate = '11/21/2014'; $endDate = '12/21/2014'; @@ -86,49 +94,49 @@ $hours = $wakaTime->getHoursLoggedFor($startDate, $endDate); #### getHoursLoggedForLast -``` +```php public function getHoursLoggedForLast($period, $project = null) ``` -Calculates hours logged in last xy days, months. +Calculates hours logged in last xy days, months. _You can optionally specify a project._ **Example:** -``` +```php $hours = $wakaTime->getHoursLoggedForLast('7 days'); ``` #### getHoursLoggedForToday -``` +```php public function getHoursLoggedForToday($project = null) ``` -Returns hours logged today. +Returns hours logged today. _You can optionally specify a project._ #### getHoursLoggedForYesterday -``` +```php public function getHoursLoggedForYesterday($project = null) ``` -Returns hours logged yesterday. +Returns hours logged yesterday. _You can optionally specify a project._ #### getHoursLoggedForLast7Days -``` +```php public function getHoursLoggedForLast7Days($project = null) ``` -Basic users can only see data for maximum 7 days. Become a Premium user to preserve all data history. +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 -``` +```php public function getHoursLoggedForLast30Days($project = null) ``` @@ -137,7 +145,7 @@ _You can optionally specify a project._ #### getHoursLoggedForThisMonth -``` +```php public function getHoursLoggedForThisMonth($project = null) ``` @@ -146,7 +154,7 @@ _You can optionally specify a project._ #### getHoursLoggedForLastMonth -``` +```php public function getHoursLoggedForLastMonth($project = null) ``` @@ -173,4 +181,4 @@ export WAKATIME_API_KEY=xyz export WAKATIME_PROJECT=xyz ``` -_Of course replace `xyz` with correct values._ \ No newline at end of file +_Of course replace `xyz` with correct values._ diff --git a/src/WakaTime.php b/src/WakaTime.php index b055468..bc3919a 100644 --- a/src/WakaTime.php +++ b/src/WakaTime.php @@ -66,6 +66,20 @@ public function dailySummary($startDate, $endDate, $project = null) return $this->guzzle->get("{$this->url}/summaries?start={$startDate}&end={$endDate}&api_key={$this->getApiKey()}" . $project)->json(); } + /** + * See: https://wakatime.com/developers#stats for details. + * + * @param $range + * @param null $project + * @return mixed + */ + public function stats($range, $project = null) + { + if ($project !== null) $project = "&project={$project}"; + + return $this->guzzle->get("{$this->url}/users/current/stats/{$range}?api_key={$this->getApiKey()}" . $project)->json(); + } + /** * Calculates hours logged for a specific period. * You can optionally specify a project. diff --git a/tests/WakaTimeTest.php b/tests/WakaTimeTest.php index 03857f1..96f622b 100644 --- a/tests/WakaTimeTest.php +++ b/tests/WakaTimeTest.php @@ -150,6 +150,28 @@ public function it_returns_the_currently_logged_in_user() $this->assertInternalType('array', $response); } + /** @test */ + public function it_returns_user_stats_for_range() + { + // Act + $range = 'last_30_days'; + $response = $this->wakaTime->stats($range, $this->project); + + // Assert + $this->assertInternalType('array', $response); + } + + /** @test */ + public function it_returns_user_stats_for_range_and_project() + { + // Act + $range = 'last_30_days'; + $response = $this->wakaTime->stats($range, $this->project); + + // Assert + $this->assertInternalType('array', $response); + } + /** @test */ public function it_returns_the_daily_summary_for_period() {