|
1 |
| -# php-wrapper |
| 1 | +<div align="center"> |
| 2 | + |
| 3 | +# PHP wrapper for [Fortnite-API.com](https://fortnite-api.com) |
| 4 | + |
| 5 | +[](https://github.com/michel-pi/fortnite-api-php-wrapper/releases) [](https://packagist.org/packages/michel-pi/fortnite-api) [](https://github.com/michel-pi/fortnite-api-php-wrapper/issues) [](https://github.com/michel-pi/fortnite-api-php-wrapper/blob/master/LICENSE) |
| 6 | + |
| 7 | +[](https://github.com/guzzle/guzzle) [](https://www.php.net/) |
| 8 | + |
| 9 | +</div> |
| 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 michel-pi/fortnite-api |
| 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/michel-pi/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 MichelPi\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 | + |
| 52 | +```php |
| 53 | +// returns the base uri of the api (https://fortnite-api.com) |
| 54 | +FortniteApi::getBaseUri(); |
| 55 | + |
| 56 | +// returns an array of all supported languages |
| 57 | +FortniteApi::getSupportedLanguages(); |
| 58 | +``` |
| 59 | + |
| 60 | +- FortniteApiError |
| 61 | + |
| 62 | +```php |
| 63 | +$result = $api->cosmetics->getAll(); |
| 64 | + |
| 65 | +if ($result === null) |
| 66 | +{ |
| 67 | + $lastError = FortniteApiError::getLastError(); |
| 68 | + |
| 69 | + // this just shows which members you can access |
| 70 | + $members = [ |
| 71 | + $lastError->statusCode, |
| 72 | + $lastError->reasonPhrase, |
| 73 | + $lastError->body, |
| 74 | + $lastError->message |
| 75 | + ]; |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +```php |
| 80 | +// Returns the error set by the last request or false if none is set. |
| 81 | +FortniteApiError::getLastError(); |
| 82 | + |
| 83 | +// Determines whether an error occured within the last called function. |
| 84 | +FortniteApiError::hasLastError(); |
| 85 | +``` |
| 86 | + |
| 87 | +- Async methods |
| 88 | + |
| 89 | +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. |
| 90 | + |
| 91 | +```php |
| 92 | +// returns "instantly" |
| 93 | +$task = $api->cosmetics->getAllAsync(); |
| 94 | +// retreives the result (the one you get from non-async versions) |
| 95 | +$result = $task->await(); |
| 96 | +``` |
| 97 | + |
| 98 | +- Endpoints |
| 99 | + |
| 100 | +Each method in one of the endpoints return `null` on failure. |
| 101 | +Autocompletion and type hints are provided on each object. |
| 102 | + |
| 103 | +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. |
| 104 | + |
| 105 | +If you need more information about properties and methods then please take a look at the actual implementation. |
| 106 | + |
| 107 | +[Endpoints](https://github.com/michel-pi/fortnite-api-php-wrapper/tree/master/src/Components/Endpoints) |
| 108 | + |
| 109 | +[JSON Objects](https://github.com/michel-pi/fortnite-api-php-wrapper/tree/master/src/Components/Objects) |
| 110 | + |
| 111 | +- The `query` parameter |
| 112 | + |
| 113 | +Some methods require a `$query` parameter to work. |
| 114 | +You can find possible query parameters within the [official documentation](https://fortnite-api.com/documentation). |
| 115 | +An example for such an query `array` would be: |
| 116 | + |
| 117 | +```php |
| 118 | +// key value pairs also support arrays as value if the api allows this |
| 119 | +$query = [ |
| 120 | + "rarity" => "uncommon", |
| 121 | + "hasIcon" => true |
| 122 | +]; |
| 123 | +``` |
| 124 | + |
| 125 | +### Contribute |
| 126 | + |
| 127 | +if you can provide any help, may it only be spell checking please contribute! |
| 128 | + |
| 129 | +I am open for any contribution. |
| 130 | + |
| 131 | +### Donate |
| 132 | + |
| 133 | +Do you like this project or use it commercially? |
| 134 | +You can help me continuing my open source projects by using one of the methods to donate (even a single dollar helps and shows that you like my project). |
| 135 | + |
| 136 | +[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YJDWMDUSM8KKQ "Donate via PayPal") |
| 137 | + |
| 138 | +``` |
| 139 | +BTC 14ES7f4GB3vD1C8Faz6ywqTcdDevxZoMyY |
| 140 | +
|
| 141 | +ETH 0xd9E2CB12d310E7BF5E72F591D7A2b8820adced04 |
| 142 | +``` |
| 143 | + |
| 144 | +## License |
| 145 | + |
| 146 | +- michel-pi/fortnite-api (MIT) [License](https://github.com/michel-pi/fortnite-api-php-wrapper/blob/master/LICENSE "MIT License") |
| 147 | +- guzzlehttp/guzzle (MIT) [License](https://github.com/guzzle/guzzle/blob/master/LICENSE "MIT License") |
| 148 | + |
| 149 | +API developed by [Fortnite-API.com](https://fortnite-api.com/about) |
0 commit comments