1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Adlogix package. |
4
|
|
|
* |
5
|
|
|
* (c) Allan Segebarth <[email protected]> |
6
|
|
|
* (c) Jean-Jacques Courtens <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Adlogix\ConfluenceClient\HttpClient; |
13
|
|
|
|
14
|
|
|
use GuzzleHttp\Client; |
15
|
|
|
use GuzzleHttp\ClientInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class HttpClient |
19
|
|
|
* @package Adlogix\ConfluenceClient\HttpClient |
20
|
|
|
* @author Cedric Michaux <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class HttpClient implements HttpClientInterface |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var ClientInterface |
27
|
|
|
*/ |
28
|
|
|
private $client; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
public function __construct( |
34
|
|
|
array $options = [], |
35
|
|
|
ClientInterface $client = null |
36
|
|
|
) { |
37
|
|
|
$this->client = $client ?: new Client($options); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
public function get($uri, array $options = []) |
44
|
|
|
{ |
45
|
|
|
return $this->apiRequest('GET', $uri, null, $options); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
|
public function apiRequest($method, $uri, $json = null, array $options = []) |
52
|
|
|
{ |
53
|
|
|
if (!empty($json)) { |
54
|
|
|
$options['body'] = $json; |
55
|
|
|
$options['headers']['content-type'] = 'application/json'; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $this->client->request($method, 'rest/api/' . $uri, $options); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public function post($uri, $json, array $options = []) |
65
|
|
|
{ |
66
|
|
|
return $this->apiRequest('POST', $uri, $json, $options); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
|
|
public function put($uri, $json, array $options = []) |
73
|
|
|
{ |
74
|
|
|
return $this->apiRequest('PUT', $uri, $json, $options); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritdoc} |
79
|
|
|
*/ |
80
|
|
|
public function delete($uri, array $options = []) |
81
|
|
|
{ |
82
|
|
|
return $this->apiRequest('DELETE', $uri, null, $options); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritdoc} |
87
|
|
|
*/ |
88
|
|
|
public function attachmentRequest($uri, array $options = []) |
89
|
|
|
{ |
90
|
|
|
return $this->client->request('GET', $uri, $options); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
|