Skip to content

Commit 1a8044f

Browse files
committed
Organization: add synchronization call
1 parent d868141 commit 1a8044f

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ From `$client` object, you can access the full Private Packagist API.
3434

3535
Full documentation can be found in the [Private Packagist documentation](https://packagist.com/docs/api).
3636

37+
#### Organization
38+
39+
##### Trigger a full synchronization
40+
```php
41+
$client->organization()->sync();
42+
```
43+
3744
#### Customer
3845

3946
##### List an organization's customers

src/Api/AbstractApi.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,26 @@ protected function post($path, array $parameters = [], array $headers = [])
6060
return $this->responseMediator->getContent($response);
6161
}
6262

63+
/**
64+
* @param string $path
65+
* @param array $parameters
66+
* @param array $headers
67+
* @return array|string
68+
*/
69+
protected function put($path, array $parameters = [], array $headers = [])
70+
{
71+
$response = $this->client->getHttpClient()->put(
72+
$path,
73+
array_merge($headers, [
74+
'Accept' => 'application/json',
75+
'Content-Type' => 'application/json',
76+
]),
77+
$this->createJsonBody($parameters)
78+
);
79+
80+
return $this->responseMediator->getContent($response);
81+
}
82+
6383
/**
6484
* @param string $path
6585
* @param array $parameters

src/Api/Organization.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace PrivatePackagist\ApiClient\Api;
4+
5+
class Organization extends AbstractApi
6+
{
7+
public function sync()
8+
{
9+
return $this->put('/organization/sync');
10+
}
11+
}

src/Client.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public function customers()
4848
return new Api\Customers($this, $this->responseMediator);
4949
}
5050

51+
public function organization()
52+
{
53+
return new Api\Organization($this, $this->responseMediator);
54+
}
55+
5156
public function packages()
5257
{
5358
return new Api\Packages($this, $this->responseMediator);

tests/Api/OrganizationTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace PrivatePackagist\ApiClient\Api;
4+
5+
class OrganizationTest extends ApiTestCase
6+
{
7+
public function testSync()
8+
{
9+
$expected = [];
10+
11+
/** @var Organization&\PHPUnit_Framework_MockObject_MockObject $api */
12+
$api = $this->getApiMock();
13+
$api->expects($this->once())
14+
->method('put')
15+
->with($this->equalTo('/organization/sync'))
16+
->will($this->returnValue($expected));
17+
18+
$this->assertSame($expected, $api->sync());
19+
}
20+
21+
/**
22+
* @return string
23+
*/
24+
protected function getApiClass()
25+
{
26+
return Organization::class;
27+
}
28+
}

0 commit comments

Comments
 (0)