Skip to content

Latest commit

 

History

History
50 lines (40 loc) · 1.1 KB

example.md

File metadata and controls

50 lines (40 loc) · 1.1 KB

Example

Let's say we want the list of World of Warcraft realms for a specific region.

1️⃣ Inject the RealmApi service in one of your classes

use Ajardin\BlizzardSdkBundle\BlizzardApi\WorldOfWarcraft\RealmApi;

class RealmLoader
{
    public function __construct(private RealmApi $realmApi)
    {
    }
}

2️⃣ Trigger the HTTP request to the Blizzard API

use Ajardin\BlizzardSdkBundle\BlizzardApi\WorldOfWarcraft\RealmApi;

class RealmLoader
{
    // ...

    public function getRealms(string $region): array
    {
        $response = $this->realmApi->realmIndex($region);
        // The HTTP request is sent asynchronously,
        // you can send other requests or retrieve the response content immediately.
    }
}

3️⃣ Consume the response when you need it

use Ajardin\BlizzardSdkBundle\BlizzardApi\WorldOfWarcraft\RealmApi;

class RealmLoader
{
    // ...

    public function getRealms(string $region): array
    {
        $response = $this->realmApi->realmIndex($region);
        $content = $response->toArray();

        return $content['realms'] ?? [];
    }
}