Skip to content

Commit 4018a93

Browse files
jamiehusonacrobat
authored andcommitted
Added missing Apps endpoints (#814)
* add Apps endpoint /apps/installations/:installation_id: * add Apps endpoint delete /apps/installations/:installation_id: * add Apps endpoint get /org/:org:/installation * add Apps endpoint get /repos/:owner/:repo/installation * add Apps endpoint get /users/:username/installation * fix styling of comments * use the configurePreviewHeader() function in newly added endpoints * switch to camel casing for some arg names
1 parent 2665eb8 commit 4018a93

File tree

2 files changed

+158
-1
lines changed

2 files changed

+158
-1
lines changed

lib/Github/Api/Apps.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,85 @@ public function findInstallations()
5353
return $this->get('/app/installations');
5454
}
5555

56+
/**
57+
* Get an installation of the application.
58+
*
59+
* @link https://developer.github.com/v3/apps/#get-an-installation
60+
*
61+
* @param $installationId An integration installation id
62+
*
63+
* @return array
64+
*/
65+
public function getInstallation($installationId)
66+
{
67+
$this->configurePreviewHeader();
68+
69+
return $this->get('/app/installations/'.rawurldecode($installationId));
70+
}
71+
72+
/**
73+
* Get an installation of the application for an organization.
74+
*
75+
* @link https://developer.github.com/v3/apps/#get-an-organization-installation
76+
*
77+
* @param $org An organization
78+
*
79+
* @return array
80+
*/
81+
public function getInstallationForOrganization($org)
82+
{
83+
$this->configurePreviewHeader();
84+
85+
return $this->get('/org/'.rawurldecode($org).'/installation');
86+
}
87+
88+
/**
89+
* Get an installation of the application for a repository.
90+
*
91+
* @link https://developer.github.com/v3/apps/#get-a-repository-installation
92+
*
93+
* @param $owner the owner of a repository
94+
* @param $repo the name of the repository
95+
*
96+
* @return array
97+
*/
98+
public function getInstallationForRepo($owner, $repo)
99+
{
100+
$this->configurePreviewHeader();
101+
102+
return $this->get('/repos/'.rawurldecode($owner).'/'.rawurldecode($repo).'/installation');
103+
}
104+
105+
/**
106+
* Get an installation of the application for a user.
107+
*
108+
* @link https://developer.github.com/v3/apps/#get-a-user-installation
109+
*
110+
* @param $username
111+
*
112+
* @return array
113+
*/
114+
public function getInstallationForUser($username)
115+
{
116+
$this->configurePreviewHeader();
117+
118+
return $this->get('/users/'.rawurldecode($username).'/installation');
119+
}
120+
121+
/**
122+
* Delete an installation of the application.
123+
*
124+
* @link https://developer.github.com/v3/apps/#delete-an-installation
125+
*
126+
* @param $installationId An integration installation id
127+
*/
128+
public function removeInstallation($installationId)
129+
{
130+
$this->configurePreviewHeader();
131+
132+
$this->delete('/app/installations/'.rawurldecode($installationId));
133+
}
134+
56135
/**
57136
* List repositories that are accessible to the authenticated installation.
58137
*

test/Github/Tests/Api/AppTest.php

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function shouldCreateInstallationTokenForInstallation()
2727
/**
2828
* @test
2929
*/
30-
public function shouldFindRepositoriesForApplication()
30+
public function shouldFindInstallationsForApplication()
3131
{
3232
$result = ['installation1', 'installation2'];
3333

@@ -40,6 +40,84 @@ public function shouldFindRepositoriesForApplication()
4040
$this->assertEquals($result, $api->findInstallations());
4141
}
4242

43+
/**
44+
* @test
45+
*/
46+
public function shouldGetInstallationForApplication()
47+
{
48+
$result = ['installation1'];
49+
50+
$api = $this->getApiMock();
51+
$api->expects($this->once())
52+
->method('get')
53+
->with('/app/installations/1234')
54+
->willReturn($result);
55+
56+
$this->assertEquals($result, $api->getInstallation('1234'));
57+
}
58+
59+
/**
60+
* @test
61+
*/
62+
public function shouldGetInstallationForOrganization()
63+
{
64+
$result = ['installation1'];
65+
66+
$api = $this->getApiMock();
67+
$api->expects($this->once())
68+
->method('get')
69+
->with('/org/1234/installation')
70+
->willReturn($result);
71+
72+
$this->assertEquals($result, $api->getInstallationForOrganization('1234'));
73+
}
74+
75+
/**
76+
* @test
77+
*/
78+
public function shouldGetInstallationForRepo()
79+
{
80+
$result = ['installation1'];
81+
82+
$api = $this->getApiMock();
83+
$api->expects($this->once())
84+
->method('get')
85+
->with('/repos/MyOrg/MyRepo/installation')
86+
->willReturn($result);
87+
88+
$this->assertEquals($result, $api->getInstallationForRepo('MyOrg', 'MyRepo'));
89+
}
90+
91+
/**
92+
* @test
93+
*/
94+
public function shouldGetInstallationForUser()
95+
{
96+
$result = ['installation1'];
97+
98+
$api = $this->getApiMock();
99+
$api->expects($this->once())
100+
->method('get')
101+
->with('/users/octocat/installation')
102+
->willReturn($result);
103+
104+
$this->assertEquals($result, $api->getInstallationForUser('octocat'));
105+
}
106+
107+
/**
108+
* @test
109+
*/
110+
public function shouldDeleteInstallationForApplication()
111+
{
112+
$id = 123;
113+
$api = $this->getApiMock();
114+
$api->expects($this->once())
115+
->method('delete')
116+
->with('/app/installations/'.$id);
117+
118+
$api->removeInstallation($id);
119+
}
120+
43121
/**
44122
* @test
45123
*/

0 commit comments

Comments
 (0)