/**
  * @param \Buzz\Message\Request $request
  * @param object                $tracking
  */
 public function bind(Request $request, $tracking)
 {
     $number = $tracking->getNumber();
     $trackingData = [];
     $trackingData = ['tracking_number' => $number];
     if ($courier = $tracking->getCourier()) {
         $trackingData['slug'] = $courier;
     }
     if ($orderId = $tracking->getOrderId()) {
         $trackingData['order_id'] = $orderId;
     }
     if ($orderUrl = $tracking->getOrderUrl()) {
         $trackingData['order_id_path'] = $orderUrl;
     }
     if ($meta = $tracking->getMeta()) {
         $customFields = [];
         foreach ($meta as $key => $value) {
             $customFields[$key] = $value;
         }
         $trackingData['custom_fields'] = $customFields;
     }
     $content = ['tracking' => $trackingData];
     $content = $this->encodeContent($content);
     $request->setContent($content);
 }
 /**
  * @param  Buzz\Message\Request                           $request
  * @param  Doctrine\Common\Collections\Collection         $collection
  * @throws AntiMattr\Sears\Exception\IntegrationException
  */
 public function bindCollection(Request $request, Collection $collection)
 {
     $createdAt = $this->getCreatedAt();
     if (null === $createdAt) {
         throw new IntegrationException('CreatedAt is required');
     }
     $element = $this->xmlBuilder->setRoot('dss-order-adjustment-feed')->setNamespace('http://seller.marketplace.sears.com/oms/v1')->setSchemaLocation('http://seller.marketplace.sears.com/oms/v1 dss-order-return-v1.xsd ')->create();
     $element->addChild('date-time-stamp', $this->getCreatedAt()->format('Y-m-d\\TH:i:s'));
     // Hold all IntegrationExceptions until the end
     $exceptions = array();
     foreach ($collection as $orderReturn) {
         try {
             $this->xmlBuilder->addChild($element, 'dss-order-adjustment', $orderReturn->toArray());
         } catch (IntegrationException $e) {
             $orderId = $orderReturn->getPurchaseOrderId();
             $message = $e->getMessage();
             $exceptions[] = $this->exceptionMessageForOrder($orderId, $message);
         }
     }
     $xml = $element->asXML();
     $request->setContent($xml);
     if (count($exceptions) > 0) {
         throw new IntegrationException(json_encode($exceptions));
     }
 }
示例#3
0
 /**
  * Authenticate the request object. Apply the access_token to the URL
  *
  * TODO: implement
  * 
  * @param Request       $request        Request object to authenticate
  */
 public function authenticate(\Buzz\Message\Request $request)
 {
     $url = $request->getUrl();
     $prefix = strpos($url, '?') > 0 ? '&' : '?';
     $request->fromUrl($url . $prefix . 'access_token=' . $this->accessToken);
     return $request;
 }
示例#4
0
 protected static function setCurlOptsFromRequest($curl, Message\Request $request)
 {
     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->getMethod());
     curl_setopt($curl, CURLOPT_URL, $request->getUrl());
     curl_setopt($curl, CURLOPT_HTTPHEADER, $request->getHeaders());
     curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getContent());
 }
示例#5
0
 /**
  * Create request instance
  *
  * @param string $method Request method
  * @param string $path Request path
  * @param array $body Request body array
  */
 protected function createRequest($method, $path, array $body)
 {
     $request = new Request($method, $path, $this->createHost());
     $request->setHeaders(['Accept' => 'application/json; charset=UTF-8', 'Content-Type' => 'application/json', 'X-Stream' => 'true']);
     $request->addHeader('Authorization: Basic ' . base64_encode($this->options['username'] . ':' . $this->options['password']));
     $request->setContent(json_encode($body));
     return $request;
 }
示例#6
0
文件: Api.php 项目: ledjin/sagepay
 /**
  * @param array $paymentDetails
  *
  * @return \LedjIn\Bridge\Buzz\Response
  */
 public function createOffsitePurchase(array $paymentDetails)
 {
     $paymentDetails['TxType'] = static::OPERATION_PAYMENT;
     $query = http_build_query($paymentDetails);
     $request = new Request('post', $this->getOffsiteResource(), $this->getGatewayHost());
     $request->setContent($query);
     return $this->doRequest($request);
 }
 public function testBearerAuthListener()
 {
     $request = new Message\Request();
     $this->assertEmpty($request->getHeader('Authorization'));
     $listener = new BearerAuthListener('superSecretAccessTokenGeneratedByTheNsaItself');
     $listener->preSend($request);
     $this->assertEquals('Bearer superSecretAccessTokenGeneratedByTheNsaItself', $request->getHeader('Authorization'));
 }
 public function testBasicAuthHeader()
 {
     $request = new Message\Request();
     $this->assertEmpty($request->getHeader('Authorization'));
     $listener = new BasicAuthListener('foo', 'bar');
     $listener->preSend($request);
     $this->assertEquals('Basic ' . base64_encode('foo:bar'), $request->getHeader('Authorization'));
 }
示例#9
0
 /**
  * @return HttpRequest
  */
 public function createHttpRequest($method, $uri, $contentType = '', $acceptType = '')
 {
     $request = new HttpRequest($method, $uri, $this->httpHost);
     $request->addHeader('Authorization: Basic ' . base64_encode($this->httpAuth));
     $request->addHeader('Content-Type: ' . $this->generateMediaTypeString($contentType));
     $request->addHeader('Accept: ' . $this->generateMediaTypeString($acceptType));
     return $request;
 }
示例#10
0
文件: Jar.php 项目: philip/Buzz
 /**
  * Processes Set-Cookie headers from a request/response pair.
  * 
  * @param Message\Request  $request  A request object
  * @param Message\Response $response A response object
  */
 public function processSetCookieHeaders(Message\Request $request, Message\Response $response)
 {
     foreach ($response->getHeader('Set-Cookie', false) as $header) {
         $cookie = new Cookie();
         $cookie->fromSetCookieHeader($header, parse_url($request->getHost(), PHP_URL_HOST));
         $this->addCookie($cookie);
     }
 }
 /**
  * @param  Request     $request
  * @return BuzzRequest
  */
 protected function prepareRequest(Request $request)
 {
     $buzzRequest = new BuzzRequest($request->getMethod(), $request->getUrl()->getResource(), $request->getUrl()->getHost());
     $buzzRequest->setProtocolVersion($request->getProtocolVersion());
     $buzzRequest->setHeaders(HeaderConverter::convertAssociativeToRaw($this->prepareHeaders($request)));
     $buzzRequest->setContent($request->getContent());
     return $buzzRequest;
 }
示例#12
0
 /**
  * @dataProvider provideInvalidHosts
  */
 public function testSendToInvalidUrl($host, $client)
 {
     $this->setExpectedException('Buzz\\Exception\\ClientException');
     $request = new Message\Request();
     $request->fromUrl('http://' . $host . ':12345');
     $response = new Message\Response();
     $client = new $client();
     $client->setTimeout(0.05);
     $client->send($request, $response);
 }
示例#13
0
 public function __construct(Response $response, Request $request, Curl $client)
 {
     $this->response = $response;
     $request->setProtocolVersion(1.1);
     $request->addHeader('Content-Type: application/json');
     $this->request = $request;
     $client->setTimeout(5);
     $client->setIgnoreErrors(true);
     $this->client = $client;
 }
示例#14
0
 /**
  * @dataProvider provideInvalidHosts
  */
 public function testSendToInvalidUrl($host)
 {
     $this->setExpectedException('RuntimeException');
     $request = new Message\Request();
     $request->fromUrl('http://' . $host . ':12345');
     $response = new Message\Response();
     $client = new FileGetContents();
     $client->setTimeout(0.05);
     $client->send($request, $response);
 }
示例#15
0
 /**
  *
  * @param \Buzz\Message\Request $request
  * @return boolean
  */
 public function isRequestCacheable(Request $request)
 {
     if (!$this->isHTTPMethodCacheable($request->getMethod())) {
         return false;
     }
     //[rfc2616-14.8]
     if ($request->getHeader("authorization")) {
         return false;
     }
     return true;
 }
示例#16
0
 /**
  * Plumbery method to request webdriver server.
  *
  * @param string $verb    HTTP method to use (GET, POST, DELETE)
  * @param string $path    Relative URL to server, without prefix "/"
  * @param string $content Content of request
  * @param array  $headers Additional HTTP headers
  */
 public function request($verb, $path, $content = null, array $headers = array())
 {
     $url = $this->url . $path;
     $request = new Request($verb, $url);
     $request->setContent($content);
     $response = new Response();
     $this->client->send($request, $response);
     $response->setContent(str_replace("", "", $response->getContent()));
     $this->verifyResponse($response);
     return $response;
 }
示例#17
0
 public function testAuthenticate()
 {
     $basic = new OAuth('KFGDSYGSDHKKGFSFN');
     // Create request, authenticate it
     $request = new Request();
     $request->fromUrl('http://test.com?name=dsyph3r');
     $request = $basic->authenticate($request);
     // Check access_token param is set correctly
     $url = parse_url($request->getUrl());
     $params = explode('&', $url['query']);
     $this->assertContains('access_token=KFGDSYGSDHKKGFSFN', $params);
 }
示例#18
0
 /**
  * Sends a request and records it to the journal.
  * 
  * @param Message\Request  $request  A request object
  * @param Message\Response $response A response object
  * 
  * @return Message\Response A response object
  */
 public function send(Message\Request $request, Message\Response $response = null)
 {
     if (null === $response) {
         $response = $this->createResponse();
     }
     if ($request instanceof BrowserAwareInterface) {
         $request->setBrowser($this);
     }
     $this->getClient()->send($request, $response);
     $this->getJournal()->record($request, $response);
     return $response;
 }
示例#19
0
 private function performRequest($endpoint, array $params = array())
 {
     $uri = static::BASE_URI . '/' . ltrim($endpoint, '/') . '?' . http_build_query($params);
     $request = new Request(Request::METHOD_GET, $uri);
     $request->addHeader(sprintf('Authorization: Bearer %s', $this->accessToken));
     $response = new Response();
     $this->client->send($request, $response);
     $content = $response->getContent();
     if ($response->getStatusCode() !== 200) {
         throw new InvalidArgumentException('An error occurred while calling the spotify API (' . $uri . '): ' . $content);
     }
     return json_decode($content, true);
 }
 public function testAddCookieHeadersAddsCookieHeaders()
 {
     $request = new Message\Request();
     $request->setHost('http://www.example.com');
     $cookie = new Cookie();
     $cookie->setName('SESSION');
     $cookie->setValue('asdf');
     $cookie->setAttribute(Cookie::ATTR_DOMAIN, '.example.com');
     $jar = new CookieJar();
     $jar->setCookies(array($cookie));
     $jar->addCookieHeaders($request);
     $this->assertEquals('SESSION=asdf', $request->getHeader('Cookie'));
 }
示例#21
0
 public function testLogger()
 {
     $test = $this;
     $logger = function ($line) use($test) {
         $test->assertRegExp('~^Sent "GET http://google.com/" in \\d+ms$~', $line);
     };
     $request = new Message\Request();
     $request->fromUrl('http://google.com/');
     $response = new Message\Response();
     $listener = new LoggerListener($logger);
     $listener->preSend($request);
     $listener->postSend($request, $response);
 }
示例#22
0
 public function testConvertsARequestToAContextArray()
 {
     $request = new Message\Request('POST', '/resource/123', 'http://example.com');
     $request->addHeader('Content-Type: application/x-www-form-urlencoded');
     $request->addHeader('Content-Length: 15');
     $request->setContent('foo=bar&bar=baz');
     $client = new StreamClient();
     $client->setMaxRedirects(5);
     $client->setIgnoreErrors(false);
     $client->setTimeout(10);
     $expected = array('http' => array('method' => 'POST', 'header' => "Content-Type: application/x-www-form-urlencoded\r\nContent-Length: 15", 'content' => 'foo=bar&bar=baz', 'protocol_version' => 1.0, 'ignore_errors' => false, 'max_redirects' => 5, 'timeout' => 10));
     $this->assertEquals($expected, $client->getStreamContextArray($request));
 }
 /**
  * @test
  */
 public function shouldAllowFactoryHttpExceptionFromRequestAndResponse()
 {
     $request = new Request();
     $request->setHost('http://example.com');
     $request->setResource('/foobar');
     $response = new Response();
     $response->setHeaders(array('HTTP/1.1 404 Not Found'));
     $httpException = HttpException::factory($request, $response);
     $this->assertInstanceOf('Payum\\Core\\Exception\\Http\\HttpException', $httpException);
     $this->assertSame($request, $httpException->getRequest());
     $this->assertSame($response, $httpException->getResponse());
     $this->assertEquals("Client error response\n[status code] 404\n[reason phrase] Not Found\n[url] http://example.com/foobar", $httpException->getMessage());
     $this->assertEquals(404, $httpException->getCode());
 }
 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;
 }
示例#25
0
 /**
  * @param Request $request
  * @param Response $response
  * 
  * @return HttpException
  */
 public static function factory(Request $request, Response $response)
 {
     if ($response->isClientError()) {
         $label = 'Client error response';
     } elseif ($response->isServerError()) {
         $label = 'Server error response';
     } else {
         $label = 'Unsuccessful response';
     }
     $message = implode(PHP_EOL, array($label, '[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
     $e = new static($message, $response->getStatusCode());
     $e->setResponse($response);
     $e->setRequest($request);
     return $e;
 }
示例#26
0
 /**
  * {@inheritDoc}
  */
 public function createTokenResponse($clientId, $secret, $code, $redirectUrl = "")
 {
     $url = 'https://www.google.com/accounts/o8/oauth2/token';
     $request = new Request(Request::METHOD_POST, $url);
     $request->setContent(http_build_query(array('code' => $code, 'client_id' => $clientId, 'client_secret' => $secret, 'grant_type' => 'authorization_code', 'redirect_uri' => urldecode($redirectUrl))));
     $response = new Response();
     $this->client->send($request, $response);
     $data = json_decode($response->getContent());
     if (isset($data->error)) {
         return;
     }
     $expiresAt = time() + $data->expires_in;
     $people = 'https://www.googleapis.com/plus/v1/people/me' . '?key=' . $clientId . '&access_token=' . $data->access_token;
     $me = json_decode($this->request($people));
     return new GoogleToken($me, $data->access_token, $expiresAt);
 }
示例#27
0
文件: Cookie.php 项目: kingsj/core
 /**
  * Returns true if the current cookie matches the supplied request.
  *
  * @return boolean
  */
 public function matchesRequest(Message\Request $request)
 {
     // domain
     if (!$this->matchesDomain(parse_url($request->getHost(), PHP_URL_HOST))) {
         return false;
     }
     // path
     if (!$this->matchesPath($request->getResource())) {
         return false;
     }
     // secure
     if ($this->hasAttribute(static::ATTR_SECURE) && !$request->isSecure()) {
         return false;
     }
     return true;
 }
 public function testConvertsARequestToAContextArray()
 {
     $request = new Request('POST', '/resource/123', 'http://example.com');
     $request->addHeader('Content-Type: application/x-www-form-urlencoded');
     $request->addHeader('Content-Length: 15');
     $request->setContent('foo=bar&bar=baz');
     $client = new StreamClient();
     $client->setMaxRedirects(5);
     $client->setIgnoreErrors(false);
     $client->setTimeout(10);
     $expected = array('http' => array('method' => 'POST', 'header' => "Content-Type: application/x-www-form-urlencoded\r\nContent-Length: 15", 'content' => 'foo=bar&bar=baz', 'protocol_version' => 1.1, 'ignore_errors' => false, 'follow_location' => true, 'max_redirects' => 6, 'timeout' => 10), 'ssl' => array('verify_peer' => true, 'verify_host' => 2));
     $this->assertEquals($expected, $client->getStreamContextArray($request));
     $client->setVerifyPeer(true);
     $expected['ssl']['verify_peer'] = true;
     $this->assertEquals($expected, $client->getStreamContextArray($request));
     $client->setMaxRedirects(0);
     $expected['http']['follow_location'] = false;
     $expected['http']['max_redirects'] = 1;
     $this->assertEquals($expected, $client->getStreamContextArray($request));
 }
 public function provideIdenticalGetRequestsInDifferentFormats()
 {
     $data = array();
     $textRequest = $this->loadRequest('example.com');
     $guzzleRequest = $this->getRequestFactory()->fromMessage($textRequest);
     $buzzRequest = new BuzzRequest($guzzleRequest->getMethod(), $guzzleRequest->getPath());
     $buzzRequest->setHeaders($guzzleRequest->getHeaderLines());
     $zendRequest = ZendRequest::fromString($textRequest);
     $requests = array($buzzRequest, $guzzleRequest, $textRequest, $zendRequest);
     foreach ($requests as $request1) {
         foreach ($requests as $request2) {
             // Don't compare a request with itself
             if ($request1 !== $request2) {
                 continue;
             }
             $data[] = array($request1, $request2);
         }
     }
     return $data;
 }
示例#30
0
 /**
  * @param  Buzz\Message\Request                           $request
  * @param  Doctrine\Common\Collections\Collection         $collection
  * @throws AntiMattr\Sears\Exception\IntegrationException
  */
 public function bindCollection(Request $request, Collection $collection)
 {
     $element = $this->xmlBuilder->setRoot('shipment-feed')->setNamespace('http://seller.marketplace.sears.com/oms/v5')->setSchemaLocation('http://seller.marketplace.sears.com/oms/v5 asn.xsd ')->create();
     // Hold all IntegrationExceptions until the end
     $exceptions = array();
     foreach ($collection as $shipment) {
         try {
             $this->xmlBuilder->addChild($element, 'shipment', $shipment->toArray());
         } catch (IntegrationException $e) {
             $orderId = $shipment->getPurchaseOrderId();
             $message = $e->getMessage();
             $exceptions[] = $this->exceptionMessageForOrder($orderId, $message);
         }
     }
     $xml = $element->asXML();
     $request->setContent($xml);
     if (count($exceptions) > 0) {
         throw new IntegrationException(json_encode($exceptions));
     }
 }