示例#1
0
 public function makeGerritProjectReadOnly(Git_RemoteServer_GerritServer $server, $gerrit_project_full_name)
 {
     try {
         $this->logger->info("Gerrit REST driver: Set {$gerrit_project_full_name} Read-Only");
         $this->sendRequest($server, $this->guzzle_client->put($this->getGerritURL($server, '/projects/' . urlencode($gerrit_project_full_name) . '/config'), $this->getRequestOptions(array(self::HEADER_CONTENT_TYPE => self::MIME_JSON)), json_encode(array('state' => 'READ_ONLY'))));
         $this->logger->info("Gerrit REST driver: Project successfully set Read-Only");
         return true;
     } catch (Exception $exception) {
         $this->throwGerritException("Gerrit REST driver: An error occured while setting project read-only: " . $exception->getMessage());
     }
 }
 /**
  * send request to Youtrack api, dosnt check the cache. Use the rest function in this class instead
  * @param string $url request url
  * @param string $postOrGet get|post|put request type
  * @param array $headers
  * @param string $body
  * @param array $options
  * @return object request object
  */
 function restResponse($url, $postOrGet = 'get', $headers = null, $body = null, $options = null)
 {
     $client = new \Guzzle\Http\Client();
     $authenticationAndSecurity = new authenticationAndSecurity();
     $authentication = $authenticationAndSecurity->getAuthentication();
     if ($authentication['type'] !== 'password' && $authentication['type'] !== 'cookie' && $authentication['type'] !== 'file') {
         echo 'authentication type unknown. please check its set in the customSettings.php file';
         return;
     }
     if (!isset($options)) {
         if ($authentication['type'] === 'password') {
             $options = ['auth' => [$authentication['details']['user'], $authentication['details']['password']]];
         } else {
             $options = [];
         }
     }
     if ($postOrGet === 'get') {
         $request = $client->get($url, $headers, $options);
     } elseif ($postOrGet === 'post') {
         $request = $client->post($url, $headers, $body, $options);
     } elseif ($postOrGet === 'put') {
         $request = $client->put($url, $headers, $body, $options);
     }
     //        if( $postOrGet === 'put' && isset($headers) ){
     //            foreach($headers as $key => $value){
     //                $request->addHeader($key,$value);
     //            }
     //        }
     if ($authentication['type'] === 'cookie' && $authentication['details']) {
         foreach ($authentication['details'] as $singleCookie) {
             foreach ($singleCookie as $cookieName => $cookieValue) {
                 $request->addCookie($cookieName, $cookieValue);
             }
         }
     }
     $request->send();
     return $request;
 }
示例#3
0
$app['debug'] = true;
$app->get('/', function () {
    $client = new Guzzle\Http\Client();
    $response = $client->get('http://tvprogramm.srf.ch/feed/q/query/simpsons')->send();
    $xml = $response->xml();
    $times = array();
    foreach ($xml->channel->item as $item) {
        $title = (string) $item->title;
        $date = explode(',', $title)[0];
        $times[] = strtotime($date);
    }
    $next = min($times);
    $tolerance = 5 * 60;
    $now = time();
    if (isset($_GET['now'])) {
        $now = strtotime($_GET['now']);
    }
    $key = 2;
    if (isset($_GET['key'])) {
        $key = (int) $_GET['key'];
    }
    $trigger = false;
    if ($now > $next - $tolerance && $now < $next) {
        $trigger = true;
        $client->put('http://tamberg-homer.try.yaler.net/ir?key=' . $key)->send();
        //$client->put('http://requestb.in/p7ne8hp7?key=1&channel=' . $channel)->send();
    }
    $result = "Now: " . date('r', $now) . "<br>Next show: " . date('r', $next) . "<br>Trigger: " . ($trigger ? "true" : "false");
    return $result;
});
$app->run();