NewRelicPostService::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace ErsoyInsider\NewrelicCustomEvent\Services;
4
5
use ErsoyInsider\NewrelicCustomEvent\Models\NewRelicConfig;
6
use Ixudra\Curl\CurlService;
7
8
/**
9
 * Class NewRelicPostService
10
 * @package ErsoyInsider\NewrelicCustomEvent\Services
11
 */
12
class NewRelicPostService
13
{
14
    /**
15
     * @var CurlService
16
     */
17
    private $curlService;
18
    /**
19
     * @var NewRelicConfig
20
     */
21
    private $newRelicConfig;
22
23
    public function __construct(NewRelicConfig $newRelicConfig, CurlService $curlService)
24
    {
25
        $this->curlService = $curlService;
26
        $this->newRelicConfig = $newRelicConfig;
27
    }
28
29
    /**
30
     * @param array $payload
31
     * @return mixed
32
     */
33
    public function makeRequest(array $payload)
34
    {
35
        return $this->curlService
36
            ->to("https://insights-collector.newrelic.com/v1/accounts/{$this->newRelicConfig->getAccountId()}/events")
37
            ->withContentType('application/json')
38
            ->withHeader('X-Insert-Key:' . $this->newRelicConfig->getApiKey())
39
            ->withData($payload)
40
            ->asJson()
41
            ->post();
42
    }
43
}
44