This repository was archived by the owner on Apr 9, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +106
-0
lines changed
Expand file tree Collapse file tree 2 files changed +106
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace FortniteApi \Components \Tasks ;
4+
5+ use Exception ;
6+ use FortniteApi \Components \HttpClient ;
7+ use FortniteApi \Components \Objects \CreatorCode ;
8+ use FortniteApi \FortniteApiError ;
9+ use Psr \Http \Message \ResponseInterface as Response ;
10+
11+ class CreatorCodeArrayTask extends Awaitable
12+ {
13+ /**
14+ * Awaits the response and returns the parsed body.
15+ *
16+ * @return null|CreatorCode[]|array
17+ */
18+ public function await ()
19+ {
20+ FortniteApiError::clearLastError ();
21+
22+ try {
23+ /** @var Response $response */
24+ $ response = parent ::await ();
25+
26+ if (empty ($ response )) {
27+ return null ;
28+ }
29+
30+ $ statusCode = $ response ->getStatusCode ();
31+
32+ if (!HttpClient::isSuccess ($ statusCode )) {
33+ FortniteApiError::setLastError ("Request failed. " , $ response );
34+
35+ return null ;
36+ }
37+
38+ $ body = $ response ->getBody ();
39+
40+ if (empty ($ body )) {
41+ return CreatorCode::createObjectArray (null );
42+ }
43+
44+ $ text = (string )$ body ;
45+
46+ return CreatorCode::createObjectArray ($ text );
47+ } catch (Exception $ ex ) {
48+ FortniteApiError::setLastError ($ ex ->getMessage ());
49+
50+ return null ;
51+ }
52+ }
53+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace FortniteApi \Components \Tasks ;
4+
5+ use Exception ;
6+ use FortniteApi \Components \HttpClient ;
7+ use FortniteApi \Components \Objects \CreatorCode ;
8+ use FortniteApi \FortniteApiError ;
9+ use Psr \Http \Message \ResponseInterface as Response ;
10+
11+ class CreatorCodeTask extends Awaitable
12+ {
13+ /**
14+ * Awaits the response and returns the parsed body.
15+ *
16+ * @return null|CreatorCode
17+ */
18+ public function await ()
19+ {
20+ FortniteApiError::clearLastError ();
21+
22+ try {
23+ /** @var Response $response */
24+ $ response = parent ::await ();
25+
26+ if (empty ($ response )) {
27+ return null ;
28+ }
29+
30+ $ statusCode = $ response ->getStatusCode ();
31+
32+ if (!HttpClient::isSuccess ($ statusCode )) {
33+ FortniteApiError::setLastError ("Request failed. " , $ response );
34+
35+ return null ;
36+ }
37+
38+ $ body = $ response ->getBody ();
39+
40+ if (empty ($ body )) {
41+ return CreatorCode::createObject (null );
42+ }
43+
44+ $ text = (string )$ body ;
45+
46+ return CreatorCode::createObject ($ text );
47+ } catch (Exception $ ex ) {
48+ FortniteApiError::setLastError ($ ex ->getMessage ());
49+
50+ return null ;
51+ }
52+ }
53+ }
You can’t perform that action at this time.
0 commit comments