-
Notifications
You must be signed in to change notification settings - Fork 1
/
HttpClient.php
49 lines (42 loc) · 1.03 KB
/
HttpClient.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace Appkeep\Laravel;
use Appkeep\Laravel\Facades\Appkeep;
use Illuminate\Support\Facades\Http;
use Appkeep\Laravel\Events\AbstractEvent;
use Appkeep\Laravel\Events\ScheduledTaskEvent;
class HttpClient
{
/**
* @var string
*/
private $key;
public function __construct($key)
{
$this->key = $key;
}
/**
* Send data to Appkeep
*/
public function sendEvent(AbstractEvent $event)
{
return Http::withHeaders($this->defaultHeaders())->post(
config('appkeep.endpoint'),
$event->toArray()
);
}
/**
* Send scheduled task result
*/
public function sendScheduledTaskOutput(ScheduledTaskOutput $output)
{
return $this->sendEvent(new ScheduledTaskEvent($output))->throw();
}
protected function defaultHeaders()
{
return [
'accept' => 'application/json',
'authorization' => 'Bearer ' . $this->key,
'x-appkeep-client' => Appkeep::version(),
];
}
}