Skip to content

Commit

Permalink
Add beginning of everhour, main setup menu and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
godbout committed Jun 22, 2019
1 parent 39872b4 commit 0392e6c
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 11 deletions.
Binary file added resources/icons/everhour.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions src/Menus/Everhour/Setup.php
@@ -0,0 +1,70 @@
<?php

namespace Godbout\Alfred\Time\Menus\Everhour;

use Godbout\Alfred\Time\Workflow;
use Godbout\Alfred\Workflow\Icon;
use Godbout\Alfred\Workflow\Item;
use Godbout\Alfred\Time\Menus\Menu;
use Godbout\Alfred\Workflow\ScriptFilter;

class Setup extends Menu
{
public static function scriptFilter()
{
ScriptFilter::add(
self::apikey(),
self::state(),
self::back()
);
}

private static function apikey()
{
return Item::create()
->title(self::apikeyTitle())
->subtitle(self::apikeySubtitle())
->arg('everhour_setup_apikey')
->icon(Icon::create('resources/icons/everhour.png'));
}

private static function apikeyTitle()
{
return empty(Workflow::getConfig()->read('everhour.api_token')) ? 'Set API KEY' : 'Update API KEY';
}

private static function apikeySubtitle()
{
$apikey = Workflow::getConfig()->read('everhour.api_token');

return empty($apikey) ? 'No API KEY found' : 'Current API KEY: ' . substr($apikey, 0, 11) . '...';
}

private static function state()
{
return Item::create()
->title(self::stateTitle())
->subtitle(self::stateSubtitle())
->arg('everhour_setup_state')
->variable('everhour_enabled', Workflow::getConfig()->read('everhour.is_active') ? 'false' : 'true')
->icon(Icon::create('resources/icons/everhour.png'));
}

private static function stateTitle()
{
return (Workflow::getConfig()->read('everhour.is_active') === true) ? 'Disable' : 'Enable';
}

private static function stateSubtitle()
{
return (Workflow::getConfig()->read('everhour.is_active') === true) ? 'Currently enabled' : 'Currently disabled';
}

private static function back()
{
return Item::create()
->title('Back')
->arg('setup')
->icon(Icon::create('resources/icons/icon.png'));
}
}
14 changes: 11 additions & 3 deletions src/Menus/Setup.php
Expand Up @@ -12,10 +12,9 @@ public static function scriptFilter()
{
ScriptFilter::add(
self::toggl(),
self::harvest()
self::harvest(),
self::everhour()
);

ScriptFilter::sortItems();
}

private static function toggl()
Expand All @@ -35,4 +34,13 @@ private static function harvest()
->icon(Icon::create('resources/icons/harvest.png'))
->arg('harvest_setup');
}

private static function everhour()
{
return Item::create()
->title('Setup Everhour')
->subtitle('')
->icon(Icon::create('resources/icons/everhour.png'))
->arg('everhour_setup');
}
}
52 changes: 52 additions & 0 deletions src/Services/Everhour.php
@@ -0,0 +1,52 @@
<?php

namespace Godbout\Alfred\Time\Services;

use Exception;
use Carbon\Carbon;
use Carbon\CarbonInterval;
use MorningTrain\TogglApi\TogglApi;

class Everhour extends TimerService
{
private $client;

private $data = null;


public function __construct($apiToken)
{
}

public function projects()
{
}

public function tags()
{
}

public function pastTimers()
{
}

public function startTimer()
{
}

public function stopCurrentTimer()
{
}

public function runningTimer()
{
}

public function continueTimer($timerId)
{
}

public function deleteTimer($timerId)
{
}
}
19 changes: 17 additions & 2 deletions src/Workflow.php
Expand Up @@ -6,12 +6,14 @@
use Godbout\Alfred\Time\Services\Toggl;
use Godbout\Alfred\Time\Services\Harvest;
use Godbout\Alfred\Workflow\ScriptFilter;
use Godbout\Alfred\Time\Services\Everhour;

class Workflow
{
const SERVICES = [
'toggl',
'harvest'
'harvest',
'everhour'
];

private static $instance = null;
Expand Down Expand Up @@ -91,6 +93,11 @@ public static function disableService($service = '')
return self::getInstance()->serviceStatus($service, false);
}

public static function services()
{
return self::SERVICES;
}

protected function serviceStatus($service, $status = false)
{
self::getInstance()->disableAllServices();
Expand All @@ -112,7 +119,9 @@ protected function classExistsForService($service = '')
public static function serviceEnabled()
{
if (self::getInstance()->getConfig()->read('toggl.is_active')) {
return new Toggl(Workflow::getConfig()->read('toggl.api_token'));
return new Toggl(
Workflow::getConfig()->read('toggl.api_token')
);
}

if (self::getInstance()->getConfig()->read('harvest.is_active')) {
Expand All @@ -122,6 +131,12 @@ public static function serviceEnabled()
);
}

if (self::getInstance()->getConfig()->read('everhour.is_active')) {
return new Everhour(
Workflow::getConfig()->read('everhour.api_token')
);
}

return null;
}

Expand Down
25 changes: 25 additions & 0 deletions tests/Feature/EverhourSetupMenusTest.php
@@ -0,0 +1,25 @@
<?php

namespace Tests\Feature;

use Tests\TestCase;
use Godbout\Alfred\Time\Workflow;

class EverhourSetupMenusTest extends TestCase
{
/** @test */
public function it_shows_setting_an_api_key_if_none_is_saved_in_the_config_yet()
{
$this->everhourApikey('');

$output = $this->reachEverhourSetupMenu();

$this->assertStringContainsString('"subtitle":"No API KEY found"', $output);
}

/** @test */
public function some_more_test()
{
$this->markTestIncomplete('lots of test to add for everhour');
}
}
1 change: 1 addition & 0 deletions tests/Feature/SetupMenusTest.php
Expand Up @@ -32,6 +32,7 @@ public function it_proposes_to_setup_toggl_and_harvest_if_setup_is_accepted_and_

$this->assertStringContainsString('"toggl_setup"', $output);
$this->assertStringContainsString('"harvest_setup"', $output);
$this->assertStringContainsString('"everhour_setup"', $output);
}

/** @test */
Expand Down
16 changes: 10 additions & 6 deletions tests/Feature/WorkflowTest.php
Expand Up @@ -48,13 +48,15 @@ public function it_detects_when_a_timer_is_already_running_and_proposes_to_stop_
/** @test */
public function it_can_disable_all_services_at_once()
{
Workflow::enableService('toggl');
Workflow::enableService('harvest');
foreach (Workflow::services() as $service) {
Workflow::enableService($service);
}

Workflow::disableAllServices();

$this->assertFalse(Workflow::getConfig()->read('toggl.is_active'));
$this->assertFalse(Workflow::getConfig()->read('harvest.is_active'));
foreach (Workflow::services() as $service) {
$this->assertFalse(Workflow::getConfig()->read("$service.is_active"));
}
}

/** @test */
Expand All @@ -81,10 +83,12 @@ public function it_only_allows_one_service_enabled_at_a_time()
{
Workflow::enableService('toggl');
Workflow::enableService('harvest');
Workflow::enableService('everhour');

$this->assertTrue(Workflow::getConfig()->read('harvest.is_active'));
$this->assertTrue(Workflow::getConfig()->read('everhour.is_active'));
$this->assertFalse(Workflow::getConfig()->read('harvest.is_active'));
$this->assertFalse(Workflow::getConfig()->read('toggl.is_active'));

$this->assertSame('harvest', (string) Workflow::serviceEnabled());
$this->assertSame('everhour', (string) Workflow::serviceEnabled());
}
}
10 changes: 10 additions & 0 deletions tests/TestCase.php
Expand Up @@ -91,6 +91,11 @@ protected function harvestApitoken($apitoken = '1153865.pt.Vjxherj4YPfPiEhTp3jOR
Workflow::getConfig()->write('harvest.api_token', $apitoken);
}

protected function everHourApikey($apikey = '507f-ef41-c355b1-992023-06d0dff9')
{
Workflow::getConfig()->write('everhour.api_token', $apikey);
}

protected function harvestAccountId($accountId = '987654')
{
Workflow::getConfig()->write('harvest.account_id', $accountId);
Expand All @@ -116,6 +121,11 @@ protected function reachHarvestSetupMenu()
return $this->reachWorkflowMenu('action=harvest_setup');
}

protected function reachEverhourSetupMenu()
{
return $this->reachWorkflowMenu('action=everhour_setup');
}

protected function reachTogglApikeySetupMenu()
{
return $this->reachWorkflowMenu('action=toggl_setup_apikey');
Expand Down

0 comments on commit 0392e6c

Please sign in to comment.