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 NotifyClient |
11
|
|
|
* |
12
|
|
|
* @package NStack\Clients |
13
|
|
|
* @author Tiago Araujo <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class NotifyClient 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
|
|
|
{ |
38
|
1 |
|
$path = $this->buildPath($this->path) . "?platform=" . $platform; |
39
|
1 |
|
if ($currentVersion) { |
40
|
|
|
$path = $path . '¤t_version=' . $currentVersion; |
41
|
|
|
} |
42
|
1 |
|
if ($lastVersion) { |
43
|
|
|
$path = $path . '&last_version=' . $lastVersion; |
44
|
|
|
} |
45
|
1 |
|
if ($test) { |
46
|
|
|
$path = $path . '&test=' . $test; |
47
|
|
|
} |
48
|
|
|
|
49
|
1 |
|
$response = $this->client->get($path); |
50
|
1 |
|
$contents = $response->getBody()->getContents(); |
51
|
1 |
|
$data = json_decode($contents, true); |
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
|
1 |
|
return new SeenUpdate($data['data']); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
} |