2017 © Pedro Peláez
 

library steam

Package combining several Steam-related libraries into one wrapped and easy-to-use package.

image

bearsys/steam

Package combining several Steam-related libraries into one wrapped and easy-to-use package.

  • Sunday, February 11, 2018
  • by markfrydrych
  • Repository
  • 0 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 17 % Grown

The README.md

PHP Steam libraries

This package combines several useful PHP libraries for working with Steam IDs, Steam Web API and Steam oAuth., (*1)

Can be used standalone or as Nette framework extension., (*2)

Package currently includes these libraries: - Ehesp/Steam-Login - used for Nette login component - xPaw/SteamID - used for conversions of Steam IDs - zyberspace/php-steam-web-api-client - used for querying Steam Web API, (*3)

Installation

composer require bearsys/steam

Usage

Note that Valve limits requests to this API (if you don't have publisher's key). There should be daily limit of 100,000 requests. That is 69 requests per minute. But you could probably make all 100,000 requests at once, although it is not recommended., (*4)

Standalone

Create instance of BearSys\Steam\SteamWrapper, provide you Steam Web API user key as constructor parameter., (*5)

You can then work with this wrapper as you wish., (*6)

Example:

$apiKey = 'KEY_GOES_HERE'; // Your API key, matches regex ^[0-9A-F]{32}$
$wrapper = new BearSys\Steam\SteamWrapper($apiKey);

$user = $wrapper->getUser('hitzor'); // you could use any form of Steam ID or vanity URL
$user->getInfo(); // returns info about selected user

$game = $wrapper->getGame(730); // 730 is CS:GO's AppID
$game->getActivePlayersCount(); // returns how many players are currently playing

Nette framework

Register extension in your config and set Steam Web API key., (*7)

extensions:
    steam: BearSys\Steam\Bridges\NetteDI\SteamExtension

steam:
    apiKey: # your Steam Web API key goes here

You can request SteamWrapper after that in every class that is created using Nette DI., (*8)

Login component

Extension will register login factory. Inject it into your presenter (or any other component) and use it's setup method to set callbacks., (*9)

/** @var BearSys\Steam\Bridges\NetteApplication\SteamLoginFactory @inject */
public $loginFactory;
// you could use any suitable injection method, this is just the example

public function createComponentSteamLogin()
{
    $successCallback = function (string $steamId, bool $registered) {
        if ($registered)
            $this->redirect('this');
        else
            $this->redirect('User:signUpSteam', $steamId);
    };

    $failureCallback = function (\Exception $e) {
        // log $e
    };

    return $this->loginFactory->setup(
        function (SteamLogin $login) use ($successCallback, $failureCallback) {
            $this->steamAuthenticator->login($login, $successCallback, $failureCallback);
        }
    );
}

Then you need to handle login inside your own authenticator. You could also do that inside your callback and then just call Nette\Security\User::login() method with Nette\Security\IIdentity instance, but we recommend to don't do that., (*10)

use Ehesp\SteamLogin\SteamLogin;

class SteamAuthenticator extends AbstractAuthenticator
{
    public function login(SteamLogin $login, callable $success, callable $failure)
    {
        try {
            $steamId = $login->validate(); // if this failed, it will throw an exception

            /*
             * Your custom logic goes here.
             * 
             * You will probably want to check, if Steam ID is in database.
             * If it is, then just login associated user.
             * If it isn't, then create user and redirect him to sign-up page
             * with pre-filled username from Steam (obtainable using SteamWrapper).
             */

            $success($steamId, $registered);
        } catch (\Exception $e) {
            // Login attempt failed
            $failure($e);
        }
    }
}

At last, create link to component handle and style it however you want., (*11)

<a href="{link steamLogin-steamLogin!}">Steam login</a>

Future plans

  • Tests (ASAP)
  • Integrate koraktor/steam-condenser-php
  • Add support for Symfony, Laravel and other frameworks (pull-requests are welcomed)
  • Consider supporting Steamworks publisher's API endpoints

The Versions

11/02 2018

dev-master

9999999-dev

Package combining several Steam-related libraries into one wrapped and easy-to-use package.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marek Frydrych

nette steam