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
|
|
|
/** @type string The expected date format ScaleEngine uses. **/ |
19
|
|
|
const SCALEENGINE_DATE_FORMAT = 'Y-m-d H:i:s'; |
20
|
|
|
|
21
|
|
|
/** @type string The full date string ScaleEngine uses for a null date. **/ |
22
|
|
|
const SCALEENGINE_NULL_DATE = '0000-00-00 00:00:00'; |
23
|
|
|
|
24
|
|
|
/** @type string The timezone ScaleEngine uses for its dates. **/ |
25
|
|
|
const SCALEENGINE_TIMEZONE = 'UTC'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Construct a service client for ScaleEngine's API. |
29
|
|
|
* |
30
|
|
|
* Loads the standard service description for ScaleEngine's API endpoints |
31
|
|
|
* and initializes the commands with a visitor that can properly encode |
32
|
|
|
* requests to ScaleEngine's API including request signing. |
33
|
|
|
* |
34
|
|
|
* @param array $config { |
35
|
|
|
* @var string apiSecret (required) The API secret used to sign |
36
|
|
|
* requests. |
37
|
|
|
* @var array command.params { |
38
|
|
|
* @var string apiKey The secret API key used to authenticate with |
39
|
|
|
* your ScaleEngine account. |
40
|
|
|
* @var int cdn The CDN id of your ScaleEngine account. |
41
|
|
|
* } |
42
|
|
|
* } |
43
|
|
|
*/ |
44
|
|
|
public static function factory($config = []) |
45
|
|
|
{ |
46
|
|
|
if (!array_key_exists('apiSecret', $config)) { |
47
|
|
|
throw new Exception('Missing apiSecret for ScaleEngine API.'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$client = parent::factory($config); |
51
|
|
|
|
52
|
|
|
$description = ServiceDescription::factory(__DIR__ . '/service/main.json'); |
53
|
|
|
$client->setCommandFactory( |
54
|
|
|
new ScaleEngineCommandFactory($config['apiSecret'], $description) |
55
|
|
|
); |
56
|
|
|
$client->setDescription($description); |
57
|
|
|
|
58
|
|
|
return $client; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|