diff --git a/lib/Gitlab/Api/Projects.php b/lib/Gitlab/Api/Projects.php index 6e8dca3ab..31ff53b5d 100644 --- a/lib/Gitlab/Api/Projects.php +++ b/lib/Gitlab/Api/Projects.php @@ -23,6 +23,13 @@ public function create($name, array $params = array()) return $this->post('projects', $params); } + + public function createForUser($user_id, $name, array $params = array()) + { + $params['name'] = $name; + + return $this->post('projects/user/'.urlencode($user_id), $params); + } public function remove($project_id) { diff --git a/lib/Gitlab/Client.php b/lib/Gitlab/Client.php index b16195570..4277355fb 100644 --- a/lib/Gitlab/Client.php +++ b/lib/Gitlab/Client.php @@ -119,12 +119,13 @@ public function api($name) * @param string $token Gitlab private token * @param null|string $authMethod One of the AUTH_* class constants */ - public function authenticate($token, $authMethod = null) + public function authenticate($token, $authMethod = null, $sudo = null) { $this->httpClient->addListener( new AuthListener( $authMethod, - $token + $token, + $sudo ) ); } diff --git a/lib/Gitlab/HttpClient/Listener/AuthListener.php b/lib/Gitlab/HttpClient/Listener/AuthListener.php index ab40a4e74..8a42a4885 100644 --- a/lib/Gitlab/HttpClient/Listener/AuthListener.php +++ b/lib/Gitlab/HttpClient/Listener/AuthListener.php @@ -19,19 +19,26 @@ class AuthListener implements ListenerInterface * @var string */ private $method; + /** * @var string */ private $token; + /** + * @var string|null + */ + private $sudo; + /** * @param string $method * @param string $token */ - public function __construct($method, $token) + public function __construct($method, $token, $sudo = null) { $this->method = $method; $this->token = $token; + $this->sudo = $sudo; } /** @@ -49,12 +56,19 @@ public function preSend(RequestInterface $request) switch ($this->method) { case Client::AUTH_HTTP_TOKEN: $request->addHeader('private_token: '.$this->token); + if (!is_null($this->sudo)) { + $request->addHeader('SUDO: '.$this->sudo); + } break; case Client::AUTH_URL_TOKEN: $url = $request->getUrl(); - $url .= (false === strpos($url, '?') ? '?' : '&').utf8_encode(http_build_query(array('private_token' => $this->token), '', '&')); - + $query=array('private_token' => $this->token); + if (!is_null($this->sudo)) { + $query['sudo'] = $this->sudo; + } + $url .= (false === strpos($url, '?') ? '?' : '&').utf8_encode(http_build_query($query, '', '&')); + $request->fromUrl(new Url($url)); break; }