Example #1
0
 public function callMethod($method, array $params)
 {
     $meta = array();
     if ($this->sessionKey) {
         $meta['sessionKey'] = $this->sessionKey;
     }
     if ($this->connectionID) {
         $meta['connectionID'] = $this->connectionID;
     }
     if ($method == 'conduit.connect') {
         $certificate = idx($params, 'certificate');
         if ($certificate) {
             $token = time();
             $params['authToken'] = $token;
             $params['authSignature'] = sha1($token . $certificate);
         }
         unset($params['certificate']);
     }
     if ($meta) {
         $params['__conduit__'] = $meta;
     }
     $port = null;
     if ($this->port) {
         $port = ':' . $this->port;
     }
     $uri = $this->protocol . '://' . $this->host . $port . '/' . $this->path . $method;
     $data = array('params' => json_encode($params), 'output' => 'json');
     if ($this->protocol == 'https') {
         $core_future = new HTTPSFuture($uri, $data);
     } else {
         $core_future = new HTTPFuture($uri, $data);
     }
     $core_future->setMethod('POST');
     $core_future->setTimeout($this->timeout);
     $profiler = PhutilServiceProfiler::getInstance();
     $this->profilerCallID = $profiler->beginServiceCall(array('type' => 'conduit', 'method' => $method));
     $conduit_future = new ConduitFuture($core_future);
     $conduit_future->setClient($this, $method);
     $conduit_future->isReady();
     return $conduit_future;
 }
Example #2
0
#!/usr/bin/env php
<?php 
$root = dirname(dirname(dirname(__FILE__)));
require_once $root . '/scripts/__init_script__.php';
$uri = 'https://secure.phabricator.com/derp/derp/';
$method = 'GET';
$data = '';
$timeout = 30;
$parsed = new PhutilURI($uri);
if ($parsed->getProtocol() == 'https') {
    $future = new HTTPSFuture($uri, $data);
} else {
    $future = new HTTPFuture($uri, $data);
}
$future->setMethod($method);
$future->setTimeout($timeout);
print_r($future->resolve());
Example #3
0
 public function callMethod($method, array $params)
 {
     $meta = array();
     if ($this->sessionKey) {
         $meta['sessionKey'] = $this->sessionKey;
     }
     if ($this->connectionID) {
         $meta['connectionID'] = $this->connectionID;
     }
     if ($method == 'conduit.connect') {
         $certificate = idx($params, 'certificate');
         if ($certificate) {
             $token = time();
             $params['authToken'] = $token;
             $params['authSignature'] = sha1($token . $certificate);
         }
         unset($params['certificate']);
     }
     if ($meta) {
         $params['__conduit__'] = $meta;
     }
     $port = null;
     if ($this->port) {
         $port = ':' . $this->port;
     }
     $uri = $this->protocol . '://' . $this->host . $port . '/' . $this->path . $method;
     $data = array('params' => json_encode($params), 'output' => 'json', '__conduit__' => true);
     // NOTE: If we're on Windows, the socket-based HTTPFuture won't work
     // properly. In theory it may be fixable, but the easier fix is just to use
     // the cURL-based HTTPSFuture for HTTP. We'll lose the ability to
     // parallelize requests but things will work correctly.
     $use_https_future = $this->protocol == 'https' || phutil_is_windows();
     if ($use_https_future) {
         $core_future = new HTTPSFuture($uri, $data);
     } else {
         $core_future = new HTTPFuture($uri, $data);
     }
     $core_future->setMethod('POST');
     $core_future->setTimeout($this->timeout);
     $profiler = PhutilServiceProfiler::getInstance();
     $this->profilerCallID = $profiler->beginServiceCall(array('type' => 'conduit', 'method' => $method, 'size' => strlen(http_build_query($data, '', '&'))));
     $conduit_future = new ConduitFuture($core_future);
     $conduit_future->setClient($this, $method);
     $conduit_future->isReady();
     return $conduit_future;
 }