Completed
Push — master ( 1e77f8...b679e8 )
by Sergey
04:00 queued 01:42
created

Endpoint::putResource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace seregazhuk\HeadHunterApi\EndPoints;
4
5
use seregazhuk\HeadHunterApi\Request;
6
7
abstract class Endpoint
8
{
9
    const RESOURCE = '/resource';
10
11
    /**
12
     * @var EndpointsContainer
13
     */
14
    protected $container;
15
16
    /**
17
     * @var Request
18
     */
19
    protected $request;
20
21
    /**
22
     * @param EndpointsContainer $container
23
     */
24
    public function __construct(EndpointsContainer $container)
25
    {
26
        $this->container = $container;
27
        $this->request = $this->container->getRequest();
28
    }
29
30
    /**
31
     * @param string $verb
32
     * @param array $params
33
     * @return array
34
     */
35
    protected function getResource($verb = '', array $params = [])
36
    {
37
        return $this->request->get(
38
            $this->getResourceUri($verb), $params
39
        );
40
    }
41
42
    /**
43
     * @param string $verb
44
     * @param array $params
45
     * @return mixed
46
     */
47
    protected function postResource($verb = '', array $params = [])
48
    {
49
        return $this->request->post(
50
            $this->getResourceUri($verb), $params
51
        );
52
    }
53
54
    /**
55
     * @param string $verb
56
     * @param array $params
57
     * @return mixed
58
     */
59
    protected function postResourceJson($verb = '', array $params = [])
60
    {
61
        return $this->request->postJson(
62
            $this->getResourceUri($verb), $params
63
        );
64
    }
65
66
    protected function postResourceFile($verb, array $params = [])
67
    {
68
        return $this->request->postFile(
69
            $this->getResourceUri($verb), $params
70
        );
71
    }
72
73
74
    /**
75
     * @param string $verb
76
     * @param array $params
77
     * @return mixed
78
     */
79
    protected function putResource($verb = '', array $params = [])
80
    {
81
        return $this->request->put(
82
            $this->getResourceUri($verb), $params
83
        );
84
    }
85
86
    /**
87
     * @param string $verb
88
     * @param array $params
89
     * @return mixed
90
     */
91
    protected function putResourceJson($verb = '', array $params = [])
92
    {
93
        return $this->request->putJson(
94
            $this->getResourceUri($verb), $params
95
        );
96
    }
97
98
    /**
99
     * @param string $verb
100
     */
101
    protected function deleteResource($verb = '')
102
    {
103
        $this->request->delete($this->getResourceUri($verb));
104
    }
105
106
    /**
107
     * @param string $uri
108
     * @return string
109
     */
110
    protected function getResourceUri($uri = '')
111
    {
112
        $resource = static::RESOURCE;
113
114
        return empty($uri) ? $resource : $resource . sprintf('/%s', $uri);
115
    }
116
}