|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NStack\Clients; |
|
4
|
|
|
|
|
5
|
|
|
use NStack\Exceptions\FailedToParseException; |
|
6
|
|
|
use NStack\Models\SeenUpdate; |
|
7
|
|
|
use NStack\Models\VersionControlUpdate; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class VersionControlClient |
|
11
|
|
|
* |
|
12
|
|
|
* @package NStack\Clients |
|
13
|
|
|
* @author Tiago Araujo <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class VersionControlClient extends NStackClient |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var string */ |
|
18
|
|
|
protected $path = 'notify/updates'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* versionControlIndex |
|
22
|
|
|
* |
|
23
|
|
|
* @param String $platform |
|
24
|
|
|
* @param String|null $currentVersion |
|
25
|
|
|
* @param String|null $lastVersion |
|
26
|
|
|
* @param String|null $test |
|
27
|
|
|
* @return VersionControlUpdate |
|
28
|
|
|
* @throws FailedToParseException |
|
29
|
|
|
* @author Tiago Araujo <[email protected]> |
|
30
|
|
|
*/ |
|
31
|
1 |
|
public function versionControlIndex( |
|
32
|
|
|
String $platform, |
|
33
|
|
|
String $currentVersion = null, |
|
34
|
|
|
String $lastVersion = null, |
|
35
|
|
|
String $test = null |
|
36
|
|
|
): VersionControlUpdate { |
|
37
|
1 |
|
$path = $this->buildPath($this->path) . "?platform=" . $platform; |
|
38
|
1 |
|
if ($currentVersion) { |
|
39
|
|
|
$path = $path . '¤t_version=' . $currentVersion; |
|
40
|
|
|
} |
|
41
|
1 |
|
if ($lastVersion) { |
|
42
|
|
|
$path = $path . '&last_version=' . $lastVersion; |
|
43
|
|
|
} |
|
44
|
1 |
|
if ($test) { |
|
45
|
|
|
$path = $path . '&test=' . $test; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
1 |
|
$response = $this->client->get($path); |
|
49
|
1 |
|
$contents = $response->getBody()->getContents(); |
|
50
|
1 |
|
$data = json_decode($contents, true); |
|
51
|
|
|
|
|
52
|
1 |
|
return new VersionControlUpdate($data); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* markUpdateAsSeen |
|
57
|
|
|
* |
|
58
|
|
|
* @param String $guid |
|
59
|
|
|
* @param int $updateId |
|
60
|
|
|
* @param String $answer |
|
61
|
|
|
* @param String $type |
|
62
|
|
|
* @return SeenUpdate |
|
63
|
|
|
* @throws FailedToParseException |
|
64
|
|
|
*/ |
|
65
|
1 |
|
public function markUpdateAsSeen(String $guid, int $updateId, String $answer, String $type) |
|
66
|
|
|
{ |
|
67
|
1 |
|
$response = $this->client->post($this->buildPath($this->path), [ |
|
68
|
|
|
'form_params' => [ |
|
69
|
1 |
|
'guid' => $guid, |
|
70
|
1 |
|
'update_id' => $updateId, |
|
71
|
1 |
|
'answer' => $answer, |
|
72
|
1 |
|
'type' => $type, |
|
73
|
|
|
], |
|
74
|
|
|
]); |
|
75
|
1 |
|
$contents = $response->getBody()->getContents(); |
|
76
|
1 |
|
$data = json_decode($contents, true); |
|
77
|
|
|
|
|
78
|
1 |
|
return new SeenUpdate($data['data']); |
|
79
|
|
|
} |
|
80
|
|
|
} |