/**
  * Constructor.
  *
  * @param string $apiKey
  * @param array  $config
  */
 public final function __construct($apiKey, array $config = [])
 {
     $this->api = new GraphCommonsApi($this);
     // check user config options
     if (isset($config['api_url'])) {
         $this->apiUrl = Util::arrayPick($config, 'api_url');
     }
     if (isset($config['api_version'])) {
         $this->apiVersion = Util::arrayPick($config, 'api_version');
     }
     // prevent typos
     $this->apiKey = trim($apiKey);
     $this->client = new Client($this, $config);
 }
 /**
  * Create a signal collection from JSON string.
  *
  * @param  string $json
  * @return GraphCommons\Graph\SignalCollection
  * @throws GraphCommons\Util\JsonException, \InvalidArgumentException
  */
 public static final function fromJson($json)
 {
     $json = new Json($json);
     if ($json->hasError()) {
         $jsonError = $json->getError();
         throw new JsonException(sprintf('JSON error: code(%d) message(%s)', $jsonError['code'], $jsonError['message']), $jsonError['code']);
     }
     $data = $json->decode(true);
     if (!isset($data['signals'])) {
         throw new \InvalidArgumentException("'signals' field is required!");
     }
     $array = array();
     foreach ($data['signals'] as $i => $signal) {
         if (!isset($signal['action'])) {
             throw new \InvalidArgumentException("Signal 'action' and 'parameters' fields are required!");
         }
         $array[$i]['action'] = Signal::detectAction(Util::arrayPick($signal, 'action'));
         foreach ($signal as $key => $value) {
             $array[$i]['parameters'][$key] = $value;
         }
     }
     return self::fromArray($array);
 }