Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions CashPilot/CashPilot.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,33 @@ class CashPilot extends \App\SupportedApps implements \App\EnhancedApps
public function test()
{
$test = parent::appTest($this->url('api/earnings/summary'), $this->attrs());

// CashPilot answers 403 to its fleet key (CASHPILOT_API_KEY), which only
// enrolls workers and reads nothing. Say which key the tile needs.
if ($test->code === 403) {
echo 'Failed: use the read-only API key (CASHPILOT_READONLY_API_KEY)';
return;
}

echo $test->status;
}

public function livestats()
{
$status = 'inactive';
$data = [];
$data = [
'earnings' => '—',
'running' => '—',
];

$res = parent::execute($this->url('api/earnings/summary'), $this->attrs());

// execute() returns null when CashPilot cannot be reached, and a 401 or
// 403 body still decodes to an object. Only a 200 is an answer.
if ($res === null || $res->getStatusCode() !== 200) {
return parent::getLiveStats($status, $data);
}

$details = json_decode($res->getBody());

if ($details) {
Expand All @@ -27,15 +45,15 @@ public function livestats()
// is zero". has_readings is false on a fresh install and on one whose
// collection has stopped, so a figure there would state a
// measurement that was never taken.
$data['earnings'] = (isset($details->has_readings) && $details->has_readings)
? '$' . number_format((float) ($details->total_adjusted ?? 0), 2)
: '—';
if (isset($details->has_readings) && $details->has_readings) {
$data['earnings'] = '$' . number_format((float) ($details->total_adjusted ?? 0), 2);
}

// active_services is null when the count could not be taken. Showing
// 0 would read as "nothing is running" while containers are running.
$data['running'] = (isset($details->active_services) && $details->active_services !== null)
? $details->active_services
: '—';
if (isset($details->active_services)) {
$data['running'] = $details->active_services;
}
}

return parent::getLiveStats($status, $data);
Expand Down
2 changes: 1 addition & 1 deletion CashPilot/cashpilot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions CashPilot/config.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<div class="items">
<div class="input">
<label>{{ strtoupper(__('app.url')) }}</label>
{!! Form::text('config[override_url]', null, array('placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control')) !!}
{!! Form::text('config[override_url]', isset($item) ? ($item->getconfig()->override_url ?? null) : null, array('placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control')) !!}
</div>
<div class="input">
<label>{{ __('app.apps.apikey') }} (API Key)</label>
{!! Form::text('config[access_token]', null, array('placeholder' => __('app.apps.apikey'), 'data-config' => 'access_token', 'class' => 'form-control config-item')) !!}
<label>{{ __('app.apps.apikey') }} (read-only)</label>
{!! Form::text('config[access_token]', isset($item) ? ($item->getconfig()->access_token ?? null) : null, array('placeholder' => 'CASHPILOT_READONLY_API_KEY', 'data-config' => 'access_token', 'class' => 'form-control config-item')) !!}
</div>
<div class="input">
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
Expand Down