/** * 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; }
/** * exit respond with 401 code if logged in */ function checkForCookie() { $authenticationAndSecurity = new authenticationAndSecurity(); $authentication = $authenticationAndSecurity->getAuthentication(); if ($authentication['type'] === 'cookie' && $authentication['details'] === false) { http_response_code(401); // set 'unauthorised' code exit; } }