diff --git a/lib/Gitlab/Api/DeployKeys.php b/lib/Gitlab/Api/DeployKeys.php new file mode 100644 index 000000000..f7e2a39d5 --- /dev/null +++ b/lib/Gitlab/Api/DeployKeys.php @@ -0,0 +1,24 @@ +get('deploy_keys', array( + 'page' => $page, + 'per_page' => $per_page, + 'order_by' => $order_by, + 'sort' => $sort + )); + } +} diff --git a/lib/Gitlab/Api/Projects.php b/lib/Gitlab/Api/Projects.php index 8b963a58c..43e7111a0 100644 --- a/lib/Gitlab/Api/Projects.php +++ b/lib/Gitlab/Api/Projects.php @@ -339,6 +339,26 @@ public function removeKey($project_id, $key_id) return $this->delete($this->getProjectPath($project_id, 'keys/'.$this->encodePath($key_id))); } + /** + * @param int $project_id + * @param int $key_id + * @return mixed + */ + public function enableKey($project_id, $key_id) + { + return $this->post($this->getProjectPath($project_id, 'keys/'.$this->encodePath($key_id).'/enable')); + } + + /** + * @param int $project_id + * @param int $key_id + * @return mixed + */ + public function disableKey($project_id, $key_id) + { + return $this->delete($this->getProjectPath($project_id, 'keys/'.$this->encodePath($key_id).'/disable')); + } + /** * @param int $project_id * @param int $page diff --git a/lib/Gitlab/Client.php b/lib/Gitlab/Client.php index c7e179b10..94674b96f 100644 --- a/lib/Gitlab/Client.php +++ b/lib/Gitlab/Client.php @@ -101,6 +101,10 @@ public function api($name) { switch ($name) { + case 'deploy_keys': + $api = new Api\DeployKeys($this); + break; + case 'groups': $api = new Api\Groups($this); break; diff --git a/lib/Gitlab/Model/Project.php b/lib/Gitlab/Model/Project.php index a412a1889..14f9ca891 100644 --- a/lib/Gitlab/Model/Project.php +++ b/lib/Gitlab/Model/Project.php @@ -346,6 +346,28 @@ public function removeKey($key_id) return true; } + /** + * @param string $key_id + * @return bool + */ + public function enableKey($key_id) + { + $this->api('projects')->enableKey($this->id, $key_id); + + return true; + } + + /** + * @param string $key_id + * @return bool + */ + public function disableKey($key_id) + { + $this->api('projects')->disableKey($this->id, $key_id); + + return true; + } + /** * @param string $name * @param string $ref diff --git a/test/Gitlab/Tests/Api/DeployKeysTest.php b/test/Gitlab/Tests/Api/DeployKeysTest.php new file mode 100644 index 000000000..a17dd312c --- /dev/null +++ b/test/Gitlab/Tests/Api/DeployKeysTest.php @@ -0,0 +1,51 @@ +getMultipleDeployKeysData(); + + $api = $this->getMultipleDeployKeysRequestMock('deploy_keys', $expectedArray); + + $this->assertEquals($expectedArray, $api->all()); + } + + protected function getMultipleDeployKeysRequestMock($path, $expectedArray = array(), $page = 1, $per_page = 20, $order_by = 'id', $sort = 'asc') + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with($path, array('page' => $page, 'per_page' => $per_page, 'order_by' => $order_by, 'sort' => $sort)) + ->will($this->returnValue($expectedArray)) + ; + + return $api; + } + + protected function getMultipleDeployKeysData() + { + return array( + array( + 'id' => 1, + 'title' => 'Public key', + 'key' => 'ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=', + 'created_at' => '2013-10-02T10:12:29Z' + ), + array( + 'id' => 3, + 'title' => 'Another Public key', + 'key' => 'ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=', + 'created_at' => '2013-10-02T11:12:29Z' + ) + ); + } + + protected function getApiClass() + { + return 'Gitlab\Api\DeployKeys'; + } +} diff --git a/test/Gitlab/Tests/Api/ProjectsTest.php b/test/Gitlab/Tests/Api/ProjectsTest.php index 1973315cd..fb5a5ec33 100644 --- a/test/Gitlab/Tests/Api/ProjectsTest.php +++ b/test/Gitlab/Tests/Api/ProjectsTest.php @@ -606,6 +606,40 @@ public function shouldRemoveKey() $this->assertEquals($expectedBool, $api->removeKey(1, 3)); } + /** + * @test + */ + public function shoudEnableKey() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/keys/3/enable') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->enableKey(1, 3)); + } + + /** + * @test + */ + public function shoudDisableKey() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('projects/1/keys/3/disable') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->disableKey(1, 3)); + } + /** * @test */