/**
  * @param  string $binaryImage
  * @param  string $filename
  * @param  int    $expire
  *
  * @return Response
  */
 public function call($binaryImage, $filename, $expire)
 {
     $response = new Response();
     $image = new FormUpload();
     $image->setFilename($filename);
     $image->setContent($binaryImage);
     $request = $this->buildRequest($image, $expire);
     $this->client->setOption(CURLOPT_TIMEOUT, 10000);
     $this->client->send($request, $response);
     return $this->processResponse($response);
 }
Esempio n. 2
0
 /**
  * Performs an "Had" action on facebook app
  *
  * <code>
  * curl
  *  -F 'access_token=xxxxxxxxxxxxxxxx'
  *  -F 'cocktail=http://just-had-a-cocktail.pagodabox.com/cocktail/yyyyyyy'
  * 'https://graph.facebook.com/me/lmammino-jhac:had'
  * </code>
  *
  * @param $cocktailUrl
  */
 public function hadCocktail($cocktailUrl, $timestamp = NULL)
 {
     $request = new FormRequest(Request::METHOD_POST, 'me/lmammino-jhac:had', self::$GRAPH_HOST);
     $request->setField('access_token', $this->accessToken);
     $request->setField('cocktail', $cocktailUrl);
     if ($timestamp) {
         $date = date('c', $timestamp);
         $request->setField('start_time', $date);
         $request->setField('end_time', $date);
     }
     $response = new Response();
     $this->buzz->send($request, $response);
     return json_decode($response->getContent());
 }
Esempio n. 3
0
 /**
  * Send the request
  */
 public function send()
 {
     // prepare client
     $curl = new Curl();
     $curl->send($this->request, $this->response);
     $this->sent = true;
 }
Esempio n. 4
0
 /**
  * @param  Doctrine\Common\Collections\Collection                   $collection
  * @throws AntiMattr\Sears\Exception\Connection\ConnectionException
  * @throws AntiMattr\Sears\Exception\Http\BadRequestException
  * @throws AntiMattr\Sears\Exception\IntegrationException
  */
 public function updateShipments(Collection $collection)
 {
     $handler = $this->requestHandlerFactory->createRequestHandler('updateShipments');
     $resource = sprintf('/SellerPortal/api/oms/asn/v5?email=%s&password=%s', $this->email, $this->password);
     $request = $this->messageFactory->createRequest('PUT', $resource, $this->host);
     $integrationException = null;
     try {
         $handler->bindCollection($request, $collection);
     } catch (IntegrationException $e) {
         $integrationException = $e;
     }
     $this->updateHeaders($request);
     $requestString = $request->__toString();
     $this->log($requestString);
     $response = $this->messageFactory->createResponse();
     try {
         $this->buzz->send($request, $response);
     } catch (ClientException $e) {
         $subject = $e->getMessage();
         throw new ConnectionException($subject);
     }
     $responseString = $response->__toString();
     $this->log($responseString);
     if ($integrationException) {
         throw $integrationException;
     }
 }
Esempio n. 5
0
 public function send(RequestInterface $request, MessageInterface $response, array $options = array())
 {
     try {
         parent::send($request, $response, $options);
     } catch (RuntimeException $e) {
         // Catch but do not do anything as we consider the request to be ~ asynchronous
         if (isset($this->logger)) {
             $this->logger->notice("An issue occurred while handling HttpCache purge: {$e->getMessage()}.");
         }
     }
 }
 /**
  * Tells if the data looks like spam
  *
  * @param array $data
  * @return boolean
  */
 public function isSpam(array $data)
 {
     $data['blog'] = $this->blogUrl;
     $request = new Message\Request('POST', '/1.1/comment-check', $this->getHost());
     $request->setContent(http_build_query($data));
     $request->addHeader('Content-Type: application/x-www-form-urlencoded');
     $request->addHeader(sprintf('Content-Length: %d', strlen($request->getContent())));
     $response = new Message\Response();
     $client = new Client\Curl();
     $client->send($request, $response);
     return 'true' == $response->getContent();
 }
 /**
  * @param array $parameters
  *
  * @return array
  */
 protected function doHttpRequest($parameters)
 {
     $request = new Request(RequestInterface::METHOD_POST, self::OAUTH2_ACCESS_TOKEN_URL);
     $response = new Response();
     $contentParameters = ['client_id' => $this->configManager->get('oro_google_integration.client_id'), 'client_secret' => $this->configManager->get('oro_google_integration.client_secret')];
     $parameters = array_merge($contentParameters, $parameters);
     $content = http_build_query($parameters, '', '&');
     $headers = ['Content-length: ' . strlen($content), 'content-type: application/x-www-form-urlencoded', 'user-agent: oro-oauth'];
     $request->setHeaders($headers);
     $request->setContent($content);
     $this->httpClient->send($request, $response);
     return $this->getResponseContent($response);
 }
 /**
  * @param array $transformed
  *
  * @throws \AntiMattr\ETL\Exception\LoadException
  */
 public function load(array $transformed = [])
 {
     if (empty($transformed)) {
         throw new LoadException("Error - No data to load");
     }
     $messageFactory = $this->createMessageFactory();
     $dataContext = $this->task->getDataContext();
     $content = ['POST' => ["/action" => array_values($transformed)]];
     $resource = '/v2/batch';
     $request = $messageFactory->createRequest('POST', $resource, $this->host);
     $request->addHeader('Content-Type: application/json');
     $request->setContent(json_encode($content));
     $response = $messageFactory->createResponse();
     $options = [CURLOPT_USERPWD => sprintf("%s:%s", $this->apiKey, $this->apiSecret)];
     try {
         $this->buzz->send($request, $response, $options);
         $this->buzz->setTimeout($this->timeout);
     } catch (ClientException $e) {
         throw new LoadException($e->getMessage());
     }
     $dataContext->setLoadedCount(count($transformed));
 }
 public function sendRequest()
 {
     // new Request
     $request = new Request($this->requestType, $this->resource, $this->host);
     // add headers
     $request->addHeaders($this->headers);
     // add body
     $request->setContent($this->body);
     // prepare client
     $response = new Response();
     $curl = new Curl();
     $curl->send($request, $response);
     $this->request = $request;
     $this->response = $response;
 }
Esempio n. 10
0
 /**
  * @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);
     }
 }
Esempio n. 11
0
 /**
  * Make an API request.
  *
  * @param  \Tev\Bs\Contracts\EndpointInterface $endpoint Requesting endpoint
  * @return \Tev\Bs\Contracts\ResponseInterface           Response
  *
  * @throws \Exception
  * @throws \Tev\Bs\Exception\ErrorResponseException
  */
 public function request(EndpointInterface $endpoint)
 {
     if ($this->customerId !== null) {
         $endpoint->setParam('customer_id', $this->customerId);
     }
     // Request
     $request = new Request($endpoint->getMethod(), $endpoint->getUrl(), $this->host);
     $request->setContent($endpoint->getContent());
     // Response
     $response = new Response();
     // Authorisation
     $listener = new BasicAuthListener($this->clientId, $this->clientSecret);
     $listener->preSend($request);
     // Send
     $client = new Curl();
     $client->setTimeout(30);
     $client->send($request, $response);
     // Parse
     $parser = new Parser($response, $endpoint);
     return $parser->getResponse();
 }
Esempio n. 12
0
 /**
  * @param $id
  * @return mixed|null
  */
 public function getGroupByID($id)
 {
     $token = $this->getAccessToken();
     if ($token == "") {
         return null;
     }
     $client = new Curl();
     $req = new Request(Request::METHOD_GET, "/" . $this->tenant . "/groups?api-version=1.6", "https://graph.windows.net");
     $req->addHeader("authorization: Bearer " . $token);
     $res = new Response();
     $client->setTimeout(20000);
     $client->send($req, $res);
     if ($res->getStatusCode() < 299) {
         return json_decode($res->getContent());
     }
     if ($res->getStatusCode() == 401) {
         $this->refreshToken($this->token->getToken()->getUser());
         return $this->getGroupByID($id);
     }
     return null;
 }
 /**
  * @param AntiMattr\Common\Address\AddressInterface $address
  *
  * @return AntiMattr\AddressVerifier\Event\VerificationEvent $event
  *
  * @throws AntiMattr\AddressVerifier\Exception\Connection\ConnectionException
  * @throws AntiMattr\AddressVerifier\Exception\Connection\TimeoutException
  * @throws AntiMattr\AddressVerifier\Exception\IntegrationException
  * @throws AntiMattr\AddressVerifier\Exception\Location\CorrectionException
  * @throws AntiMattr\AddressVerifier\Exception\Location\StreetAddressException     
  */
 public function verifyLocation(AddressInterface $address)
 {
     if (!($streetAddressLine1 = $address->getStreetAddressLine1())) {
         throw new IntegrationException('Verify address missing street address line 1');
     }
     if (!($locality = $address->getLocality())) {
         throw new IntegrationException('Verify address missing locality');
     }
     if (!($region = $address->getRegion())) {
         throw new IntegrationException('Verify address missing region');
     }
     if (!($postalCode = $address->getPostalCode())) {
         throw new IntegrationException('Verify address missing postal code');
     }
     $streetAddressLine2 = $address->getStreetAddressLine2() ?: '';
     $params = array('address[street]' => $streetAddressLine1, 'address[unit]' => $streetAddressLine2, 'address[city]' => $locality, 'address[state]' => $region, 'address[zip]' => $postalCode, 'apikey' => $this->apiKey);
     $query = http_build_query($params);
     $resource = sprintf("/addresses.json?%s", $query);
     $request = $this->messageFactory->createRequest('GET', $resource, 'https://bpi.briteverify.com');
     $response = $this->messageFactory->createResponse();
     $event = $this->eventFactory->createEvent($address);
     $this->buzz->setTimeout($this->timeout);
     $this->log($request);
     try {
         $this->buzz->send($request, $response);
         $this->log($response);
         $statusCode = $response->getStatusCode();
         if ($statusCode !== 200) {
             $message = $response->getReasonPhrase();
             throw new IntegrationException($message);
         }
         $content = json_decode($response->getContent());
         if ($content->status === 'invalid') {
             $message = $content->error;
             throw new StreetAddressException($message);
         }
         if ($content->corrected === true) {
             $newAddress = new GenericAddress();
             if (isset($content->street)) {
                 $newAddress->setStreetAddressLine1($content->street);
             }
             if (isset($content->unit)) {
                 $newAddress->setStreetAddressLine2($content->unit);
             }
             if (isset($content->city)) {
                 $newAddress->setLocality($content->city);
             }
             if (isset($content->state_code)) {
                 $newAddress->setRegion($content->state_code);
             }
             if (isset($content->zip)) {
                 $postalCode = isset($content->plus4) ? $content->zip . '-' . $content->plus4 : $content->zip;
                 $newAddress->setPostalCode($postalCode);
             }
             if (isset($content->country_code)) {
                 $newAddress->setCountry($content->country_code);
             }
             throw new CorrectionException($newAddress);
         }
     } catch (ClientException $e) {
         $subject = $e->getMessage();
         if (0 !== preg_match('/timed out/', $subject)) {
             throw new TimeoutException($subject);
         }
         throw new ConnectionException($subject);
     }
     return $event;
 }
Esempio n. 14
0
 /**
  * @param string $body
  * @param string $type
  */
 public function speak($body, $type = 'TextMessage')
 {
     $buzzRequest = new BuzzRequest('POST', '/room/' . $this->room . '/speak.json', 'https://' . $this->subdomain . '.campfirenow.com');
     $buzzRequest->addHeader('Content-type: application/json');
     $buzzRequest->addHeader('Authorization: Basic ' . base64_encode($this->token . ':x'));
     $buzzRequest->setContent(json_encode(array('message' => array('type' => $type, 'body' => $body))));
     $response = new BuzzResponse();
     $client = new BuzzCurl();
     $client->send($buzzRequest, $response);
 }