Example #1
0
 /**
  * save current node
  *
  * @throws \Neo4j\Exception\HttpException
  * @return void
  */
 public function save()
 {
     if ($this->_is_new) {
         list($response, $http_code) = Request::post($this->getUri(), $this->_data);
         if ($http_code != 201) {
             throw new \Neo4j\Exception\HttpException("http code: " . $http_code . ", response: " . print_r($response, true));
         }
     } else {
         list($response, $http_code) = Request::put($this->getUri() . '/properties', $this->_data);
         if ($http_code != 204) {
             throw new \Neo4j\Exception\HttpException("http code: " . $http_code . ", response: " . print_r($response, true));
         }
     }
     if ($this->_is_new) {
         $path = explode("/", $response['self']);
         $this->_id = end($path);
         $this->_is_new = false;
     }
 }
Example #2
0
 private function _executePut($resource, $data, $requiresToken = true)
 {
     if ($requiresToken) {
         $this->requiresToken();
     }
     $request = new Request($this->_url, $this->getToken());
     $content = $request->put($resource, $data);
     return true;
 }
Example #3
0
function testSendPut()
{
    $response = Request::put(TEST_URL)->sendsAndExpects(Mime::JSON)->body(array("key" => "value"))->sendIt();
    assert('{"key":"value"}' === $response->body->requestBody);
    assert(Http::PUT === $response->body->requestMethod);
    $response = Request::put(TEST_URL)->sendsAndExpects(Mime::JSON)->body('{"key":"value"}')->sendIt();
    assert('{"key":"value"}' === $response->body->requestBody);
}
Example #4
0
 /**
  * Test the params/get/put/post functions for retrieving input data.
  * 
  * Pre-conditions:
  * Data is present in input arrays (POST, GET, COOKIE, etc)
  *
  * Post-conditions:
  * Requested data is returned if it is present, otherwise null.
  */
 public function testParamFunctions()
 {
     $_GET = array('get_foo' => 'get_bar');
     $_POST = array('post_foo' => 'post_bar');
     $_COOKIE = array('cookie_foo' => 'cookie_bar');
     $_SERVER['REQUEST_URI'] = '';
     $request = new Request();
     $this->assertEquals($request->params('get_foo'), 'get_bar');
     $this->assertEquals($request->params('post_foo'), 'post_bar');
     $this->assertNull($request->params('null'));
     $this->assertEquals($request->get(), $_GET);
     $this->assertEquals($request->post(), $_POST);
     $this->assertEquals($request->get('get_foo'), 'get_bar');
     $this->assertEquals($request->post('post_foo'), 'post_bar');
     $this->assertEquals($request->cookie('cookie_foo'), 'cookie_bar');
     $this->assertEquals($request->header('HOST'), 'slim');
     // Handle overriding PUT
     $_POST = array('put_foo' => 'put_bar', '_METHOD' => 'PUT');
     $request = new Request();
     $this->assertEquals($request->put('put_foo'), 'put_bar');
     $this->assertEquals($request->put(), array('put_foo' => 'put_bar'));
 }
Example #5
0
/**
 * Sends an HTTP PUT request.
 *
 * Uses HTTP PUT request to post $data to a $url
 * @param string $url The URL that should be opnened.
 * @param arrray $data An associative array that contains the fields that should
 * be postet to $url
 * @param bool $authbool If true then send sessioninformation in header.
 * @param string $message The Response Message e.g. 404. Argument is optional.
 */
function http_put_data($url, $data, $authbool, &$message = 0)
{
    $answer = Request::put($url, array(), $data, $authbool);
    if (isset($answer['status'])) {
        $message = $answer['status'];
    }
    if ($message == "401") {
        Authentication::logoutUser();
    }
    return isset($answer['content']) ? $answer['content'] : '';
}