Skip to content

Commit

Permalink
Organization: add synchronization call
Browse files Browse the repository at this point in the history
  • Loading branch information
glaubinix committed Jun 21, 2018
1 parent d868141 commit 1a8044f
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ From `$client` object, you can access the full Private Packagist API.

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

#### Organization

##### Trigger a full synchronization
```php
$client->organization()->sync();
```

#### Customer

##### List an organization's customers
Expand Down
20 changes: 20 additions & 0 deletions src/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ protected function post($path, array $parameters = [], array $headers = [])
return $this->responseMediator->getContent($response);
}

/**
* @param string $path
* @param array $parameters
* @param array $headers
* @return array|string
*/
protected function put($path, array $parameters = [], array $headers = [])
{
$response = $this->client->getHttpClient()->put(
$path,
array_merge($headers, [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
]),
$this->createJsonBody($parameters)
);

return $this->responseMediator->getContent($response);
}

/**
* @param string $path
* @param array $parameters
Expand Down
11 changes: 11 additions & 0 deletions src/Api/Organization.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace PrivatePackagist\ApiClient\Api;

class Organization extends AbstractApi
{
public function sync()
{
return $this->put('/organization/sync');
}
}
5 changes: 5 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public function customers()
return new Api\Customers($this, $this->responseMediator);
}

public function organization()
{
return new Api\Organization($this, $this->responseMediator);
}

public function packages()
{
return new Api\Packages($this, $this->responseMediator);
Expand Down
28 changes: 28 additions & 0 deletions tests/Api/OrganizationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace PrivatePackagist\ApiClient\Api;

class OrganizationTest extends ApiTestCase
{
public function testSync()
{
$expected = [];

/** @var Organization&\PHPUnit_Framework_MockObject_MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('put')
->with($this->equalTo('/organization/sync'))
->will($this->returnValue($expected));

$this->assertSame($expected, $api->sync());
}

/**
* @return string
*/
protected function getApiClass()
{
return Organization::class;
}
}

0 comments on commit 1a8044f

Please sign in to comment.