Skip to content
This repository was archived by the owner on Apr 9, 2024. It is now read-only.

Commit f311de4

Browse files
committed
added new CreatorCodeEndpoint
1 parent b69e179 commit f311de4

File tree

1 file changed

+152
-0
lines changed

1 file changed

+152
-0
lines changed
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
<?php
2+
3+
namespace FortniteApi\Components\Endpoints;
4+
5+
use FortniteApi\Components\HttpClient;
6+
use FortniteApi\Components\Tasks\CreatorCodeArrayTask;
7+
use FortniteApi\Components\Tasks\CreatorCodeTask;
8+
use FortniteApi\FortniteApiError;
9+
10+
/**
11+
* Provides access to the /creatorcode endpoint.
12+
*/
13+
class CreatorCodeEndpoint
14+
{
15+
/**
16+
* Returns the creator code data for a given slug.
17+
*
18+
* @param string|array|mixed $slug
19+
* @return null|CreatorCode
20+
*/
21+
public function get($slug)
22+
{
23+
$promise = $this->getAsync($slug);
24+
25+
if ($promise == null) {
26+
return null;
27+
} else {
28+
return $promise->await();
29+
}
30+
}
31+
32+
/**
33+
* Returns the creator code data for a given slug.
34+
*
35+
* @param string|array|mixed $slug
36+
* @return null|CreatorCodeTask
37+
*/
38+
public function getAsync($slug)
39+
{
40+
FortniteApiError::clearLastError();
41+
42+
if (empty($slug)) {
43+
FortniteApiError::setLastError("Missing paramter 'slug'.");
44+
45+
return null;
46+
}
47+
48+
$path = "/creatorcode";
49+
50+
$query = [
51+
"slug" => $slug
52+
];
53+
54+
$promise = HttpClient::getInstance()->getAsync($path, [
55+
"query" => $query
56+
]);
57+
58+
return new CreatorCodeTask($promise);
59+
}
60+
61+
/**
62+
* Returns the first creator code matching the given slug.
63+
*
64+
* @param string|array|mixed $slug
65+
* @return null|CreatorCode
66+
*/
67+
public function search($slug)
68+
{
69+
$promise = $this->searchAsync($slug);
70+
71+
if ($promise == null) {
72+
return null;
73+
} else {
74+
return $promise->await();
75+
}
76+
}
77+
78+
/**
79+
* Returns the first creator code matching the given slug.
80+
*
81+
* @param string|array|mixed $slug
82+
* @return null|CreatorCodeTask
83+
*/
84+
public function searchAsync($slug)
85+
{
86+
FortniteApiError::clearLastError();
87+
88+
if (empty($slug)) {
89+
FortniteApiError::setLastError("Missing paramter 'slug'.");
90+
91+
return null;
92+
}
93+
94+
$path = "/creatorcode/search";
95+
96+
$query = [
97+
"slug" => $slug
98+
];
99+
100+
$promise = HttpClient::getInstance()->getAsync($path, [
101+
"query" => $query
102+
]);
103+
104+
return new CreatorCodeTask($promise);
105+
}
106+
107+
/**
108+
* Returns the all creator codes matching the given slug.
109+
*
110+
* @param string|array|mixed $slug
111+
* @return null|CreatorCode[]|array|mixed
112+
*/
113+
public function searchAll($slug)
114+
{
115+
$promise = $this->searchAllAsync($slug);
116+
117+
if ($promise == null) {
118+
return null;
119+
} else {
120+
return $promise->await();
121+
}
122+
}
123+
124+
/**
125+
* Returns the all creator codes matching the given slug.
126+
*
127+
* @param string|array|mixed $slug
128+
* @return null|CreatorCodeArrayTask
129+
*/
130+
public function searchAllAsync($slug)
131+
{
132+
FortniteApiError::clearLastError();
133+
134+
if (empty($slug)) {
135+
FortniteApiError::setLastError("Missing paramter 'slug'.");
136+
137+
return null;
138+
}
139+
140+
$path = "/creatorcode/search/all";
141+
142+
$query = [
143+
"slug" => $slug
144+
];
145+
146+
$promise = HttpClient::getInstance()->getAsync($path, [
147+
"query" => $query
148+
]);
149+
150+
return new CreatorCodeArrayTask($promise);
151+
}
152+
}

0 commit comments

Comments
 (0)