/** * @param Doctrine\Common\Collections\Collection $products * @param AntiMattr\Twitter\Marketplace\Model\Merchant $merchant * @param int $attempt * * @throws AntiMattr\Twitter\Marketplace\Exception\AbstractAuthException * @throws AntiMattr\Twitter\Marketplace\Exception\ConnectionException * @throws AntiMattr\Twitter\Marketplace\Exception\Http\BadRequestException * @throws AntiMattr\Twitter\Marketplace\Exception\Http\InternalErrorException * @throws AntiMattr\Twitter\Marketplace\Exception\Http\NotFoundException * @throws AntiMattr\Twitter\Marketplace\Exception\Http\UnauthorizedException * @throws AntiMattr\Twitter\Marketplace\Exception\IntegrationException */ public function updateProducts(Collection $products, Merchant $merchant, $attempt = 1) { $this->checkMerchantCredentials($merchant); $oAuth = $merchant->getOAuth(); $consumerKey = $oAuth->getConsumerKey(); $consumerSecret = $oAuth->getConsumerSecret(); $oAuthToken = $oAuth->getOAuthToken(); $oAuthTokenSecret = $oAuth->getOAuthTokenSecret(); $this->checkAccountId($merchant); $resource = sprintf("/1.1/commerce/accounts/%s/item_urls/", $merchant->getAccountId()); $request = $this->messageFactory->createFormRequest('PUT', $resource, $this->host); $response = $this->messageFactory->createResponse(); $urls = array(); foreach ($products as $product) { $urls[] = $product->getMeta()->offsetGet('url'); } if (empty($urls) || count($urls) > 5) { $message = 'Update Products require at least 1 and a most 5 urls'; throw new IntegrationException($message); } $urls = implode(",", $urls); $request->setField('urls', $urls); $this->requestSigner->bind($oAuth, $request); $this->log($request); try { $this->buzz->send($request, $response); $this->log($response); $responseHandler = $this->responseHandlerFactory->createResponseHandler('products'); $responseHandler->bind($response, $products); } catch (InternalErrorException $e) { if ($attempt >= $this->maxRetries) { throw new ConnectionException($e->getMessage()); } $nextAttempt = $attempt + 1; $this->log("Attempt " . $nextAttempt); usleep($this->retryDelay * $attempt); $this->updateProducts($products, $merchant, $nextAttempt); } }