├── src ├── Components │ ├── HttpClient.php │ ├── Tasks │ │ ├── Awaitable.php │ │ ├── NewsTask.php │ │ ├── ShopTask.php │ │ ├── CosmeticTask.php │ │ ├── NewsEntryTask.php │ │ ├── CreatorCodeTask.php │ │ ├── CosmeticArrayTask.php │ │ └── CreatorCodeArrayTask.php │ ├── JsonSerializer.php │ ├── Objects │ │ ├── Image.php │ │ ├── Option.php │ │ ├── Variant.php │ │ ├── News.php │ │ ├── Reflection │ │ │ └── Activator.php │ │ ├── NewsEntry.php │ │ ├── CreatorCode.php │ │ ├── Shop.php │ │ ├── NewsMessage.php │ │ ├── ShopEntry.php │ │ └── Cosmetic.php │ └── Endpoints │ │ ├── ShopEndpoint.php │ │ ├── CreatorCodeEndpoint.php │ │ ├── NewsEndpoint.php │ │ └── CosmeticsEndpoint.php ├── FortniteApi.php └── FortniteApiError.php ├── .gitignore ├── composer.json ├── LICENSE ├── test └── index.php └── README.md /src/Components/HttpClient.php: -------------------------------------------------------------------------------- 1 | = 200 && $statusCode < 400; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /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/JsonSerializer.php: -------------------------------------------------------------------------------- 1 | =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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |