Completed
Push — master ( 73e0b1...55420f )
by Sergey
06:20 queued 03:39
created

Endpoint::headers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace seregazhuk\Favro\Api\Endpoints;
4
5
use seregazhuk\Favro\Contracts\HttpClient;
6
7
abstract class Endpoint
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $rateLimitInfo;
13
14
    /**
15
     * @var array
16
     */
17
    protected $headers = [];
18
19
    /**
20
     * @var HttpClient
21
     */
22
    protected $http;
23
24
    /**
25
     * @var string
26
     */
27
    protected $organizationId;
28
29
    /**
30
     * @param HttpClient $http
31
     */
32
    public function __construct(HttpClient $http)
33
    {
34
        $this->http = $http;
35
    }
36
37
    /**
38
     * @param string $verb
39
     * @return string
40
     */
41
    public function makeRequestUrl($verb = '')
42
    {
43
        return "https://favro.com/api/v1/{$this->endpoint()}/$verb";
44
    }
45
46
    /**
47
     * @param array $params
48
     * @return array
49
     */
50
    public function getAll(array $params = [])
51
    {
52
        return $this
53
            ->http
54
            ->get(
55
                $this->makeRequestUrl(),
56
                $params,
57
                $this->headers()
58
            );
59
    }
60
61
    /**
62
     * @param string $id
63
     * @return array
64
     */
65
    public function getById($id)
66
    {
67
        return $this
68
            ->http
69
            ->get(
70
                $this->makeRequestUrl($id),
71
                [],
72
                $this->headers()
73
            );
74
    }
75
76
    /**
77
     * @return array
78
     */
79
    protected function headers()
80
    {
81
        return array_merge(
82
            ['organizationId' => $this->organizationId],
83
            $this->headers
84
        );
85
    }
86
87
    /**
88
     * @param string $organizationId
89
     * @return $this
90
     */
91
    public function withOrganization($organizationId)
92
    {
93
        $this->organizationId = $organizationId;
94
95
        return $this;
96
    }
97
98
    /**
99
     * @return string
100
     */
101
    abstract public function endpoint();
102
}
103