Coder Social home page Coder Social logo

php-api's Introduction

Paladins API (PHP)

Latest Stable Version License Total Downloads Build Status

About

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.

Installation

$ composer require paladinsdev/php-api

Usage

There are two ways of using the class, however only 1 recommended. The singleton method is used on Paladins Ninja and handles hundreds of thousands a matches a day.

Recommended (Singleton)

<?php
use PaladinsDev\PHP\PaladinsAPI;

class  YourClass
{
	public function getSomePlayer()
	{
		$playerDetails =  PaladinsAPI::getInstance('YourDevId', 'YourDevAuthKey', $cacheDriver)->getPlayer('SomePlayer');
	}
}

Using This Method (Laravel)

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.

$app->singleton('PaladinsAPI', function($app) {
	return PaladinsDev\PHP\PaladinsAPI::getInstance(env('PALADINS_DEVID'), env('PALADINS_AUTHKEY'), $cacheDriver);
});

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.

Not Recommended

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.

<?php

use PaladinsDev\PHP\PaladinsAPI;
 
class YourClass
{
	private $api;

	public function __construct()
	{
		$this->api = new PaladinsAPI('YourDevId', 'YourDevAuthKey', $cacheDriver);
	}

	public function getSomePlayer()
	{
		$playerDetails = $this->api->getPlayer('SomePlayer');
	}
}

Cache Driver

To uncouple the Laravel/Iluminate framework from the package, we've taken a page from TeamReflex's book and integrated Onoi Cache.

You can pass the driver as the 3rd parameter of the constructor or getInstance method.

Illuminate Driver

Install

composer require halfpetal/illuminate-onoi-cache

Usage

use Halfpetal\Onoi\Illuminate\Cache;
use lluminate\Cache\Repository;

$cacheDriver = new Cache(app(Repository::class));

php-api's People

Contributors

matthewsh avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.