コード例 #1
0
 /**
  * @param string $commandName
  * @param array  $params
  *
  * @return EmarsysResponse
  * @throws \Exception
  */
 public function executeCommand($commandName, array $params = array())
 {
     // add the headers
     $this->setHeaders($this->buildHeaders());
     $response = parent::executeCommand($commandName, $params);
     if ($response['status'] == 'success') {
         $message = $response['message']->json();
         if ($message['replyCode'] == 0) {
             return new EmarsysResponse($message['data']);
         }
     }
     throw new \Exception('Invalid request');
 }
コード例 #2
0
 /**
  * @param array $objectBucket
  * @param array $sizes
  * @param bool  $onlyCount
  *
  * @return array
  */
 public function retrieveObjectListImageUrls(array $objectBucket, array $sizes, $onlyCount = false)
 {
     $paramsArray = array();
     foreach ($objectBucket as $deviceId => $objectInfo) {
         $paramsArray['objects'][] = array('properties' => $objectInfo['properties'], 'deviceId' => $deviceId, 'prefix' => $objectInfo['prefix'], 'infix' => $objectInfo['infix'], 'sizes' => $sizes, 'onlyCount' => $onlyCount);
     }
     $result = $this->guzzleCommandClient->executeCommand('retrieveObjectListImageUrls', $paramsArray);
     if ($result['status'] == 'error') {
         return array();
     }
     if (is_object($result['message'])) {
         return $result['message']->json();
     }
     return $result['message'];
 }
コード例 #3
0
 public function testExecuteCommandWithWrongParameter()
 {
     $jsonString = '{"status":true}';
     $jsonStringArray = json_decode($jsonString, true);
     $mockHandler = new MockHandler(['status' => 200, 'headers' => array('Location' => 'asgoodasnu.test.com', 'Content-Type' => 'application/json'), 'body' => Stream::factory($jsonString)]);
     $client = new Client(['handler' => $mockHandler]);
     $json = file_get_contents(__DIR__ . "/../../Resources/config/service.json");
     $config = json_decode($json, true);
     $description = new Description($config);
     $clientMock = new GuzzleClient($client, $description);
     $guzzle = new GuzzleCommandClient($json);
     $guzzle->setClient($clientMock);
     /** @var Response $message */
     $result = $guzzle->executeCommand('getTest', array('foo' => true));
     $this->assertEquals("error", $result['status']);
     $this->assertEquals("Validation errors: [foo] must be of type string", $result['message']);
 }
コード例 #4
0
 /**
  * @param string $commandName
  * @param array  $params
  *
  * @return array
  */
 public function executeCommand($commandName, array $params = array())
 {
     $connectionParams = array('Partnerid' => $this->partnerId, 'PartnerPass' => $this->partnerPassword, 'Action' => 'new', 'UserID' => $this->userId);
     $result = parent::executeCommand($commandName, array_merge($connectionParams, $params));
     return $result;
 }
コード例 #5
0
 /**
  * Executes a guzzle command with given parameters
  *
  * @param string $commandName
  * @param array  $params
  *
  * @return string|\DOMDocument
  */
 public function executeCommand($commandName, array $params = array())
 {
     // add global request parameters
     $params['AWSAccessKeyId'] = $this->awsAccessKeyId;
     $params['SignatureMethod'] = $this->signatureMethod;
     $params['SignatureVersion'] = $this->signatureVersion;
     $params['Timestamp'] = date("Y-m-d\\TH:i:s\\Z", time());
     $operation = $this->client->getDescription()->getOperation($commandName);
     // calculate the signature
     $signatureParams = $this->getParametersForSignature($operation, $params);
     $params['Signature'] = $this->calculateSignature($signatureParams, $operation->getHttpMethod(), $this->mwsEndpoint . $operation->getUri());
     // execute the command
     $result = parent::executeCommand($commandName, $params);
     return $this->handleResult($result);
 }