/**
  * Adds authentication header to the request headers.
  *
  * @param \GuzzleHttp\Psr7\Request $request HTTP request object.
  * 
  * @return \GuzzleHttp\Psr7\Request
  */
 public function handleRequest($request)
 {
     $requestHeaders = HttpFormatter::formatHeaders($request->getHeaders());
     $signedKey = $this->_authenticationScheme->getAuthorizationHeader($requestHeaders, $request->getUri(), \GuzzleHttp\Psr7\parse_query($request->getUri()->getQuery()), $request->getMethod());
     return $request->withHeader(Resources::AUTHENTICATION, $signedKey);
 }
 /**
  * Creates BatchResult object.
  * 
  * @param string            $body           The HTTP response body.
  * @param array             $operations     The batch operations.
  * @param array             $contexts       The batch operations context.
  * @param IAtomReaderWriter $atomSerializer The Atom reader and writer.
  * @param IMimeReaderWriter $mimeSerializer The MIME reader and writer.
  * 
  * @return \MicrosoftAzure\Storage\Table\Models\BatchResult
  * 
  * @throws \InvalidArgumentException 
  */
 public static function create($body, $operations, $contexts, $atomSerializer, $mimeSerializer)
 {
     $result = new BatchResult();
     $responses = self::_constructResponses($body, $mimeSerializer);
     $callbackName = __CLASS__ . '::_compareUsingContentId';
     $count = count($responses);
     $entries = array();
     // Sort $responses based on Content-ID so they match order of $operations.
     uasort($responses, $callbackName);
     for ($i = 0; $i < $count; $i++) {
         $context = $contexts[$i];
         $response = $responses[$i];
         $operation = $operations[$i];
         $type = $operation->getType();
         $body = $response->body;
         $headers = HttpFormatter::formatHeaders($response->headers);
         try {
             ServiceRestProxy::throwIfError($response->statusCode, $response->reason, $response->body, $context->getStatusCodes());
             switch ($type) {
                 case BatchOperationType::INSERT_ENTITY_OPERATION:
                     $entries[] = InsertEntityResult::create($body, $headers, $atomSerializer);
                     break;
                 case BatchOperationType::UPDATE_ENTITY_OPERATION:
                 case BatchOperationType::MERGE_ENTITY_OPERATION:
                 case BatchOperationType::INSERT_REPLACE_ENTITY_OPERATION:
                 case BatchOperationType::INSERT_MERGE_ENTITY_OPERATION:
                     $entries[] = UpdateEntityResult::create($headers);
                     break;
                 case BatchOperationType::DELETE_ENTITY_OPERATION:
                     $entries[] = Resources::BATCH_ENTITY_DEL_MSG;
                     break;
                 default:
                     throw new \InvalidArgumentException();
             }
         } catch (ServiceException $e) {
             $entries[] = BatchError::create($e, $response->headers);
         }
     }
     $result->setEntries($entries);
     return $result;
 }
 /**
  * Updates the visibility timeout of a message and/or the message contents.
  * 
  * @param string              $queueName                  The queue name.
  * @param string              $messageId                  The id of the message.
  * @param string              $popReceipt                 The valid pop receipt 
  * value returned from an earlier call to the Get Messages or Update Message
  * operation.
  * @param string              $messageText                The message contents.
  * @param int                 $visibilityTimeoutInSeconds Specifies the new 
  * visibility timeout value, in seconds, relative to server time. 
  * The new value must be larger than or equal to 0, and cannot be larger 
  * than 7 days. The visibility timeout of a message cannot be set to a value 
  * later than the expiry time. A message can be updated until it has been 
  * deleted or has expired.
  * @param QueueServiceOptions $options                    The optional 
  * parameters.
  * 
  * @return MicrosoftAzure\Storage\Common\Models\UpdateMessageResult
  */
 public function updateMessage($queueName, $messageId, $popReceipt, $messageText, $visibilityTimeoutInSeconds, $options = null)
 {
     Validate::isString($queueName, 'queueName');
     Validate::notNullOrEmpty($queueName, 'queueName');
     Validate::isString($messageId, 'messageId');
     Validate::notNullOrEmpty($messageId, 'messageId');
     Validate::isString($popReceipt, 'popReceipt');
     Validate::notNullOrEmpty($popReceipt, 'popReceipt');
     Validate::isString($messageText, 'messageText');
     Validate::isInteger($visibilityTimeoutInSeconds, 'visibilityTimeoutInSeconds');
     Validate::notNull($visibilityTimeoutInSeconds, 'visibilityTimeoutInSeconds');
     $method = Resources::HTTP_PUT;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $path = $queueName . '/messages' . '/' . $messageId;
     $body = Resources::EMPTY_STRING;
     $statusCode = Resources::STATUS_NO_CONTENT;
     if (is_null($options)) {
         $options = new QueueServiceOptions();
     }
     $this->addOptionalQueryParam($queryParams, Resources::QP_VISIBILITY_TIMEOUT, $visibilityTimeoutInSeconds);
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $this->addOptionalQueryParam($queryParams, Resources::QP_POPRECEIPT, $popReceipt);
     if (!empty($messageText)) {
         $this->addOptionalHeader($headers, Resources::CONTENT_TYPE, Resources::URL_ENCODED_CONTENT_TYPE);
         $message = new QueueMessage();
         $message->setMessageText($messageText);
         $body = $message->toXml($this->dataSerializer);
     }
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode, $body);
     $responseHeaders = HttpFormatter::formatHeaders($response->getHeaders());
     $popReceipt = Utilities::tryGetValue($responseHeaders, Resources::X_MS_POPRECEIPT);
     $timeNextVisible = Utilities::tryGetValue($responseHeaders, Resources::X_MS_TIME_NEXT_VISIBLE);
     $date = Utilities::rfc1123ToDateTime($timeNextVisible);
     $result = new UpdateMessageResult();
     $result->setPopReceipt($popReceipt);
     $result->setTimeNextVisible($date);
     return $result;
 }
 /**
  * Inserts new entity to the table.
  *
  * @param string                     $table   name of the table.
  * @param Models\Entity              $entity  table entity.
  * @param Models\TableServiceOptions $options optional parameters.
  *
  * @return Models\InsertEntityResult
  *
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179433.aspx
  */
 public function insertEntity($table, $entity, $options = null)
 {
     $context = $this->_constructInsertEntityContext($table, $entity, $options);
     $response = $this->sendContext($context);
     $body = $response->getBody();
     $headers = HttpFormatter::formatHeaders($response->getHeaders());
     return InsertEntityResult::create($body, $headers, $this->_atomSerializer);
 }
 /**
  * Copies a source blob to a destination blob within the same storage account.
  * 
  * @param string                 $destinationContainer name of the destination 
  * container
  * @param string                 $destinationBlob      name of the destination 
  * blob
  * @param string                 $sourceContainer      name of the source 
  * container
  * @param string                 $sourceBlob           name of the source
  * blob
  * @param Models\CopyBlobOptions $options              optional parameters
  * 
  * @return CopyBlobResult
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd894037.aspx
  */
 public function copyBlob($destinationContainer, $destinationBlob, $sourceContainer, $sourceBlob, $options = null)
 {
     $method = Resources::HTTP_PUT;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $destinationBlobPath = $this->_createPath($destinationContainer, $destinationBlob);
     $statusCode = Resources::STATUS_ACCEPTED;
     if (is_null($options)) {
         $options = new CopyBlobOptions();
     }
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $sourceBlobPath = $this->_getCopyBlobSourceName($sourceContainer, $sourceBlob, $options);
     $headers = $this->addOptionalAccessConditionHeader($headers, $options->getAccessCondition());
     $headers = $this->addOptionalSourceAccessConditionHeader($headers, $options->getSourceAccessCondition());
     $this->addOptionalHeader($headers, Resources::X_MS_COPY_SOURCE, $sourceBlobPath);
     $headers = $this->addMetadataHeaders($headers, $options->getMetadata());
     $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $options->getLeaseId());
     $this->addOptionalHeader($headers, Resources::X_MS_SOURCE_LEASE_ID, $options->getSourceLeaseId());
     $response = $this->send($method, $headers, $queryParams, $postParams, $destinationBlobPath, $statusCode);
     return CopyBlobResult::create(HttpFormatter::formatHeaders($response->getHeaders()));
 }