Passed
Push — master ( 7e1a51...dce3a0 )
by Sergey
02:59
created

Endpoint::isMethodAllowed()   A

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
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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
     * @return HttpClient
48
     */
49
    public function getHttp()
50
    {
51
        return $this->http;
52
    }
53
54
    /**
55
     * @param array $params
56
     * @return array
57
     */
58
    public function getAll(array $params = [])
59
    {
60
        return $this
61
            ->getHttp()
62
            ->get(
63
                $this->makeRequestUrl(),
64
                $params,
65
                $this->getHeaders()
66
            );
67
    }
68
69
    /**
70
     * @param string $id
71
     * @return array
72
     */
73
    public function getById($id)
74
    {
75
        return $this
76
            ->getHttp()
77
            ->get(
78
                $this->makeRequestUrl($id),
79
                [],
80
                $this->getHeaders()
81
            );
82
    }
83
84
    /**
85
     * @return array
86
     */
87
    public function getHeaders()
88
    {
89
        return array_merge(
90
            ['organizationId' => $this->organizationId],
91
            $this->headers
92
        );
93
    }
94
95
    /**
96
     * @param string $organizationId
97
     * @return $this
98
     */
99
    public function setOrganizationId($organizationId)
100
    {
101
        $this->organizationId = $organizationId;
102
103
        return $this;
104
    }
105
106
    /**
107
     * @return string
108
     */
109
    abstract public function endpoint();
110
}
111