1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kwk\Geckoboard\Dataset; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Client as HttpClient; |
6
|
|
|
use GuzzleHttp\Exception\RequestException; |
7
|
|
|
use GuzzleHttp\Message\ResponseInterface; |
8
|
|
|
|
9
|
|
|
class Client |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var HttpClient |
13
|
|
|
*/ |
14
|
|
|
private $httpClient; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private $apiKey; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param HttpClient $httpClient |
23
|
|
|
* @param string $apiKey |
24
|
|
|
*/ |
25
|
|
|
public function __construct(HttpClient $httpClient, $apiKey) |
26
|
|
|
{ |
27
|
|
|
$this->httpClient = $httpClient; |
28
|
|
|
$this->apiKey = $apiKey; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Tworzenie dataSet |
33
|
|
|
* |
34
|
|
|
* @param DataSetInterface $dataSet |
35
|
|
|
* |
36
|
|
|
* @return ResponseInterface |
37
|
|
|
* @throws RequestException |
38
|
|
|
*/ |
39
|
|
|
public function create(DataSetInterface $dataSet) |
40
|
|
|
{ |
41
|
|
|
$request = (new RequestFactory($this->httpClient, $this->apiKey))->getCreateRequest($dataSet); |
42
|
|
|
|
43
|
|
|
return $this->httpClient->send($request); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Dodaje wiersz do dataset'u |
48
|
|
|
* |
49
|
|
|
* @param DataSetInterface $dataSet |
50
|
|
|
* @param DataSetRowInterface[] $dataRows |
51
|
|
|
* |
52
|
|
|
* @return ResponseInterface |
53
|
|
|
*/ |
54
|
|
|
public function append(DataSetInterface $dataSet, array $dataRows) |
55
|
|
|
{ |
56
|
|
|
$request = (new RequestFactory($this->httpClient, $this->apiKey))->getAppendRequest($dataSet->getName(), $dataRows); |
57
|
|
|
|
58
|
|
|
return $this->httpClient->send($request); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Podmienia cały dataset |
63
|
|
|
* |
64
|
|
|
* @param DataSetInterface $dataSet |
65
|
|
|
* @param DataSetRowInterface[] $dataRows |
66
|
|
|
* |
67
|
|
|
* @return ResponseInterface |
68
|
|
|
*/ |
69
|
|
|
public function replace(DataSetInterface $dataSet, array $dataRows) |
70
|
|
|
{ |
71
|
|
|
$request = (new RequestFactory($this->httpClient, $this->apiKey))->getReplaceRequest($dataSet->getName(), $dataRows); |
72
|
|
|
|
73
|
|
|
return $this->httpClient->send($request); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Usunięcie dataset'u |
78
|
|
|
* |
79
|
|
|
* @param DataSetInterface $dataSet |
80
|
|
|
* |
81
|
|
|
* @return ResponseInterface |
82
|
|
|
*/ |
83
|
|
|
public function delete(DataSetInterface $dataSet) |
84
|
|
|
{ |
85
|
|
|
$request = (new RequestFactory($this->httpClient, $this->apiKey))->getDeleteRequest($dataSet->getName()); |
86
|
|
|
|
87
|
|
|
return $this->httpClient->send($request); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|