├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── src ├── Components │ ├── Endpoints │ │ ├── CosmeticsEndpoint.php │ │ ├── CreatorCodeEndpoint.php │ │ ├── NewsEndpoint.php │ │ └── ShopEndpoint.php │ ├── HttpClient.php │ ├── JsonSerializer.php │ ├── Objects │ │ ├── Cosmetic.php │ │ ├── CreatorCode.php │ │ ├── Image.php │ │ ├── News.php │ │ ├── NewsEntry.php │ │ ├── NewsMessage.php │ │ ├── Option.php │ │ ├── Reflection │ │ │ └── Activator.php │ │ ├── Shop.php │ │ ├── ShopEntry.php │ │ └── Variant.php │ └── Tasks │ │ ├── Awaitable.php │ │ ├── CosmeticArrayTask.php │ │ ├── CosmeticTask.php │ │ ├── CreatorCodeArrayTask.php │ │ ├── CreatorCodeTask.php │ │ ├── NewsEntryTask.php │ │ ├── NewsTask.php │ │ └── ShopTask.php ├── FortniteApi.php └── FortniteApiError.php └── test └── index.php /.gitignore: -------------------------------------------------------------------------------- 1 | composer.phar 2 | /vendor/ 3 | phpunit.xml 4 | composer.phar 5 | composer.lock 6 | composer-test.lock 7 | vendor/ 8 | 9 | # Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control 10 | # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file 11 | # composer.lock 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Fortnite-API.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # PHP wrapper for [Fortnite-API.com](https://fortnite-api.com) 4 | 5 | [![GitHub release (latest by date)](https://img.shields.io/github/v/release/Fortnite-API/php-wrapper?logo=github)](https://github.com/Fortnite-API/php-wrapper/releases) [![Packagist](https://img.shields.io/packagist/dt/fortnite-api/php-wrapper)](https://packagist.org/packages/fortnite-api/php-wrapper) [![GitHub issues](https://img.shields.io/github/issues/Fortnite-API/php-wrapper?logo=github)](https://github.com/Fortnite-API/php-wrapper/issues) [![MIT License](https://img.shields.io/github/license/Fortnite-API/php-wrapper)](https://github.com/Fortnite-API/php-wrapper/blob/master/LICENSE) 6 | 7 | [![PHP version](https://img.shields.io/packagist/php-v/fortnite-api/php-wrapper?logo=php)](https://www.php.net/) [![Guzzle HTTP](https://img.shields.io/badge/requires-guzzlehttp%2Fguzzle-blue)](https://github.com/guzzle/guzzle) [![Donate](https://img.shields.io/badge/donate-PayPal-blue.svg?logo=paypal)](https://fortnite-api.com/paypal) [![Discord](https://discordapp.com/api/guilds/621452110558527502/widget.png?style=shield)](https://fortnite-api.com/discord) 8 | 9 |
10 | 11 | This library offers a complete wrapper around the endpoints of [fortnite-api.com](https://fortnite-api.com). 12 | 13 | All classes and JSON objects are well documented and support autocompletion and type hints for each object and property. 14 | 15 | We also have async requests for each endpoint! 16 | 17 | ## Composer 18 | 19 | composer require fortnite-api/php-wrapper 20 | 21 | ## Documentation 22 | 23 | Here is a quick overview of the API so you can get started very quickly. 24 | 25 | If you need an in-use example then please take a look at the [index.php](https://github.com/Fortnite-API/php-wrapper/blob/master/test/index.php) in my test folder where i use some of the endpoints. 26 | 27 | - General usage 28 | 29 | ```php 30 | use FortniteApi\FortniteApi; 31 | 32 | require_once __DIR__ . '/../vendor/autoload.php'; 33 | 34 | $api = new FortniteApi(); 35 | ``` 36 | 37 | - FortniteApi class 38 | 39 | ```php 40 | $api = new FortniteApi(); 41 | 42 | // accesses the cosmetics endpoint (https://fortnite-api.com/cosmetics) 43 | $api->cosmetics->... 44 | 45 | // accesses the news endpoint (https://fortnite-api.com/news) 46 | $api->news->... 47 | 48 | // accesses the shop endpoint (https://fortnite-api.com/shop) 49 | $api->shop->... 50 | 51 | // accesses the creatorcode endpoint (https://fortnite-api.com/creatorcode) 52 | $api->creatorCode->... 53 | ``` 54 | 55 | ```php 56 | // returns the base uri of the api (https://fortnite-api.com) 57 | FortniteApi::getBaseUri(); 58 | 59 | // returns an array of all supported languages 60 | FortniteApi::getSupportedLanguages(); 61 | ``` 62 | 63 | - FortniteApiError 64 | 65 | ```php 66 | $result = $api->cosmetics->getAll(); 67 | 68 | if ($result === null) 69 | { 70 | $lastError = FortniteApiError::getLastError(); 71 | 72 | // this just shows which members you can access 73 | $members = [ 74 | $lastError->statusCode, 75 | $lastError->reasonPhrase, 76 | $lastError->body, 77 | $lastError->message 78 | ]; 79 | } 80 | ``` 81 | 82 | ```php 83 | // Returns the error set by the last request or false if none is set. 84 | FortniteApiError::getLastError(); 85 | 86 | // Determines whether an error occured within the last called function. 87 | FortniteApiError::hasLastError(); 88 | ``` 89 | 90 | - Async methods 91 | 92 | Each method in an endpoint has an equivalent async method (i.e. getAsync) which returns an awaitable task. You can await the response at any point in your script. 93 | 94 | ```php 95 | // returns "instantly" 96 | $task = $api->cosmetics->getAllAsync(); 97 | // retreives the result (the one you get from non-async versions) 98 | $result = $task->await(); 99 | ``` 100 | 101 | - Endpoints 102 | 103 | Each method in one of the endpoints return `null` on failure. 104 | Autocompletion and type hints are provided on each object. 105 | 106 | Objects are mapped with the exact same layout as on [fortnite-api.com/documentation](https://fortnite-api.com/documentation) but without their status and data properties which already get validated for you. 107 | 108 | If you need more information about properties and methods then please take a look at the actual implementation. 109 | 110 | [Endpoints](https://github.com/Fortnite-API/php-wrapper/tree/master/src/Components/Endpoints) 111 | 112 | [JSON Objects](https://github.com/Fortnite-API/php-wrapper/tree/master/src/Components/Objects) 113 | 114 | - The `query` parameter 115 | 116 | Some methods require a `$query` parameter to work. 117 | You can find possible query parameters within the [official documentation](https://fortnite-api.com/documentation). 118 | An example for such an query `array` would be: 119 | 120 | ```php 121 | // key value pairs also support arrays as value if the api allows this 122 | $query = [ 123 | "rarity" => "uncommon", 124 | "hasIcon" => true 125 | ]; 126 | ``` 127 | 128 | ### Contribute 129 | 130 | if you can provide any help, may it only be spell checking please contribute! 131 | 132 | We are open for any contribution. 133 | 134 | ## License 135 | 136 | - Fortnite-API (MIT) [License](https://github.com/Fortnite-API/php-wrapper/blob/master/LICENSE "MIT License") 137 | - guzzlehttp/guzzle (MIT) [License](https://github.com/guzzle/guzzle/blob/master/LICENSE "MIT License") 138 | 139 | API developed by [Fortnite-API.com](https://fortnite-api.com/about) 140 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fortnite-api/php-wrapper", 3 | "description": "PHP wrapper for https://fortnite-api.com", 4 | "keywords": [ 5 | "framework", 6 | "wrapper", 7 | "api", 8 | "fortnite", 9 | "fortnite-api", 10 | "client", 11 | "fortnite-api.com", 12 | "michel-pi" 13 | ], 14 | "type": "library", 15 | "license": "MIT", 16 | "authors": [ 17 | { 18 | "name": "michel-pi", 19 | "email": "mail@michel-pi.de", 20 | "homepage": "https://github.com/Fortnite-API/php-wrapper", 21 | "role": "maintainer" 22 | }, 23 | { 24 | "name": "NotOfficer", 25 | "email": "contact@fortnite-api.com", 26 | "homepage": "https://github.com/Fortnite-API/php-wrapper", 27 | "role": "owner" 28 | } 29 | ], 30 | "minimum-stability": "stable", 31 | "require": { 32 | "php": ">=7.0", 33 | "guzzlehttp/guzzle": "^6.4" 34 | }, 35 | "autoload": { 36 | "psr-4": { 37 | "FortniteApi\\": "src/" 38 | } 39 | }, 40 | "autoload-dev": { 41 | "psr-4": { 42 | "FortniteApi\\": "src/" 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Components/Endpoints/CosmeticsEndpoint.php: -------------------------------------------------------------------------------- 1 | httpClient = $httpClient; 28 | } 29 | 30 | /** 31 | * Returns the requested cosmetic. 32 | * 33 | * @param string $cosmeticId 34 | * @param null|string $language 35 | * @return null|Cosmetic 36 | */ 37 | public function get($cosmeticId, $language = null) 38 | { 39 | $promise = $this->getAsync($cosmeticId, $language); 40 | 41 | if ($promise == null) { 42 | return null; 43 | } else { 44 | return $promise->await(); 45 | } 46 | } 47 | 48 | /** 49 | * Makes an async request for the specified cosmetic. 50 | * 51 | * @param string $cosmeticId 52 | * @param null|string $language 53 | * @return null|CosmeticTask 54 | */ 55 | public function getAsync($cosmeticId, $language = null) 56 | { 57 | FortniteApiError::clearLastError(); 58 | 59 | if (empty($cosmeticId)) { 60 | FortniteApiError::setLastError("CosmeticId can't be null or empty."); 61 | 62 | return null; 63 | } 64 | 65 | $path = "/cosmetics/br/".$cosmeticId; 66 | 67 | $query = []; 68 | 69 | if (!empty($language)) { 70 | if (!in_array($language, FortniteApi::getSupportedLanguages())) { 71 | FortniteApiError::setLastError("The given language is not supported by this api."); 72 | 73 | return null; 74 | } 75 | 76 | $query["language"] = $language; 77 | } 78 | 79 | if (count($query) == 0) { 80 | $promise = $this->httpClient->getAsync($path); 81 | } else { 82 | $promise = $this->httpClient->getAsync($path, [ 83 | "query" => $query 84 | ]); 85 | } 86 | 87 | return new CosmeticTask($promise); 88 | } 89 | 90 | /** 91 | * Returns all cosmetics. 92 | * 93 | * @param null|string $language 94 | * @return null|Cosmetic[]|array 95 | */ 96 | public function getAll($language = null) 97 | { 98 | $promise = $this->getAllAsync($language); 99 | 100 | if ($promise == null) { 101 | return null; 102 | } else { 103 | return $promise->await(); 104 | } 105 | } 106 | 107 | /** 108 | * Makes an async request to retrieve all cosmetics. 109 | * 110 | * @param null|string $language 111 | * @return CosmeticArrayTask 112 | */ 113 | public function getAllAsync($language = null) 114 | { 115 | FortniteApiError::clearLastError(); 116 | 117 | $path = "/cosmetics/br"; 118 | 119 | $query = []; 120 | 121 | if (!empty($language)) { 122 | if (!in_array($language, FortniteApi::getSupportedLanguages())) { 123 | FortniteApiError::setLastError("The given language is not supported by this api."); 124 | 125 | return null; 126 | } 127 | 128 | $query["language"] = $language; 129 | } 130 | 131 | if (count($query) == 0) { 132 | $promise = $this->httpClient->getAsync($path); 133 | } else { 134 | $promise = $this->httpClient->getAsync($path, [ 135 | "query" => $query 136 | ]); 137 | } 138 | 139 | return new CosmeticArrayTask($promise); 140 | } 141 | 142 | /** 143 | * Returns the first cosmetic matching the search query 144 | * 145 | * @param array $query 146 | * @param null|string $language 147 | * @return null|Cosmetic 148 | */ 149 | public function search($query, $language = null) 150 | { 151 | $promise = $this->searchAsync($query, $language); 152 | 153 | if ($promise == null) { 154 | return null; 155 | } else { 156 | return $promise->await(); 157 | } 158 | } 159 | 160 | /** 161 | * Makes an async request for the first cosmetic matching the search query. 162 | * 163 | * @param array $query 164 | * @param null|string $language 165 | * @return null|CosmeticTask 166 | */ 167 | public function searchAsync($query, $language = null) 168 | { 169 | FortniteApiError::clearLastError(); 170 | 171 | $path = "/cosmetics/br/search"; 172 | 173 | if (!empty($language)) { 174 | if (!in_array($language, FortniteApi::getSupportedLanguages())) { 175 | FortniteApiError::setLastError("The given language is not supported by this api."); 176 | 177 | return null; 178 | } 179 | 180 | $query["language"] = $language; 181 | } 182 | 183 | $promise = $this->httpClient->getAsync($path, [ 184 | "query" => $query 185 | ]); 186 | 187 | return new CosmeticTask($promise); 188 | } 189 | 190 | /** 191 | * Returns all cosmetics matching the given search query. 192 | * 193 | * @param array $query 194 | * @param null|string $language 195 | * @return null|Cosmetic[]|array 196 | */ 197 | public function searchAll($query, $language = null) 198 | { 199 | $promise = $this->searchAllAsync($query, $language); 200 | 201 | if ($promise == null) { 202 | return null; 203 | } else { 204 | return $promise->await(); 205 | } 206 | } 207 | 208 | /** 209 | * Makes an async request to search for all cosmetics matching the given search query. 210 | * 211 | * @param array $query 212 | * @param null|string $language 213 | * @return null|CosmeticArrayTask 214 | */ 215 | public function searchAllAsync($query, $language = null) 216 | { 217 | FortniteApiError::clearLastError(); 218 | 219 | $path = "/cosmetics/br/search/all"; 220 | 221 | if (!empty($language)) { 222 | if (!in_array($language, FortniteApi::getSupportedLanguages())) { 223 | FortniteApiError::setLastError("The given language is not supported by this api."); 224 | 225 | return null; 226 | } 227 | 228 | $query["language"] = $language; 229 | } 230 | 231 | $promise = $this->httpClient->getAsync($path, [ 232 | "query" => $query 233 | ]); 234 | 235 | return new CosmeticArrayTask($promise); 236 | } 237 | 238 | /** 239 | * Returns all cosmetics matching the given id(s). 240 | * 241 | * @param string|array $ids 242 | * @param null|string $language 243 | * @return null|Cosmetic[] 244 | */ 245 | public function searchIds($ids, $language = null) 246 | { 247 | $promise = $this->searchIdsAsync($ids, $language); 248 | 249 | if ($promise == null) { 250 | return null; 251 | } else { 252 | return $promise->await(); 253 | } 254 | } 255 | 256 | /** 257 | * Makes an async request to get all cosmetics matching the given id(s). 258 | * 259 | * @param string|array $ids 260 | * @param null|string $language 261 | * @return null|CosmeticArrayTask 262 | */ 263 | public function searchIdsAsync($ids, $language = null) 264 | { 265 | FortniteApiError::clearLastError(); 266 | 267 | if (empty($ids)) { 268 | FortniteApiError::setLastError("The ids parameter is required."); 269 | 270 | return null; 271 | } 272 | 273 | if (!is_array($ids)) { 274 | $ids = array($ids); 275 | } 276 | 277 | $path = "/cosmetics/br/search/ids"; 278 | 279 | $query = []; 280 | 281 | $query["id"] = $ids; 282 | 283 | if (!empty($language)) { 284 | if (!in_array($language, FortniteApi::getSupportedLanguages())) { 285 | FortniteApiError::setLastError("The given language is not supported by this api."); 286 | 287 | return null; 288 | } 289 | 290 | $query["language"] = $language; 291 | } 292 | 293 | $promise = $this->httpClient->getAsync($path, [ 294 | "query" => $query 295 | ]); 296 | 297 | return new CosmeticArrayTask($promise); 298 | } 299 | } 300 | -------------------------------------------------------------------------------- /src/Components/Endpoints/CreatorCodeEndpoint.php: -------------------------------------------------------------------------------- 1 | httpClient = $httpClient; 26 | } 27 | 28 | /** 29 | * Returns the creator code data for a given slug. 30 | * 31 | * @param string|array|mixed $slug 32 | * @return null|CreatorCode 33 | */ 34 | public function get($slug) 35 | { 36 | $promise = $this->getAsync($slug); 37 | 38 | if ($promise == null) { 39 | return null; 40 | } else { 41 | return $promise->await(); 42 | } 43 | } 44 | 45 | /** 46 | * Returns the creator code data for a given slug. 47 | * 48 | * @param string|array|mixed $slug 49 | * @return null|CreatorCodeTask 50 | */ 51 | public function getAsync($slug) 52 | { 53 | FortniteApiError::clearLastError(); 54 | 55 | if (empty($slug)) { 56 | FortniteApiError::setLastError("Missing paramter 'slug'."); 57 | 58 | return null; 59 | } 60 | 61 | $path = "/creatorcode"; 62 | 63 | $query = [ 64 | "slug" => $slug 65 | ]; 66 | 67 | $promise = $this->httpClient->getAsync($path, [ 68 | "query" => $query 69 | ]); 70 | 71 | return new CreatorCodeTask($promise); 72 | } 73 | 74 | /** 75 | * Returns the first creator code matching the given slug. 76 | * 77 | * @param string|array|mixed $slug 78 | * @return null|CreatorCode 79 | */ 80 | public function search($slug) 81 | { 82 | $promise = $this->searchAsync($slug); 83 | 84 | if ($promise == null) { 85 | return null; 86 | } else { 87 | return $promise->await(); 88 | } 89 | } 90 | 91 | /** 92 | * Returns the first creator code matching the given slug. 93 | * 94 | * @param string|array|mixed $slug 95 | * @return null|CreatorCodeTask 96 | */ 97 | public function searchAsync($slug) 98 | { 99 | FortniteApiError::clearLastError(); 100 | 101 | if (empty($slug)) { 102 | FortniteApiError::setLastError("Missing paramter 'slug'."); 103 | 104 | return null; 105 | } 106 | 107 | $path = "/creatorcode/search"; 108 | 109 | $query = [ 110 | "slug" => $slug 111 | ]; 112 | 113 | $promise = $this->httpClient->getAsync($path, [ 114 | "query" => $query 115 | ]); 116 | 117 | return new CreatorCodeTask($promise); 118 | } 119 | 120 | /** 121 | * Returns the all creator codes matching the given slug. 122 | * 123 | * @param string|array|mixed $slug 124 | * @return null|CreatorCode[]|array|mixed 125 | */ 126 | public function searchAll($slug) 127 | { 128 | $promise = $this->searchAllAsync($slug); 129 | 130 | if ($promise == null) { 131 | return null; 132 | } else { 133 | return $promise->await(); 134 | } 135 | } 136 | 137 | /** 138 | * Returns the all creator codes matching the given slug. 139 | * 140 | * @param string|array|mixed $slug 141 | * @return null|CreatorCodeArrayTask 142 | */ 143 | public function searchAllAsync($slug) 144 | { 145 | FortniteApiError::clearLastError(); 146 | 147 | if (empty($slug)) { 148 | FortniteApiError::setLastError("Missing paramter 'slug'."); 149 | 150 | return null; 151 | } 152 | 153 | $path = "/creatorcode/search/all"; 154 | 155 | $query = [ 156 | "slug" => $slug 157 | ]; 158 | 159 | $promise = $this->httpClient->getAsync($path, [ 160 | "query" => $query 161 | ]); 162 | 163 | return new CreatorCodeArrayTask($promise); 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /src/Components/Endpoints/NewsEndpoint.php: -------------------------------------------------------------------------------- 1 | httpClient = $httpClient; 27 | } 28 | 29 | /** 30 | * Returns the data of the current battle royale, save the world and creative news. 31 | * 32 | * @param null|string $language 33 | * @return null|News 34 | */ 35 | public function get($language = null) 36 | { 37 | $promise = $this->getAsync($language); 38 | 39 | if ($promise == null) { 40 | return null; 41 | } else { 42 | return $promise->await(); 43 | } 44 | } 45 | 46 | /** 47 | * Makes an async request for the data of the current battle royale, save the world and creative news. 48 | * 49 | * @param null|string $language 50 | * @return null|NewsTask 51 | */ 52 | public function getAsync($language = null) 53 | { 54 | FortniteApiError::clearLastError(); 55 | 56 | $path = "/news"; 57 | 58 | $query = []; 59 | 60 | if (!empty($language)) { 61 | if (!in_array($language, FortniteApi::getSupportedLanguages())) { 62 | FortniteApiError::setLastError("The given language is not supported by this api."); 63 | 64 | return null; 65 | } 66 | 67 | $query["language"] = $language; 68 | } 69 | 70 | if (count($query) == 0) { 71 | $promise = $this->httpClient->getAsync($path); 72 | } else { 73 | $promise = $this->httpClient->getAsync($path, [ 74 | "query" => $query 75 | ]); 76 | } 77 | 78 | return new NewsTask($promise); 79 | } 80 | 81 | /** 82 | * Returns the current battle royale news. 83 | * 84 | * @param null|string $language 85 | * @return null|NewsEntry 86 | */ 87 | public function getBr($language = null) 88 | { 89 | $promise = $this->getBrAsync($language); 90 | 91 | if ($promise == null) { 92 | return null; 93 | } else { 94 | return $promise->await(); 95 | } 96 | } 97 | 98 | /** 99 | * Makes an async tequest for the current battle royale news. 100 | * 101 | * @param null|string $language 102 | * @return null|NewsEntry 103 | */ 104 | public function getBrAsync($language = null) 105 | { 106 | return $this->internalGetAsync("/br", $language); 107 | } 108 | 109 | /** 110 | * Returns the current save the world news. 111 | * 112 | * @param null|string $language 113 | * @return null|NewsEntry 114 | */ 115 | public function getStw($language = null) 116 | { 117 | $promise = $this->getStwAsync($language); 118 | 119 | if ($promise == null) { 120 | return null; 121 | } else { 122 | return $promise->await(); 123 | } 124 | } 125 | 126 | /** 127 | * Makes an async tequest for the current save the world news. 128 | * 129 | * @param null|string $language 130 | * @return null|NewsEntry 131 | */ 132 | public function getStwAsync($language = null) 133 | { 134 | return $this->internalGetAsync("/stw", $language); 135 | } 136 | 137 | /** 138 | * Returns the current creative news. 139 | * 140 | * @param null|string $language 141 | * @return null|NewsEntry 142 | */ 143 | public function getCreative($language = null) 144 | { 145 | $promise = $this->getCreativeAsync($language); 146 | 147 | if ($promise == null) { 148 | return null; 149 | } else { 150 | return $promise->await(); 151 | } 152 | } 153 | 154 | /** 155 | * Makes an async tequest for the current creative news. 156 | * 157 | * @param null|string $language 158 | * @return null|NewsEntry 159 | */ 160 | public function getCreativeAsync($language = null) 161 | { 162 | return $this->internalGetAsync("/creative", $language); 163 | } 164 | 165 | private function internalGetAsync($section, $language = null) 166 | { 167 | FortniteApiError::clearLastError(); 168 | 169 | $path = "/news".$section; 170 | 171 | $query = []; 172 | 173 | if (!empty($language)) { 174 | if (!in_array($language, FortniteApi::getSupportedLanguages())) { 175 | FortniteApiError::setLastError("The given language is not supported by this api."); 176 | 177 | return null; 178 | } 179 | 180 | $query["language"] = $language; 181 | } 182 | 183 | if (count($query) == 0) { 184 | $promise = $this->httpClient->getAsync($path); 185 | } else { 186 | $promise = $this->httpClient->getAsync($path, [ 187 | "query" => $query 188 | ]); 189 | } 190 | 191 | return new NewsEntryTask($promise); 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /src/Components/Endpoints/ShopEndpoint.php: -------------------------------------------------------------------------------- 1 | httpClient = $httpClient; 26 | } 27 | 28 | /** 29 | * Returns the current battle royale shop. 30 | * 31 | * @param null|string $language 32 | * @return null|Shop 33 | */ 34 | public function get($language = null) 35 | { 36 | $promise = $this->getAsync($language); 37 | 38 | if ($promise == null) { 39 | return null; 40 | } else { 41 | return $promise->await(); 42 | } 43 | } 44 | 45 | /** 46 | * Makes an async request for the current battle royale shop. 47 | * 48 | * @param null|string $language 49 | * @return null|Shop 50 | */ 51 | public function getAsync($language = null) 52 | { 53 | FortniteApiError::clearLastError(); 54 | 55 | $path = "/shop/br"; 56 | 57 | $query = []; 58 | 59 | if (!empty($language)) { 60 | if (!in_array($language, FortniteApi::getSupportedLanguages())) { 61 | FortniteApiError::setLastError("The given language is not supported by this api."); 62 | 63 | return null; 64 | } 65 | 66 | $query["language"] = $language; 67 | } 68 | 69 | if (count($query) == 0) { 70 | $promise = $this->httpClient->getAsync($path); 71 | } else { 72 | $promise = $this->httpClient->getAsync($path, [ 73 | "query" => $query 74 | ]); 75 | } 76 | 77 | return new ShopTask($promise); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/Components/HttpClient.php: -------------------------------------------------------------------------------- 1 | = 200 && $statusCode < 400; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Components/JsonSerializer.php: -------------------------------------------------------------------------------- 1 | createObjectFromBody($body); 162 | } 163 | 164 | public static function createObjectArray($body) 165 | { 166 | return self::getActivator()->createArrayFromBody($body); 167 | } 168 | 169 | /** 170 | * Undocumented function 171 | * 172 | * @param Cosmetic $obj 173 | * @param array|mixed $body 174 | * @return bool 175 | */ 176 | private static function initializeObject(&$obj, &$body) 177 | { 178 | try { 179 | $obj->id = $body["id"]; 180 | $obj->type = $body["type"]; 181 | $obj->backendType = $body["backendType"]; 182 | $obj->rarity = $body["rarity"]; 183 | $obj->backendRarity = $body["backendRarity"]; 184 | $obj->name = $body["name"]; 185 | $obj->shortDescription = $body["shortDescription"]; 186 | $obj->description = $body["description"]; 187 | $obj->set = $body["set"]; 188 | $obj->series = $body["series"]; 189 | $obj->backendSeries = $body["backendSeries"]; 190 | $obj->variants = Variant::createObjectArray($body["variants"]); 191 | $obj->gameplayTags = $body["gameplayTags"]; 192 | $obj->displayAssetPath = $body["displayAssetPath"]; 193 | $obj->definition = $body["definition"]; 194 | $obj->requiredItemId = $body["requiredItemId"]; 195 | $obj->builtInEmoteId = $body["builtInEmoteId"]; 196 | $obj->path = $body["path"]; 197 | $obj->lastUpdate = $body["lastUpdate"]; 198 | $obj->added = $body["added"]; 199 | $obj->displayRarity = $body["displayRarity"]; 200 | $obj->setText = $body["setText"]; 201 | 202 | $obj->images = []; 203 | foreach ($body["images"] as $key => $value) { 204 | $obj->images[$key] = Image::createObject($value); 205 | } 206 | 207 | return true; 208 | } catch (Exception $ex) { 209 | return false; 210 | } 211 | } 212 | 213 | /** 214 | * Undocumented function 215 | * 216 | * @return Activator 217 | */ 218 | private static function getActivator() 219 | { 220 | if (empty(self::$_activator)) { 221 | self::$_activator = new Activator(function () { 222 | return new Cosmetic(); 223 | }, function (&$obj, &$body) { 224 | return self::initializeObject($obj, $body); 225 | }); 226 | } 227 | 228 | return self::$_activator; 229 | } 230 | } 231 | -------------------------------------------------------------------------------- /src/Components/Objects/CreatorCode.php: -------------------------------------------------------------------------------- 1 | createObjectFromBody($body); 54 | } 55 | 56 | public static function createObjectArray($body) 57 | { 58 | return self::getActivator()->createArrayFromBody($body); 59 | } 60 | 61 | /** 62 | * Undocumented function 63 | * 64 | * @param CreatorCode $obj 65 | * @param array|mixed $body 66 | * @return bool 67 | */ 68 | private static function initializeObject(&$obj, &$body) 69 | { 70 | try { 71 | $obj->id = $body["id"]; 72 | $obj->slug = $body["slug"]; 73 | $obj->displayName = $body["displayName"]; 74 | $obj->status = $body["status"]; 75 | $obj->verified = $body["verified"]; 76 | 77 | return true; 78 | } catch (Exception $ex) { 79 | return false; 80 | } 81 | } 82 | 83 | /** 84 | * Undocumented function 85 | * 86 | * @return Activator 87 | */ 88 | private static function getActivator() 89 | { 90 | if (empty(self::$_activator)) { 91 | self::$_activator = new Activator(function () { 92 | return new CreatorCode(); 93 | }, function (&$obj, &$body) { 94 | return self::initializeObject($obj, $body); 95 | }); 96 | } 97 | 98 | return self::$_activator; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/Components/Objects/Image.php: -------------------------------------------------------------------------------- 1 | createObjectFromBody($body); 29 | } 30 | 31 | public static function createObjectArray($body) 32 | { 33 | return self::getActivator()->createArrayFromBody($body); 34 | } 35 | 36 | /** 37 | * Undocumented function 38 | * 39 | * @param Image $obj 40 | * @param array|mixed $body 41 | * @return bool 42 | */ 43 | private static function initializeObject(&$obj, &$body) 44 | { 45 | try { 46 | $obj->hash = $body["hash"]; 47 | $obj->url = $body["url"]; 48 | 49 | return true; 50 | } catch (Exception $ex) { 51 | return false; 52 | } 53 | } 54 | 55 | private static function getActivator() 56 | { 57 | if (empty(self::$_activator)) { 58 | self::$_activator = new Activator(function () { 59 | return new Image(); 60 | }, function (&$obj, &$body) { 61 | return self::initializeObject($obj, $body); 62 | }); 63 | } 64 | 65 | return self::$_activator; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Components/Objects/News.php: -------------------------------------------------------------------------------- 1 | createObjectFromBody($body); 41 | } 42 | 43 | public static function createObjectArray($body) 44 | { 45 | return self::getActivator()->createArrayFromBody($body); 46 | } 47 | 48 | /** 49 | * Undocumented function 50 | * 51 | * @param News $obj 52 | * @param array|mixed $body 53 | * @return bool 54 | */ 55 | private static function initializeObject(&$obj, &$body) 56 | { 57 | try { 58 | $obj->br = NewsEntry::createObject($body["br"]); 59 | $obj->stw = NewsEntry::createObject($body["stw"]); 60 | $obj->creative = NewsEntry::createObject($body["creative"]); 61 | 62 | return true; 63 | } catch (Exception $ex) { 64 | return false; 65 | } 66 | } 67 | 68 | /** 69 | * Undocumented function 70 | * 71 | * @return Activator 72 | */ 73 | private static function getActivator() 74 | { 75 | if (empty(self::$_activator)) { 76 | self::$_activator = new Activator(function () { 77 | return new News(); 78 | }, function (&$obj, &$body) { 79 | return self::initializeObject($obj, $body); 80 | }); 81 | } 82 | 83 | return self::$_activator; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Components/Objects/NewsEntry.php: -------------------------------------------------------------------------------- 1 | createObjectFromBody($body); 48 | } 49 | 50 | public static function createObjectArray($body) 51 | { 52 | return self::getActivator()->createArrayFromBody($body); 53 | } 54 | 55 | /** 56 | * Undocumented function 57 | * 58 | * @param NewsEntry $obj 59 | * @param array|mixed $body 60 | * @return bool 61 | */ 62 | private static function initializeObject(&$obj, &$body) 63 | { 64 | try { 65 | $obj->language = $body["language"]; 66 | $obj->title = $body["title"]; 67 | $obj->lastModified = $body["lastModified"]; 68 | $obj->messages = NewsMessage::createObjectArray($body["messages"]); 69 | 70 | return true; 71 | } catch (Exception $ex) { 72 | return false; 73 | } 74 | } 75 | 76 | /** 77 | * Undocumented function 78 | * 79 | * @return Activator 80 | */ 81 | private static function getActivator() 82 | { 83 | if (empty(self::$_activator)) { 84 | self::$_activator = new Activator(function () { 85 | return new NewsEntry(); 86 | }, function (&$obj, &$body) { 87 | return self::initializeObject($obj, $body); 88 | }); 89 | } 90 | 91 | return self::$_activator; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/Components/Objects/NewsMessage.php: -------------------------------------------------------------------------------- 1 | createObjectFromBody($body); 76 | } 77 | 78 | public static function createObjectArray($body) 79 | { 80 | return self::getActivator()->createArrayFromBody($body); 81 | } 82 | 83 | /** 84 | * Undocumented function 85 | * 86 | * @param NewsMessage $obj 87 | * @param array|mixed $body 88 | * @return bool 89 | */ 90 | private static function initializeObject(&$obj, &$body) 91 | { 92 | try { 93 | $obj->image = $body["image"]; 94 | $obj->hidden = $body["hidden"]; 95 | $obj->messageType = $body["messageType"]; 96 | $obj->type = $body["type"]; 97 | $obj->adspace = $body["adspace"]; 98 | $obj->title = $body["title"]; 99 | $obj->body = $body["body"]; 100 | $obj->spotlight = $body["spotlight"]; 101 | 102 | return true; 103 | } catch (Exception $ex) { 104 | return false; 105 | } 106 | } 107 | 108 | /** 109 | * Undocumented function 110 | * 111 | * @return Activator 112 | */ 113 | private static function getActivator() 114 | { 115 | if (empty(self::$_activator)) { 116 | self::$_activator = new Activator(function () { 117 | return new NewsMessage(); 118 | }, function (&$obj, &$body) { 119 | return self::initializeObject($obj, $body); 120 | }); 121 | } 122 | 123 | return self::$_activator; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/Components/Objects/Option.php: -------------------------------------------------------------------------------- 1 | createObjectFromBody($body); 33 | } 34 | 35 | public static function createObjectArray($body) 36 | { 37 | return self::getActivator()->createArrayFromBody($body); 38 | } 39 | 40 | /** 41 | * Undocumented function 42 | * 43 | * @param Option $obj 44 | * @param array|mixed $body 45 | * @return bool 46 | */ 47 | private static function initializeObject(&$obj, &$body) 48 | { 49 | try { 50 | $obj->name = $body["name"]; 51 | $obj->image = Image::createObject($body["image"]); 52 | 53 | return true; 54 | } catch (Exception $ex) { 55 | return false; 56 | } 57 | } 58 | 59 | /** 60 | * Undocumented function 61 | * 62 | * @return Activator 63 | */ 64 | private static function getActivator() 65 | { 66 | if (empty(self::$_activator)) { 67 | self::$_activator = new Activator(function () { 68 | return new Option(); 69 | }, function (&$obj, &$body) { 70 | return self::initializeObject($obj, $body); 71 | }); 72 | } 73 | 74 | return self::$_activator; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Components/Objects/Reflection/Activator.php: -------------------------------------------------------------------------------- 1 | activator = $activator; 15 | $this->initializer = $initializer; 16 | } 17 | 18 | public function createObjectFromBody($body) 19 | { 20 | if (empty($body)) { 21 | return null; 22 | } 23 | 24 | if (is_string($body)) { 25 | $body = JsonSerializer::deserialize($body); 26 | 27 | if ($body === false) { 28 | return null; 29 | } 30 | } 31 | 32 | if (array_key_exists("status", $body) && array_key_exists("data", $body)) { 33 | $body = $body["data"]; 34 | } 35 | 36 | $obj = call_user_func($this->activator); 37 | 38 | if (call_user_func_array($this->initializer, array(&$obj, &$body))) { 39 | return $obj; 40 | } else { 41 | return null; 42 | } 43 | } 44 | 45 | public function createArrayFromBody($body) 46 | { 47 | if (empty($body)) { 48 | return null; 49 | } 50 | 51 | if (is_string($body)) { 52 | $body = JsonSerializer::deserialize($body); 53 | 54 | if ($body === false) { 55 | return null; 56 | } 57 | } 58 | 59 | if (array_key_exists("status", $body) && array_key_exists("data", $body)) { 60 | $body = $body["data"]; 61 | } 62 | 63 | $result = []; 64 | 65 | foreach ($body as $item) { 66 | $obj = call_user_func($this->activator); 67 | 68 | if (call_user_func_array($this->initializer, array(&$obj, &$item))) { 69 | $result[] = $obj; 70 | } 71 | } 72 | 73 | if (count($result) == 0) { 74 | return null; 75 | } else { 76 | return $result; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/Components/Objects/Shop.php: -------------------------------------------------------------------------------- 1 | createObjectFromBody($body); 62 | } 63 | 64 | public static function createObjectArray($body) 65 | { 66 | return self::getActivator()->createArrayFromBody($body); 67 | } 68 | 69 | /** 70 | * Undocumented function 71 | * 72 | * @param Shop $obj 73 | * @param array|mixed $body 74 | * @return bool 75 | */ 76 | private static function initializeObject(&$obj, &$body) 77 | { 78 | try { 79 | $obj->hash = $body["hash"]; 80 | $obj->date = $body["date"]; 81 | $obj->featured = ShopEntry::createObjectArray($body["featured"]); 82 | $obj->daily = ShopEntry::createObjectArray($body["daily"]); 83 | $obj->votes = ShopEntry::createObjectArray($body["votes"]); 84 | $obj->voteWinners = ShopEntry::createObjectArray($body["voteWinners"]); 85 | 86 | return true; 87 | } catch (Exception $ex) { 88 | return false; 89 | } 90 | } 91 | 92 | /** 93 | * Undocumented function 94 | * 95 | * @return Activator 96 | */ 97 | private static function getActivator() 98 | { 99 | if (empty(self::$_activator)) { 100 | self::$_activator = new Activator(function () { 101 | return new Shop(); 102 | }, function (&$obj, &$body) { 103 | return self::initializeObject($obj, $body); 104 | }); 105 | } 106 | 107 | return self::$_activator; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/Components/Objects/ShopEntry.php: -------------------------------------------------------------------------------- 1 | createObjectFromBody($body); 80 | } 81 | 82 | public static function createObjectArray($body) 83 | { 84 | return self::getActivator()->createArrayFromBody($body); 85 | } 86 | 87 | /** 88 | * Undocumented function 89 | * 90 | * @param ShopEntry $obj 91 | * @param array|mixed $body 92 | * @return bool 93 | */ 94 | private static function initializeObject(&$obj, &$body) 95 | { 96 | try { 97 | $obj->regularPrice = $body["regularPrice"]; 98 | $obj->finalPrice = $body["finalPrice"]; 99 | $obj->panel = $body["panel"]; 100 | $obj->banner = $body["banner"]; 101 | $obj->items = Cosmetic::createObjectArray($body["items"]); 102 | $obj->sortPriority = $body["sortPriority"]; 103 | $obj->isBundle = $body["isBundle"]; 104 | $obj->refundable = $body["refundable"]; 105 | $obj->giftable = $body["giftable"]; 106 | 107 | return true; 108 | } catch (Exception $ex) { 109 | return false; 110 | } 111 | } 112 | 113 | /** 114 | * Undocumented function 115 | * 116 | * @return Activator 117 | */ 118 | private static function getActivator() 119 | { 120 | if (empty(self::$_activator)) { 121 | self::$_activator = new Activator(function () { 122 | return new ShopEntry(); 123 | }, function (&$obj, &$body) { 124 | return self::initializeObject($obj, $body); 125 | }); 126 | } 127 | 128 | return self::$_activator; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/Components/Objects/Variant.php: -------------------------------------------------------------------------------- 1 | createObjectFromBody($body); 33 | } 34 | 35 | public static function createObjectArray($body) 36 | { 37 | return self::getActivator()->createArrayFromBody($body); 38 | } 39 | 40 | /** 41 | * Undocumented function 42 | * 43 | * @param Variant $obj 44 | * @param array|mixed $body 45 | * @return bool 46 | */ 47 | private static function initializeObject(&$obj, &$body) 48 | { 49 | try { 50 | $obj->type = $body["type"]; 51 | $obj->options = Option::createObjectArray($body["options"]); 52 | 53 | return true; 54 | } catch (Exception $ex) { 55 | return false; 56 | } 57 | } 58 | 59 | /** 60 | * Undocumented function 61 | * 62 | * @return Activator 63 | */ 64 | private static function getActivator() 65 | { 66 | if (empty(self::$_activator)) { 67 | self::$_activator = new Activator(function () { 68 | return new Variant(); 69 | }, function (&$obj, &$body) { 70 | return self::initializeObject($obj, $body); 71 | }); 72 | } 73 | 74 | return self::$_activator; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Components/Tasks/Awaitable.php: -------------------------------------------------------------------------------- 1 | promise = $promise; 24 | } 25 | 26 | public function await() 27 | { 28 | return $this->promise->wait(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Components/Tasks/CosmeticArrayTask.php: -------------------------------------------------------------------------------- 1 | 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 Cosmetic::createObjectArray(null); 42 | } 43 | 44 | $text = (string)$body; 45 | 46 | return Cosmetic::createObjectArray($text); 47 | } catch (Exception $ex) { 48 | FortniteApiError::setLastError($ex->getMessage()); 49 | 50 | return null; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Components/Tasks/CosmeticTask.php: -------------------------------------------------------------------------------- 1 | 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 Cosmetic::createObject(null); 42 | } 43 | 44 | $text = (string)$body; 45 | 46 | return Cosmetic::createObject($text); 47 | } catch (Exception $ex) { 48 | FortniteApiError::setLastError($ex->getMessage()); 49 | 50 | return null; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Components/Tasks/CreatorCodeArrayTask.php: -------------------------------------------------------------------------------- 1 | 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 | } 54 | -------------------------------------------------------------------------------- /src/Components/Tasks/CreatorCodeTask.php: -------------------------------------------------------------------------------- 1 | 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 | } 54 | -------------------------------------------------------------------------------- /src/Components/Tasks/NewsEntryTask.php: -------------------------------------------------------------------------------- 1 | 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 NewsEntry::createObject(null); 42 | } 43 | 44 | $text = (string)$body; 45 | 46 | return NewsEntry::createObject($text); 47 | } catch (Exception $ex) { 48 | FortniteApiError::setLastError($ex->getMessage()); 49 | 50 | return null; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Components/Tasks/NewsTask.php: -------------------------------------------------------------------------------- 1 | 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 News::createObject(null); 42 | } 43 | 44 | $text = (string)$body; 45 | 46 | return News::createObject($text); 47 | } catch (Exception $ex) { 48 | FortniteApiError::setLastError($ex->getMessage()); 49 | 50 | return null; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Components/Tasks/ShopTask.php: -------------------------------------------------------------------------------- 1 | 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 Shop::createObject(null); 42 | } 43 | 44 | $text = (string)$body; 45 | 46 | return Shop::createObject($text); 47 | } catch (Exception $ex) { 48 | FortniteApiError::setLastError($ex->getMessage()); 49 | 50 | return null; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/FortniteApi.php: -------------------------------------------------------------------------------- 1 | httpClient = new Client([ 67 | "base_uri" => self::getBaseUri(), 68 | "allow_redirects" => true, 69 | "connect_timeout" => 30, 70 | "timeout" => 30, 71 | "headers" => [ 72 | "x-api-key" => $apiKey 73 | ] 74 | ]); 75 | 76 | $this->apiKey = $apiKey; 77 | 78 | $this->cosmetics = new CosmeticsEndpoint($this->httpClient); 79 | $this->shop = new ShopEndpoint($this->httpClient); 80 | $this->news = new NewsEndpoint($this->httpClient); 81 | $this->creatorCode = new CreatorCodeEndpoint($this->httpClient); 82 | } 83 | 84 | public function getApiKey() 85 | { 86 | return $this->apiKey; 87 | } 88 | 89 | /** 90 | * Returns the base uri all requests use. 91 | * 92 | * @return string 93 | */ 94 | public static function getBaseUri() 95 | { 96 | return "https://fortnite-api.com"; 97 | } 98 | 99 | /** 100 | * Returns all supported languages that can be used with this api. 101 | * 102 | * @return string[]|array 103 | */ 104 | public static function getSupportedLanguages() 105 | { 106 | return [ 107 | "ar", 108 | "de", 109 | "en", 110 | "es", 111 | "es-419", 112 | "fr", 113 | "it", 114 | "ja", 115 | "ko", 116 | "pl", 117 | "pt-BR", 118 | "ru", 119 | "tr", 120 | "zh-CN", 121 | "zh-Hant" 122 | ]; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/FortniteApiError.php: -------------------------------------------------------------------------------- 1 | message = ''; 50 | } else { 51 | $this->message = $message; 52 | } 53 | 54 | if (empty($response)) { 55 | $this->statusCode = 0; 56 | $this->reasonPhrase = ''; 57 | $this->body = ''; 58 | } else { 59 | try { 60 | $this->statusCode = $response->getStatusCode(); 61 | $this->reasonPhrase = $response->getReasonPhrase(); 62 | 63 | $this->body = (string)$response->getBody(); 64 | } catch (Exception $ex) { 65 | $this->body = $ex->getMessage(); 66 | } 67 | } 68 | } 69 | 70 | /** 71 | * Determines whether an error occured within the last called function. 72 | * 73 | * @return boolean 74 | */ 75 | public static function hasLastError() 76 | { 77 | return !empty(self::$_lastError); 78 | } 79 | 80 | /** 81 | * @internal 82 | * @ignore 83 | * 84 | * @return void 85 | */ 86 | public static function clearLastError() 87 | { 88 | self::$_lastError = null; 89 | } 90 | 91 | /** 92 | * Returns the error set by the last request or false if none is set. 93 | * 94 | * @return bool|FortniteApiError 95 | */ 96 | public static function getLastError() 97 | { 98 | if (empty(self::$_lastError)) { 99 | return false; 100 | } else { 101 | return self::$_lastError; 102 | } 103 | } 104 | 105 | /** 106 | * @internal 107 | * @ignore 108 | * 109 | * @param null|string $message 110 | * @param null|Response $response 111 | * @return void 112 | */ 113 | public static function setLastError($message = null, $response = null) 114 | { 115 | self::$_lastError = new FortniteApiError($message, $response); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /test/index.php: -------------------------------------------------------------------------------- 1 | $api->cosmetics->getAsync("bannertoken_001_cattus"), 15 | "cosmeticSearch" => $api->cosmetics->searchAsync(["rarity" => "legendary"]), 16 | "cosmeticSearchAll" => $api->cosmetics->searchAllAsync(["rarity" => "uncommon"]), 17 | "cosmetics" => $api->cosmetics->getAllAsync(), 18 | "news" => $api->news->getAsync(), 19 | "shop" => $api->shop->getAsync(), 20 | "creatorCode" => $api->creatorCode->getAsync("getonmylvl"), 21 | "creatorCodeSearch" => $api->creatorCode->searchAsync("getonmylvl"), 22 | "creatorCodeSearchAll" => $api->creatorCode->searchAllAsync("getonmylvl"), 23 | ]; 24 | 25 | $result = []; 26 | foreach ($awaitables as $key => $value) { 27 | $response = $value->await(); 28 | 29 | if (empty($response)) { 30 | $result[$key] = FortniteApiError::getLastError(); 31 | } else { 32 | $result[$key] = $response; 33 | } 34 | } 35 | 36 | echo JsonSerializer::serialize($result); 37 | --------------------------------------------------------------------------------