forked from mcrumm/phlack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApiClient.php
More file actions
36 lines (30 loc) · 915 Bytes
/
ApiClient.php
File metadata and controls
36 lines (30 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
namespace Crummy\Phlack\Bridge\Guzzle;
use Guzzle\Common\Collection;
use Guzzle\Common\Event;
use Guzzle\Service\Client;
use Guzzle\Service\Description\ServiceDescription;
class ApiClient extends Client
{
/**
* @param array $config
*/
public function __construct($config = [])
{
$config = Collection::fromConfig($config, [], [ 'token' ]);
parent::__construct('', $config);
$description = ServiceDescription::factory(__DIR__.'/Resources/slack_api.json');
$this->setDescription($description);
$this->getEventDispatcher()->addListener('command.before_prepare', function (Event $event) use ($config) {
$event['command']['token'] = $config['token'];
});
}
/**
* @param array $config
* @return ApiClient
*/
public static function factory($config = [])
{
return new self($config);
}
}