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
|
|
|
*/ |
89
|
|
|
protected function deleteResource($verb = '') |
90
|
|
|
{ |
91
|
|
|
$this->request->delete($this->getResourceUri($verb)); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $uri |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
protected function getResourceUri($uri = '') |
99
|
|
|
{ |
100
|
|
|
$resource = static::RESOURCE; |
101
|
|
|
|
102
|
|
|
return empty($uri) ? $resource : $resource . sprintf('/%s', $uri); |
103
|
|
|
} |
104
|
|
|
} |