PHP code example of kshabazz / battlenet-d3

1. Go to this page and download the library: Download kshabazz/battlenet-d3 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kshabazz / battlenet-d3 example snippets


use
    \Kshabazz\Slib\HttpClient,
    \Kshabazz\BattleNet\D3\Connections\Http as D3_Http,
    \Kshabazz\BattleNet\D3\Profile as D3_Profile;

// An API key and Battle.Net Tag are        . 'AAUApgkwMYkOPQlAI';

// Get an HTTP client, currently only my custom HTTP client works.
$httpClient = new HttpClient();

// Initialize a battle.net HTTP client.
$d3Client = new D3_Http( $apiKey, $battleNetTag, $httpClient );

// Get the profile for the Battle.net tag (this will be the raw JSON).
$profileJson = $d3Client->getProfile();

// Get the Hero (again, this will be the raw JSON).
$heroJson = $d3Client->getHero( $heroId );

// Get an item (and again, this will be the raw JSON).
// Get the item from Battle.net.
$itemJson = $d3Client->getItem( $itemHash );

var_dump(
    "Profile:" . $profileJson,
    "\nHero:" . $heroJson,
    "\nItem" . $itemJson
);


use \Kshabazz\BattleNet\D3\Client as D3_Client;

$apiKey       = 'apiKeyFromMashery';
$battleNetTag = 'msuBREAKER#1374';
$heroId       = 3955832;
$itemHash     = 'item/CioI4YeygAgSBwgEFcgYShEdhBF1FR2dbLMUHape7nUwDTiTA0'
              . 'AAUApgkwMYkOPQlAI';

// Using a factory method:
$d3Client = new D3_Client( $apiKey, $battleNetTag );

// Get a profile from Battle.net and return a Profile model.
$profile = $d3Client->getProfile();

// Get a hero from Battle.net and return a Hero model.
$hero = $d3Client->getHero( $heroId );

// Get an item from Battle.net and return an Item Model.
$item = $d3Client->getItem( $itemHash );

var_dump( $profile, $hero, $item );


use \Kshabazz\BattleNet\D3\Client as D3_Client;

$apiKey       = 'apiKeyFromMashery';
$battleNetTag = 'msuBREAKER#1374';
$heroId       = 3955832;
$itemHash     = 'item/CioI4YeygAgSBwgEFcgYShEdhBF1FR2dbLMUHape7nUwDTiTA0'
              . 'AAUApgkwMYkOPQlAI';

// This is mainly when you need to pull multiple profiles at a time.
$profile = D3_Client::profileFactory( $apiKey, $battleNetTag );

// When you want to grab multiple heroes, even from multiple profiles, at a time.
$hero = D3_Client::heroFactory( $apiKey, $battleNetTag, $heroId );


// Get a list of items from the Hero.
$heroItemHashes = $hero->itemsHashesBySlot();

// Get the item from Battle.net.
$itemJson = $d3Client->getItem( $heroItemHashes['mainHand'] );

// Returns an Array.
var_dump( $profile->heroes() );
var_dump( $profile->json() );