Skip to content

Commit

Permalink
InterfaceGenerator can now read the api key from a .apikey file
Browse files Browse the repository at this point in the history
  • Loading branch information
zyberspace committed Oct 13, 2016
1 parent 284ad01 commit 35cd3fc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/composer.lock
/.apikey
/vendor/
/phpdoc/
/.project
22 changes: 19 additions & 3 deletions lib/Zyberspace/SteamWebApi/InterfaceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,26 @@

class InterfaceGenerator
{
static protected function _getApiKey(Event $event) {
//Check if api key got passed as argument
$arguments = $event->getArguments();
if (isset($arguments[0])) {
return $arguments[0];
}

//Check for `.apikey` file in the working directory
$composer = $event->getComposer();
$apiKeyFile = realpath(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', '..', '.apikey']));
if (is_readable($apiKeyFile)) {
return trim(file_get_contents($apiKeyFile));
}

//No api key found, throw Exception
throw new \Exception('Please provide a valid api key. Pass it as argument or put it in the `.apikey` file.');
}
static public function generateAll(Event $event)
{
$arguments = $event->getArguments();
$client = new Client($arguments[0]);
$client = new Client(static::_getApiKey($event));
$steamWebAPIUtil = new Interfaces\ISteamWebAPIUtil($client);

$interfaces = $steamWebAPIUtil->GetSupportedAPIListV1()->apilist->interfaces;
Expand Down Expand Up @@ -122,4 +138,4 @@ public function saveToFile()

echo $this->_interfaceApiDefinition->name . PHP_EOL;
}
}
}

0 comments on commit 35cd3fc

Please sign in to comment.