Completed
Pull Request — master (#1)
by Spencer
02:09
created

ScaleEngineClient   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 36
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A factory() 0 16 2
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