Skip to content

Commit

Permalink
accidentally removed this
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell committed Aug 13, 2021
1 parent 987f25e commit affb0cf
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/Fieldtypes/Tag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace TransformStudios\Uptime\Fieldtypes;

use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Http;
use Statamic\Fieldtypes\Relationship;

class Tag extends Relationship
{
protected static $handle = 'uptime_tag';

public function getIndexItems($request)
{
$response = Http::withToken(config('uptime.api_key'), 'Token')
->get('https://uptime.com/api/v1/check-tags/');

return collect(Arr::get($response->json(), 'results'))
->map(fn (array $tagData) => ['id' => $tagData['tag'], 'title' => $tagData['tag']])
->sortBy('title');
}

// public function preProcessIndex($id)
// {
// if (is_null($id)) {
// return;
// }

// return [[
// 'id' => $id,
// 'title' => $id,
// ]];
// }

protected function toItemArray($id)
{
if (! $id) {
return [];
}

return [
'id' => $id,
'title' => $id,
];
}
}

0 comments on commit affb0cf

Please sign in to comment.