Example #1
0
 protected function execute()
 {
     $output = curl_exec($this->_handle);
     $responseFactory = new ResponseFactory();
     $responseFactory->setCurlHandle($this->_handle)->setRawResponse($output);
     return $responseFactory->generateResponse();
 }
Example #2
0
 public function testReturnsResultOfPassingWpDataToFactoryCreate()
 {
     $wpData = ['response' => ['code' => 201]];
     $this->wpHttp->get('uri', [])->willReturn($wpData);
     $this->factory->create($wpData)->shouldBeCalled();
     $this->request->get('uri');
 }
Example #3
0
 public function testReturns500ResponseWithErrorsWhenInputIsWordpressErrorObject()
 {
     $wpError = $this->prophesize('WP_Error');
     $wpError->get_error_messages()->willReturn(['ack!', 'bleh...', 'LOL wut?']);
     $response = $this->factory->create($wpError->reveal());
     $this->assertSame(500, $response->getStatusCode());
     $this->assertSame("ack!\nbleh...\nLOL wut?", $response->getBody());
 }
Example #4
0
 public function testGetDocument()
 {
     $value = 'HTTP/1.1 200 OK' . "\r\n" . 'Server: CouchDB/1.3.1 (Erlang OTP/R15B03)' . "\r\n" . 'ETag: "7-9b82726d3c5ef5d5d95ae33ec59ddd06"' . "\r\n" . 'Date: Sun, 23 Mar 2014 21:09:51 GMT' . "\r\n" . 'Content-Type: text/plain; charset=utf-8' . "\r\n" . 'Content-Length: 456' . "\r\n" . 'Cache-Control: must-revalidate' . "\r\n" . '' . "\r\n" . '{"_id":"doc","_rev":"7-9b82726d3c5ef5d5d95ae33ec59ddd06","_attachments":{"key":{"content_type":"application/octet-stream","revpos":7,"digest":"md5-1B2M2Y8AsgTpgAmY7PhCfg==","length":0,"stub":true},"b":{"content_type":"application/octet-stream","revpos":6,"digest":"md5-fcbr7InXnOCoyr/rRJ3DtA==","length":405,"stub":true},"a":{"content_type":"application/x-www-form-urlencoded","revpos":3,"digest":"md5-fcbr7InXnOCoyr/rRJ3DtA==","length":405,"stub":true}}}';
     $expect = 'doc';
     $factory = new ResponseFactory();
     $actual = json_decode($factory->make($value)->body())->_id;
     $this->assertEquals($expect, $actual);
 }
Example #5
0
 /**
  * Attempts to create a document in the database with the given id and body.
  *
  * @param Connection $connection
  * @param string $database
  * @param string $id
  * @param string $body
  * @return mixed
  * @throws DocumentCreationException
  */
 public function createDocument(Connection $connection, $database, $id, $body)
 {
     $value = $connection->request('PUT', $database . '/' . $id, $body);
     $response = $this->response_factory->make($value);
     if ($response->status() !== '201' && $response->status() !== '202') {
         throw new DocumentCreationException();
     }
     return json_decode($response->body());
 }
Example #6
0
 /**
  * Requests a document from the database.
  *
  * If the request is not successful, then getDocument will throw a DocumentNotFoundException.
  *
  * If the request is successful, then the body should contain a json object, which will be decoded, and then
  * returned.
  *
  * @param Connection $connection
  * @param Database $database
  * @param string $id
  * @throws DocumentNotFoundException
  * @return Response
  */
 public function getDocument(Connection $connection, $database, $id)
 {
     $value = $connection->request('GET', $database . '/' . $id);
     $response = $this->response_factory->make($value);
     if (!$response->success()) {
         throw new DocumentNotFoundException();
     }
     return json_decode($response->body());
 }
Example #7
0
 public function createAttachment(Uploader $uploader, $database, $id, $revision, $name, $file)
 {
     $value = $uploader->upload('PUT', $database . '/' . $id . '/' . $name . '?rev=' . $revision, $file);
     $response = $this->response_factory->make($value);
     if ($response->status() !== '201' && $response->status() !== '202') {
         throw new AttachmentCreationException();
     }
     return json_decode($response->body());
 }
Example #8
0
 public function testQuery()
 {
     $selectResult = ['documents' => [['product_id' => 1, 'sku' => 'Product']], 'aggregations' => ['aggregation_name' => ['aggregation1' => [1, 3], 'aggregation2' => [2, 4]]]];
     $this->connectionAdapter->expects($this->at(0))->method('fetchAssoc')->will($this->returnValue($selectResult['documents']));
     $this->mapper->expects($this->once())->method('buildQuery')->with($this->request)->will($this->returnValue($this->select));
     $this->responseFactory->expects($this->once())->method('create')->with($selectResult)->will($this->returnArgument(0));
     $this->aggregatioBuilder->expects($this->once())->method('build')->willReturn($selectResult['aggregations']);
     $response = $this->adapter->query($this->request);
     $this->assertEquals($selectResult, $response);
 }
Example #9
0
 public function testQuery()
 {
     $selectResult = ['documents' => [['product_id' => 1, 'sku' => 'Product']], 'aggregations' => ['aggregation_name' => ['aggregation1' => [1, 3], 'aggregation2' => [2, 4]]]];
     $select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->getMock();
     $this->connectionAdapter->expects($this->once())->method('select')->willReturn($select);
     $table = $this->getMockBuilder('Magento\\Framework\\DB\\Ddl\\Table')->disableOriginalConstructor()->getMock();
     $this->temporaryStorage->expects($this->any())->method('storeDocumentsFromSelect')->willReturn($table);
     $this->connectionAdapter->expects($this->any())->method('fetchAssoc')->will($this->returnValue($selectResult['documents']));
     $this->mapper->expects($this->once())->method('buildQuery')->with($this->request)->will($this->returnValue($this->select));
     $this->responseFactory->expects($this->once())->method('create')->with($selectResult)->will($this->returnArgument(0));
     $this->aggregatioBuilder->expects($this->once())->method('build')->willReturn($selectResult['aggregations']);
     $response = $this->adapter->query($this->request);
     $this->assertEquals($selectResult, $response);
 }
Example #10
0
 /**
  * @return Response
  */
 private function exec()
 {
     $url = $this->url;
     $options = $this->options;
     switch ($this->method) {
         case self::METHOD_GET:
             break;
         case self::METHOD_POST:
             $options[] = [CURLOPT_POST, TRUE];
             break;
         default:
             $options[] = [CURLOPT_CUSTOMREQUEST, $this->method];
     }
     if ($this->parameters) {
         if ($this->method === self::METHOD_GET) {
             $url .= '?' . http_build_query($this->parameters);
         } else {
             $isJson = isset($options[self::CURLOPT_JSON]) && $options[self::CURLOPT_JSON];
             $data = $isJson ? json_encode($this->parameters) : http_build_query($this->parameters);
             $options[] = [CURLOPT_POSTFIELDS, $data];
         }
     }
     if ($this->headers) {
         $options[] = [CURLOPT_HTTPHEADER, $this->headers];
     }
     $request = $this->requestFactory->create($url, $options);
     return $this->responseFactory->create($request);
 }
    public function testReferenceException()
    {
        $callContext = new CallContext();
        $callContext->setIdempotenceKey('test');
        $responseHeaders = array('Content-Type' => 'application/json', 'X-GCS-Idempotence-Request-Timestamp' => '12345');
        $responseBody = <<<EOD
{
   "errorId" : "75b0f13a-04a5-41b3-83b8-b295ddb23439-000013c6",
   "errors" : [ {
      "code" : "1400",
      "message" : "DUPLICATE REQUEST IN PROGRESS",
      "httpStatusCode" : 409
   } ]
}
EOD;
        $connectionResponse = new DefaultConnectionResponse(409, $responseHeaders, $responseBody);
        $responseFactory = new ResponseFactory();
        $responseExceptionFactory = new ResponseExceptionFactory();
        $exception = $responseExceptionFactory->createException($connectionResponse->getHttpStatusCode(), $responseFactory->createResponse($connectionResponse, new ResponseClassMap(), $callContext), $callContext);
        $this->assertInstanceOf('\\Ingenico\\Connect\\Sdk\\ReferenceException', $exception);
    }
Example #12
0
 /**
  * Obtains an array of randomly generated uuids from the server.
  *
  * @param Connection $connection
  * @param int $count
  * @return mixed
  */
 public function generateIds(Connection $connection, $count = 1)
 {
     $value = $connection->request('GET', '_uuids?count=' . $count);
     $response = $this->response_factory->make($value);
     return json_decode($response->body())->uuids;
 }
Example #13
0
    MySQLConnection::Close($GLOBALS['mysqli']);
    //$ret_val['newcommentid'] = $postid;
    $ret_val['success'] = 'Thanks for your comments. You should see up it pretty soon.';
    //allow cors
    cors();
    echo json_encode($ret_val);
});
$app->get('/getuserresponses/:postid', function ($postid) {
    require_once 'common/dbconnection.php';
    require_once 'category.php';
    require_once 'post.php';
    require_once 'posttype.php';
    require_once 'userresponse.php';
    require_once 'userreply.php';
    $GLOBALS['mysqli'] = MySQLConnection::Open();
    $userResponses = ResponseFactory::GetIsOKResponsesByPost($postid);
    MySQLConnection::Close($GLOBALS['mysqli']);
    //allow cors
    cors();
    echo json_encode($userResponses);
});
$app->get('/getrelatedposts/:postid', function ($postid) {
    require_once 'common/dbconnection.php';
    require_once 'category.php';
    require_once 'post.php';
    require_once 'posttype.php';
    require_once 'userresponse.php';
    require_once 'userreply.php';
    $GLOBALS['mysqli'] = MySQLConnection::Open();
    $relatedPosts = PostFactory::GetRelatedPosts($postid);
    MySQLConnection::Close($GLOBALS['mysqli']);