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 <tiar@nodesagency.com>
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 <tiar@nodesagency.com>
30+ */
31+ public function versionControlIndex (
32+ String $ platform ,
33+ String $ currentVersion = null ,
34+ String $ lastVersion = null ,
35+ String $ test = null
36+ ): VersionControlUpdate
37+ {
38+ $ path = $ this ->buildPath ($ this ->path ) . "?platform= " . $ platform ;
39+ if ($ currentVersion ) {
40+ $ path = $ path . '¤t_version= ' . $ currentVersion ;
41+ }
42+ if ($ lastVersion ) {
43+ $ path = $ path . '&last_version= ' . $ lastVersion ;
44+ }
45+ if ($ test ) {
46+ $ path = $ path . '&test= ' . $ test ;
47+ }
48+
49+ $ response = $ this ->client ->get ($ path );
50+ $ contents = $ response ->getBody ()->getContents ();
51+ $ data = json_decode ($ contents , true );
52+ 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+ public function markUpdateAsSeen (String $ guid , int $ updateId , String $ answer , String $ type )
66+ {
67+ $ response = $ this ->client ->post ($ this ->buildPath ($ this ->path ), [
68+ 'form_params ' => [
69+ 'guid ' => $ guid ,
70+ 'update_id ' => $ updateId ,
71+ 'answer ' => $ answer ,
72+ 'type ' => $ type ,
73+ ]
74+ ]);
75+ $ contents = $ response ->getBody ()->getContents ();
76+ $ data = json_decode ($ contents , true );
77+ return new SeenUpdate ($ data ['data ' ]);
78+ }
79+
80+ }
0 commit comments