A lightweight PHP client for the Smite developer API.
To install, run composer require dant89/smite-api-php-client
in the root of your project or add dant89/smite-api-php-client
to your composer.json.
"require": {
"dant89/smite-api-php-client": REPLACE_WITH_VERSION
}
To read more about how the Smite developer API functions, please read the official documentation.
The Smite developer API requires that you first complete this form to apply for credentials.
If your application is accepted you will receive custom credentials to access the API.
- Smite
Use your provided DevId
and AuthKey
upon instantiation of this client.
use Dant89\SmiteApiClient\Client;
// Create base client
$smiteClient = new Client(SMITE_DEV_ID, SMITE_AUTH_KEY);
To begin using the API, you will first need to establish a valid Session. To do so you will start a session (via the createsession method) and receive a SessionId. Sessions are used for authentication, security, monitoring, and throttling. Once you obtain a SessionId, you will pass it to other methods for authentication. Each session only lasts for 15 minutes and must be recreated afterward.
- Smite
// Get a session_id from a signed authentication request
$authClient = $smiteClient->getHttpClient('auth');
$timestamp = date('omdHis');
$response = $authClient->createSession($timestamp);
// Check for valid response status
if ($response->getStatus() === 200) {
$sessionId = $response->getContent()['session_id'];
}
Now that you have a $sessionId
you are free to make calls to the other client methods. This client takes care of signing the requests so you don't need to worry about that and can now make calls to other methods, for example to get a teams (clans) players, you would use:
$clanId = 123;
$teamClient = $smiteClient->getHttpClient('team');
$response = $teamClient->getTeamPlayers($clanId, $sessionId, $timestamp);
$teamPlayers = [];
if ($response->getStatus() === 200) {
$teamPlayers = $response->getContent();
}
I recommend that you implement some sort of caching of your $sessionId
and / or returned data, the Smite developer API has rate limits so caching will help you avoid going over those limits:
Default limits:
concurrent_sessions: 50
sessions_per_day: 500
session_time_limit: 15 minutes
request_day_limit: 7500
languageCode
values:
1
English2
German3
French5
Chinese7
Spanish9
Spanish (Latin America)10
Portuguese11
Russian12
Polish13
Turkish
You can test your API key by running the PHPUnit tests included in this client.
At present there is no rate limiting or caching so a run through will use 7 of your daily sessions (this is not ideal).
PHPUnit tests:
- Add your
devId
andauthKey
totests/Helper/ClientTestCase.php
php vendor/phpunit/phpunit/phpunit tests
PHP CodeSniffer:
php vendor/squizlabs/php_codesniffer/bin/phpcs src --standard=PSR2 --severity=5 --extensions=php
PHP MessDetector
php vendor/phpmd/phpmd/src/bin/phpmd src text controversial,unusedcode,design
Contributions to the client are welcome, to contribute please:
- Fork this repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new pull request