PHP code example of borivojevic / rescuetime

1. Go to this page and download the library: Download borivojevic/rescuetime library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

borivojevic / rescuetime example snippets


php composer.phar install


 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();
}