mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
85 lines
1.9 KiB
PHP
85 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Karat;
|
|
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class Api
|
|
{
|
|
/**
|
|
* @var array|mixed
|
|
*/
|
|
private static mixed $username;
|
|
/**
|
|
* @var array|mixed
|
|
*/
|
|
private static mixed $password;
|
|
/**
|
|
* @var array|mixed
|
|
*/
|
|
private static mixed $endpoint;
|
|
|
|
public function __construct()
|
|
{
|
|
self::$username = Config::get('services.karat.username');
|
|
self::$password = Config::get('services.karat.password');
|
|
self::$endpoint = Config::get('services.karat.endpoint');
|
|
}
|
|
|
|
private static function doRequest($body)
|
|
{
|
|
$response = Http::timeout(300)
|
|
->withOptions([
|
|
'debug' => true,
|
|
'verify' => false,
|
|
])->withBasicAuth(self::$username, self::$password)
|
|
->post(self::$endpoint, $body);
|
|
|
|
return $response->json();
|
|
}
|
|
|
|
public static function getUsers()
|
|
{
|
|
$body = [
|
|
'command' => 'TM_GET_USERS',
|
|
];
|
|
|
|
return self::doRequest($body)['users'];
|
|
}
|
|
|
|
public static function getClients()
|
|
{
|
|
$body = [
|
|
'command' => 'TM_GET_CLIENTS',
|
|
];
|
|
|
|
return self::doRequest($body)['clients'];
|
|
}
|
|
|
|
public static function getProjects()
|
|
{
|
|
$body = [
|
|
'command' => 'TM_GET_PROJECTS',
|
|
];
|
|
|
|
return self::doRequest($body)['projects'];
|
|
}
|
|
|
|
public static function setTimesheet($timesheet)
|
|
{
|
|
echo 'Setting timesheet for project ' . $timesheet->subtask->mastertask->project->code . PHP_EOL;
|
|
|
|
$body = [
|
|
'command' => 'TM_SET_vykaz',
|
|
'zakazka' => $timesheet->subtask->mastertask->project->code,
|
|
'zdroj' => $timesheet->user->code,
|
|
'hodin' => $timesheet->time,
|
|
'datum' => $timesheet->created_at->format('Y-m-d'),
|
|
'task_mng' => $timesheet->id,
|
|
];
|
|
|
|
return self::doRequest($body);
|
|
}
|
|
}
|