Example #1
0
 /**
  * @param array $source
  *
  * @return ClientApiConfig
  *
  * @throws InvalidConfigException
  */
 public function load($source = array())
 {
     $config = new ClientApiConfig();
     try {
         $config->setKey($source['key']);
         $config->setSecret($source['secret']);
         $config->setEndpoint($source['url']);
         $config->setProjectId($source['project_id']);
     } catch (\Exception $e) {
         throw new InvalidConfigException($e->getMessage());
     }
     return $config;
 }
 /**
  * @param string $command
  * @param array  $data
  *
  * @return mixed
  *
  * @throws BlockSizeSocketException
  * @throws ClientNotInitializedException
  * @throws NullSocketResponseException
  * @throws SignatureSocketException
  * @throws SocketException
  * @throws SocketReadException
  */
 protected function callService($command, $data = array())
 {
     if (!$this->init) {
         throw new ClientNotInitializedException();
     }
     $data['auth.key'] = $this->clientApiConfig->getKey();
     $data['auth.secret'] = $this->clientApiConfig->getSecret();
     $data['command'] = $command;
     $data['project_id'] = $this->clientApiConfig->getProjectId();
     $msg = json_encode($data) . PHP_EOL;
     $this->sendMessage($msg);
     $buffer = $this->readSocket();
     if ($this->debug) {
         print $buffer;
     }
     $result = json_decode($buffer, true);
     if (!count($result)) {
         throw new NullSocketResponseException();
     }
     return $result;
 }