1
|
|
|
<?php |
2
|
|
|
namespace FloSports\ScaleEngine; |
3
|
|
|
|
4
|
|
|
use Exception; |
5
|
|
|
use FloSports\ScaleEngine\CommandFactory\ScaleEngineCommandFactory; |
6
|
|
|
use Guzzle\Service\Client as GuzzleService; |
7
|
|
|
use Guzzle\Service\Description\ServiceDescription; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* A Guzzle service client tailored for ScaleEngine's API. |
11
|
|
|
* |
12
|
|
|
* You can get a list of operations supported by calling |
13
|
|
|
* $scaleEngineClient->getDescription()->getOperations(); |
14
|
|
|
* or looking at the service description JSON. |
15
|
|
|
*/ |
16
|
|
|
class ScaleEngineClient extends GuzzleService |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Construct a service client for ScaleEngine's API. |
20
|
|
|
* |
21
|
|
|
* Loads the standard service description for ScaleEngine's API endpoints |
22
|
|
|
* and initializes the commands with a visitor that can properly encode |
23
|
|
|
* requests to ScaleEngine's API including request signing. |
24
|
|
|
* |
25
|
|
|
* @param array $config { |
26
|
|
|
* @var string apiSecret (required) The API secret used to sign |
27
|
|
|
* requests. |
28
|
|
|
* @var array command.params { |
29
|
|
|
* @var string apiKey The secret API key used to authenticate with |
30
|
|
|
* your ScaleEngine account. |
31
|
|
|
* @var int cdn The CDN id of your ScaleEngine account. |
32
|
|
|
* } |
33
|
|
|
* } |
34
|
|
|
*/ |
35
|
|
|
public static function factory($config = []) |
36
|
|
|
{ |
37
|
|
|
if (!array_key_exists('apiSecret', $config)) { |
38
|
|
|
throw new Exception('Missing apiSecret for ScaleEngine API.'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$client = parent::factory($config); |
42
|
|
|
|
43
|
|
|
$description = ServiceDescription::factory(__DIR__ . '/service/main.json'); |
44
|
|
|
$client->setCommandFactory( |
45
|
|
|
new ScaleEngineCommandFactory($config['apiSecret'], $description) |
46
|
|
|
); |
47
|
|
|
$client->setDescription($description); |
48
|
|
|
|
49
|
|
|
return $client; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|