|
2 | 2 | [](https://packagist.org/packages/paladinsdev/php-api) [](https://packagist.org/packages/paladinsdev/php-api) [](https://packagist.org/packages/paladinsdev/php-api) [](https://travis-ci.org/PaladinsDev/PHP-API) |
3 | 3 |
|
4 | 4 | ## About |
| 5 | + |
5 | 6 | This PHP package came from the need to have a well documented, functional package to help communicate with the Paladins developer API. This package is built using Laravel 5 components and has not been tested outside of that environment. |
6 | 7 |
|
| 8 | + |
7 | 9 | ## Installation |
| 10 | + |
8 | 11 | ```sh |
| 12 | + |
9 | 13 | $ composer require paladinsdev/php-api |
| 14 | + |
10 | 15 | ``` |
11 | 16 |
|
| 17 | + |
12 | 18 | ## Usage |
| 19 | + |
13 | 20 | There are two ways of using the class, however only 1 recommended. The singleton method is used on [Paladins Ninja](https://paladins.ninja) and handles hundreds of thousands a matches a day. |
14 | 21 |
|
| 22 | + |
15 | 23 | ### Recommended (Singleton) |
| 24 | + |
16 | 25 | ```php |
17 | | -<?php |
18 | 26 |
|
| 27 | +<?php |
19 | 28 | use PaladinsDev\PHP\PaladinsAPI; |
20 | 29 |
|
21 | | -class YourClass |
| 30 | +class YourClass |
22 | 31 | { |
23 | | - public function getSomePlayer() |
24 | | - { |
25 | | - $playerDetails = PaladinsAPI::getInstance('YourDevId', 'YourDevAuthKey')->getPlayer('SomePlayer'); |
26 | | - } |
| 32 | + public function getSomePlayer() |
| 33 | + { |
| 34 | + $playerDetails = PaladinsAPI::getInstance('YourDevId', 'YourDevAuthKey', $cacheDriver)->getPlayer('SomePlayer'); |
| 35 | + } |
27 | 36 | } |
28 | 37 | ``` |
29 | 38 |
|
30 | 39 | #### Using This Method (Laravel) |
| 40 | + |
31 | 41 | Laravel makes it very easy to use singletons using the `resolve()` helper. Open up the `app.php` file in the `bootstrap` folder at the root of your project directory and add the following piece of code. |
32 | 42 |
|
| 43 | + |
33 | 44 | ```php |
| 45 | + |
34 | 46 | $app->singleton('PaladinsAPI', function($app) { |
35 | | - return PaladinsDev\PHP\PaladinsAPI::getInstance(env('PALADINS_DEVID'), env('PALADINS_AUTHKEY')); |
| 47 | + return PaladinsDev\PHP\PaladinsAPI::getInstance(env('PALADINS_DEVID'), env('PALADINS_AUTHKEY'), $cacheDriver); |
36 | 48 | }); |
| 49 | + |
37 | 50 | ``` |
| 51 | + |
38 | 52 | This assumes you have two environment variables `PALADINS_DEVID` and `PALADINS_AUTHKEY`. You can edit this however you like. You use it by calling `resolve('PaladinsAPI')` and then use it just like a normal instance of a class. |
39 | 53 |
|
| 54 | + |
40 | 55 | ### Not Recommended |
| 56 | + |
41 | 57 | *This is not recommended as Hi-Rez / Evil Mojo only allows so many sessions a day and the more sessions you create, the quicker you'll get to reaching that limit. Caching **should** be able to handle this method...but it's still not recommended.* |
42 | 58 |
|
| 59 | + |
43 | 60 | ```php |
| 61 | + |
44 | 62 | <?php |
45 | 63 |
|
46 | 64 | use PaladinsDev\PHP\PaladinsAPI; |
47 | | - |
| 65 | + |
48 | 66 | class YourClass |
49 | 67 | { |
50 | | - private $api; |
51 | | - |
52 | | - public function __construct() |
53 | | - { |
54 | | - $this->api = new PaladinsAPI('YourDevId', 'YourDevAuthKey'); |
55 | | - } |
56 | | - |
57 | | - public function getSomePlayer() |
58 | | - { |
59 | | - $playerDetails = $this->api->getPlayer('SomePlayer'); |
60 | | - } |
| 68 | + private $api; |
| 69 | + |
| 70 | + public function __construct() |
| 71 | + { |
| 72 | + $this->api = new PaladinsAPI('YourDevId', 'YourDevAuthKey', $cacheDriver); |
| 73 | + } |
| 74 | + |
| 75 | + public function getSomePlayer() |
| 76 | + { |
| 77 | + $playerDetails = $this->api->getPlayer('SomePlayer'); |
| 78 | + } |
61 | 79 | } |
| 80 | + |
62 | 81 | ``` |
| 82 | + |
| 83 | +## Cache Driver |
| 84 | +To uncouple the Laravel/Iluminate framework from the package, we've taken a page from TeamReflex's book and integrated [Onoi Cache](https://packagist.org/packages/onoi/cache). |
| 85 | + |
| 86 | +You can pass the driver as the 3rd parameter of the constructor or `getInstance` method. |
| 87 | + |
| 88 | +### Illuminate Driver |
| 89 | +#### Install |
| 90 | +``` |
| 91 | +composer require halfpetal/illuminate-onoi-cache |
| 92 | +``` |
| 93 | + |
| 94 | +#### Usage |
| 95 | +```php |
| 96 | +use Halfpetal\Onoi\Illuminate\Cache; |
| 97 | +use lluminate\Cache\Repository; |
| 98 | + |
| 99 | +$cacheDriver = new Cache(app(Repository::class)); |
| 100 | +``` |
0 commit comments