, (*1)
rescuetime-api-php
PHP wrapper library for RescueTime API, (*2)
At this point RescueTime API provides single endpoint to fetch detailed and complicated data. The data is read-only through the API., (*3)
Initial release of RescueTime API is targeted at bringing developers the prepared and pre-organized data structures already familiar through the reporting views of www.rescuetime.com.
Keep in mind this is a draft interface, and may change in the future. RescueTime do intend to version the interfaces though, so it is likely forward compatible., (*4)
Installation
Recommend way to install this package with Composer. Add borivojevic/rescuetime-api-php to your composer.json file., (*5)
``` json
{
"require": {
"borivojevic/rescuetime": "2.*"
}
}, (*6)
To install composer run:
curl -s http://getcomposer.org/installer | php, (*7)
To install composer dependences run:
php composer.phar install, (*8)
You can autoload all dependencies by adding this to your code:
require 'vendor/autoload.php';, (*9)
### Usage ###
The main entry point of the library is the `RescueTime\Client` class. API methods require to be signed with valid `api_key` parameter which you have to provide as a first argument of the constructor. You can obtain RescueTime API key on [API Key Management][] console page.
``` php
<?php
use RescueTime\RequestQueryParameters as Params;
use RescueTime\Client;
$client = new Client($apiKey);
// Basic example
$activities = $client->getActivities(new Params(['perspective' => 'rank']));
foreach ($activities as $activity) {
echo $activity->getActivityName();
echo $activity->getProductivity();
}
// Fetch activities for past week
$activities = $client->getActivities(
new Params([
'perspective' => 'interval',
'resolution_time' => 'day',
'restrict_begin' => new \DateTime("-6 day"),
'restrict_end' => new \DateTime("today")
])
);
// Fetch productivity data grouped by activity
$activities = $client->getActivities(
new Params([
'perspective' => 'interval',
'resolution_time' => 'day',
'restrict_begin' => new \DateTime("-6 day"),
'restrict_end' => new \DateTime("today"),
'restrict_kind' => 'activity'
])
);
// Fetch productivity data grouped by category
$activities = $client->getActivities(
new Params([
'perspective' => 'interval',
'resolution_time' => 'day',
'restrict_begin' => new \DateTime("-6 day"),
'restrict_end' => new \DateTime("today"),
'restrict_kind' => 'category'
])
);
// Fetch daily productivity report data for past two weeks
$daily_summary = $client->getDailySummary();
foreach ($daily_summary as $day_summary) {
echo $day_summary->getTotalDurationFormatted();
echo $day_summary->getVeryDistractingHours();
echo $day_summary->getVeryDistractingDurationFormatted();
}
You can build more complex queries and filter down the data by providing other query parameters:, (*10)
php
$client->getActivities(
new Params([
"perspective" => <rank|interval|member>,
"resolution_time" => <month|week|day|hour>,
"restrict_group" => <group name>,
"restrict_user" => <user name/user email>,
"restrict_begin" => <\DateTime>,
"restrict_end" => <\DateTime>,
"restrict_kind" => <category|activity|productivity|document>,
"restrict_project" => <project name>,
"restrict_thing" => <category name/activity name/overview name>,
"restrict_thingy" => <document name/activity name>
])
);
, (*11)
Each query parameter is explained in more details in official HTTP Query Interface documentation., (*12)
For a working example of an app build on top of rescuetime-api-php library take a look at borivojevic/rescuetime-statusboard., (*13)
Contributing
Patches and pull requests are welcome. Take a look at Contributing guidelines for further info., (*14)
Versioning
The library uses Semantic Versioning, (*15)
Copyright and License
The library is licensed under the MIT license., (*16)