## Getting Started
### Minimal Setup
1. **Installation**:
```bash
composer require ajardin/blizzard-sdk-bundle
For Symfony Flex, this auto-registers the bundle. For manual setup, add to config/bundles.php:
Ajardin\BlizzardSdkBundle\AjardinBlizzardSdkBundle::class => ['all' => true],
Configure Credentials:
Add to .env:
BLIZZARD_CLIENT_ID=your_client_id
BLIZZARD_SECRET=your_client_secret
Then configure in config/packages/ajardin_blizzard_sdk.yaml:
ajardin_blizzard_sdk:
blizzard:
client_id: '%env(BLIZZARD_CLIENT_ID)%'
client_secret: '%env(BLIZZARD_SECRET)%'
First Use Case:
Fetch WoW realms for a region (e.g., us):
use Ajardin\BlizzardSdkBundle\BlizzardApi\WorldOfWarcraft\RealmApi;
class RealmService {
public function __construct(private RealmApi $realmApi) {}
public function getRealms(): array {
$response = $this->realmApi->realmIndex('us');
return $response->toArray()['realms'] ?? [];
}
}
AchievementApi, CharacterProfileApi).
use Ajardin\BlizzardSdkBundle\BlizzardApi\WorldOfWarcraft\AchievementApi;
class AchievementService {
public function __construct(private AchievementApi $achievementApi) {}
}
HttpClient responses asynchronously:
$response = $this->itemApi->itemIndex('us', 'en_US');
// Process other logic while the request completes in the background.
$data = $response->toArray(); // Fetch data when ready.
us, eu, kr, tw) to all methods:
$this->realmApi->realmIndex('eu'); // Europe
$response->toArray()JsonSerializable wrappers).$this->itemApi->itemIndex('us', 'en_US', 12345); // Item ID
$this->characterProfileApi->characterProfile('us', 'Area52', 'DeathKnight');
limit and offset parameters where supported (e.g., realmIndex).Rate Limits:
$cacheKey = 'blizzard_realms_us';
if (!$cached = $cache->get($cacheKey)) {
$cached = $this->realmApi->realmIndex('us')->toArray();
$cache->set($cacheKey, $cached, 3600); // Cache for 1 hour
}
CacheInterface or Psr\Cache\CacheItemPoolInterface.Region Support:
us, eu, kr, and tw are supported. Avoid hardcoding unsupported regions (e.g., cn).Missing Endpoints:
HttpClient:
$client = $this->container->get('http_client');
$response = $client->request('GET', 'https://api.battle.net/...');
Authentication:
.env files. Use Symfony’s ParameterBag for sensitive data in tests:
# config/packages/test/ajardin_blizzard_sdk.yaml
ajardin_blizzard_sdk:
blizzard:
client_id: '%env(resolve:BLIZZARD_CLIENT_ID)%'
client_secret: '%env(resolve:BLIZZARD_SECRET)%'
Response Errors:
if ($response->getStatusCode() === 401) {
throw new \RuntimeException('Invalid credentials');
}
file_put_contents(
'debug_blizzard.json',
$response->getContent(false)
);
Deprecation Warnings:
Custom API Endpoints:
use Ajardin\BlizzardSdkBundle\BlizzardApi\AbstractApi;
class CustomApi extends AbstractApi {
public function customEndpoint(string $region, string $locale) {
return $this->client->request('GET', $this->buildUrl($region, '/custom', $locale));
}
}
services.yaml:
services:
App\Service\CustomApi:
arguments:
$client: '@ajardin_blizzard_sdk.http_client'
Response Transformers:
use Ajardin\BlizzardSdkBundle\BlizzardApi\WorldOfWarcraft\RealmApiInterface;
class RealmApiDecorator implements RealmApiInterface {
public function __construct(private RealmApiInterface $decorated) {}
public function realmIndex(string $region): ResponseInterface {
$response = $this->decorated->realmIndex($region);
return new DecoratedResponse($response); // Custom logic
}
}
Testing:
HttpClient in tests:
$mockResponse = new MockResponse(json_encode(['realms' => []]));
$this->httpClient->__call('request', ['GET', '...'], $mockResponse);
Batch Requests:
HttpClient's stream() for parallel requests:
$promises = [];
foreach ($realms as $realm) {
$promises[] = $this->characterProfileApi->characterProfile('us', $realm, 'Paladin');
}
$results = yield from $this->httpClient->stream($promises);
Locale Handling:
locale (e.g., 'en_US', 'ko_KR') to avoid API defaults.Environment-Specific Config:
config/packages/dev/ajardin_blizzard_sdk.yaml):
ajardin_blizzard_sdk:
blizzard:
debug: true # Enable debug mode
---
How can I help you explore Laravel packages today?