2017 © Pedro Peláez
 

library destiny2-php

PHP wrapper for the Destiny 2 API

image

richard4339/destiny2-php

PHP wrapper for the Destiny 2 API

  • Wednesday, February 7, 2018
  • by richard4339
  • Repository
  • 1 Watchers
  • 1 Stars
  • 35 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

destiny2-php

A PHP wrapper for the Destiny 2 API, (*1)

Latest Stable Version Total Downloads Latest Unstable Version License composer.lock Build Status, (*2)

About

Currently includes (mostly) just the clan endpoints, with some user endpoints. Basic vendor support has been added as well (Xur's hash is 2190858386 FYI). The goal is to eventually have all endpoints available., (*3)

My intention is to make all object calls be JSON Serializable by implementing JsonSerializable(), (*4)

Installation

Using Composer

composer require richard4339/destiny2-php

Upgrading

To 0.3

  • ClanApproveMember() method now returns an object instead of a boolean. Any calls to this method that check for a boolean must change.
  • ClanKickMember() method now returns a boolean for success instead of the abstracted Guzzle response.

Usage

require 'vendor/autoload.php';

$client = new \Destiny\Client('[YOUR API KEY]', '[OPTIONAL OAUTH TOKEN]', '[OPTIONAL CLIENT ID]', '[OPTIONAL CLIENT SECRET]', '[OPTIONAL YOUR APP NAME]', '[OPTIONAL YOUR APP VERSION]', '[OPTIONAL YOUR APP ID]', '[OPTIONAL YOUR APP URL]', '[OPTIONAL YOUR APP EMAIL]');

$clan = $client->getGroup(12345);

try {
    $whoami = $client->getBungieUser(9999999999);
} catch (\Destiny\Exceptions\ClientException $x) {

}

$members = $client->getClanAdminsAndFounder(12345);

The optional App Name, Version, ID, URL, and Email fields were added to populate the User-Agent in the header, which is now recommended by Bungie (and may eventually be required)., (*5)

Symfony

If you want to use this in a Symfony project, the code below can be used to wire the service in services.yaml for calls that do not require OAuth:, (*6)

services:
    Destiny\Client:
        arguments:
            $apiKey: '%destiny.api_key%'
            $appName: '[YOUR APP NAME]'
            $appVersion: '[YOUR APP VERSION]'
            $appIDNumber: '[YOUR APP ID]'
            $appURL: '[YOUR APP URL]'
            $appEmail: '[YOUR EMAIL]'

Replace [YOUR APP NAME], [YOUR APP VERSION], [YOUR APP ID], [YOUR APP URL], and [YOUR EMAIL]., (*7)

It also assumes you have defined your API key defined in your services.yaml as well:, (*8)

parameters:
    destiny.client_id: '%env(DESTINY_CLIENT_ID)%'
    destiny.client_secret: '%env(DESTINY_CLIENT_SECRET)%'
    destiny.api_key: '%env(DESTINY_API_KEY)%'

For calls that require OAuth, you need to extend Client and wire your token in. The code below is just an example that works using the Security component which can get the token from the User., (*9)

<?php

namespace App\Services;


use Destiny\Client;
use Symfony\Component\Security\Core\Security;


/**
 * Class BungieOAuthRequest
 * @package App\Services
 */
class BungieOAuthRequest extends Client
{

    /**
     * BungieOAuthRequest constructor.
     * @param Security $security
     * @param string $apiKey
     * @param null|string $clientID
     * @param null|string $clientSecret
     * @param null|string $appName
     * @param null|string $appVersion
     * @param null|string $appIDNumber
     * @param null|string $appURL
     * @param null|string $appEmail
     * @throws \Destiny\Exceptions\ApiKeyException
     */
    public function __construct(Security $security, string $apiKey = '', ?string $clientID = null, ?string $clientSecret = null, ?string $appName = '', ?string $appVersion = '', ?string $appIDNumber = '', ?string $appURL = '', ?string $appEmail = '')
    {
        $user = $security->getUser();

        $token = $user->getBungieAccessToken();
        parent::__construct($apiKey, $token, $clientID, $clientSecret, $appName, $appVersion, $appIDNumber, $appURL, $appEmail);
    }
}

services.yaml wiring:, (*10)

services:
    App\Services\BungieOAuthRequest:
        arguments:
            $security: '@security.helper'
            $apiKey: '%destiny.api_key%'
            $clientID: '%destiny.client_id%'
            $clientSecret: '%destiny.client_secret%'
            $appName: '[YOUR APP NAME]'
            $appVersion: '[YOUR APP VERSION]'
            $appIDNumber: '[YOUR APP ID]'
            $appURL: '[YOUR APP URL]'
            $appEmail: '[YOUR EMAIL]'

Requirements

Destiny API Resources

If you need assistance with the Destiny API, there are a bunch of great resources maintained by a few wonderful community members! - Destiny Devs Wiki - Destiny API Wiki - Destiny 2 API - Manifest 101 - List of Projects - Destiny.Plumbing, (*11)

And specifically the devs below who build and maintain these community resources - Josh Hunt - lowlines, (*12)

The Versions

07/02 2018

dev-master

9999999-dev

PHP wrapper for the Destiny 2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

07/02 2018

dev-annotations

dev-annotations

PHP wrapper for the Destiny 2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

04/02 2018

v0.2.1

0.2.1.0

PHP wrapper for the Destiny 2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

02/02 2018

v0.2.0

0.2.0.0

PHP wrapper for the Destiny 2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

16/10 2017

v0.1.0

0.1.0.0

PHP wrapper for the Destiny 2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

15/10 2017

v0.0.3

0.0.3.0

PHP wrapper for the Destiny 2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

14/10 2017

v0.0.2

0.0.2.0

PHP wrapper for the Destiny 2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

01/10 2017

v0.0.1

0.0.1.0

PHP wrapper for the Destiny 2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

25/09 2017

dev-getClan

dev-getClan

PHP wrapper for the Destiny 2 API

  Sources   Download

MIT

The Requires

 

The Development Requires