Skip to content

Commit 35cd3fc

Browse files
committed
InterfaceGenerator can now read the api key from a .apikey file
1 parent 284ad01 commit 35cd3fc

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/composer.lock
2+
/.apikey
23
/vendor/
34
/phpdoc/
45
/.project

lib/Zyberspace/SteamWebApi/InterfaceGenerator.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,26 @@
1717

1818
class InterfaceGenerator
1919
{
20+
static protected function _getApiKey(Event $event) {
21+
//Check if api key got passed as argument
22+
$arguments = $event->getArguments();
23+
if (isset($arguments[0])) {
24+
return $arguments[0];
25+
}
26+
27+
//Check for `.apikey` file in the working directory
28+
$composer = $event->getComposer();
29+
$apiKeyFile = realpath(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', '..', '.apikey']));
30+
if (is_readable($apiKeyFile)) {
31+
return trim(file_get_contents($apiKeyFile));
32+
}
33+
34+
//No api key found, throw Exception
35+
throw new \Exception('Please provide a valid api key. Pass it as argument or put it in the `.apikey` file.');
36+
}
2037
static public function generateAll(Event $event)
2138
{
22-
$arguments = $event->getArguments();
23-
$client = new Client($arguments[0]);
39+
$client = new Client(static::_getApiKey($event));
2440
$steamWebAPIUtil = new Interfaces\ISteamWebAPIUtil($client);
2541

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

123139
echo $this->_interfaceApiDefinition->name . PHP_EOL;
124140
}
125-
}
141+
}

0 commit comments

Comments
 (0)