-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from packagist/vendor-bundles-api
API: add endpoints to manage vendor bundles
- Loading branch information
Showing
11 changed files
with
618 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/* | ||
* (c) Packagist Conductors GmbH <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace PrivatePackagist\ApiClient\Api\Customers; | ||
|
||
use PrivatePackagist\ApiClient\Api\AbstractApi; | ||
|
||
class VendorBundles extends AbstractApi | ||
{ | ||
public function listVendorBundles($customerIdOrUrlName) | ||
{ | ||
return $this->get(sprintf('/customers/%s/vendor-bundles/', $customerIdOrUrlName)); | ||
} | ||
|
||
/** | ||
* @param int|string $customerIdOrUrlName | ||
* @param int $vendorBundleId | ||
* @param null|string $expirationDate | ||
*/ | ||
public function addOrEditVendorBundle($customerIdOrUrlName, $vendorBundleId, $expirationDate = null) | ||
{ | ||
return $this->post(sprintf('/customers/%s/vendor-bundles/', $customerIdOrUrlName), [ | ||
'vendorBundleId' => $vendorBundleId, | ||
'expirationDate' => $expirationDate, | ||
]); | ||
} | ||
|
||
/** | ||
* @param int|string $customerIdOrUrlName | ||
* @param int $vendorBundleId | ||
*/ | ||
public function removeVendorBundle($customerIdOrUrlName, $vendorBundleId) | ||
{ | ||
return $this->delete(sprintf('/customers/%s/vendor-bundles/%s/', $customerIdOrUrlName, $vendorBundleId)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
<?php | ||
|
||
/* | ||
* (c) Packagist Conductors GmbH <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace PrivatePackagist\ApiClient\Api; | ||
|
||
class Synchronizations extends AbstractApi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
/* | ||
* (c) Packagist Conductors GmbH <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace PrivatePackagist\ApiClient\Api; | ||
|
||
class VendorBundles extends AbstractApi | ||
{ | ||
/** | ||
* @return array[] | ||
*/ | ||
public function all() | ||
{ | ||
return $this->get('/vendor-bundles/'); | ||
} | ||
|
||
/** | ||
* @param int $vendorBundleId | ||
* @return array | ||
*/ | ||
public function show($vendorBundleId) | ||
{ | ||
return $this->get(sprintf('/vendor-bundles/%s/', $vendorBundleId)); | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param string|null $minimumAccessibleStability | ||
* @param string|null $versionConstraint | ||
* @param bool $assignAllPackages | ||
* @param int[] $synchronizationIds | ||
*/ | ||
public function create($name, $minimumAccessibleStability = null, $versionConstraint = null, $assignAllPackages = false, array $synchronizationIds = []) | ||
{ | ||
return $this->post('/vendor-bundles/', [ | ||
'name' => $name, | ||
'minimumAccessibleStability' => $minimumAccessibleStability, | ||
'versionConstraint' => $versionConstraint, | ||
'assignAllPackages' => $assignAllPackages, | ||
'synchronizationIds' => $synchronizationIds, | ||
]); | ||
} | ||
|
||
/** | ||
* @param int $vendorBundleId | ||
* @param array{name: string, minimumAccessibleStability?: string, versionConstraint?: string, assignAllPackages: bool, synchronizationIds?: int[]} $bundle | ||
* @return array | ||
*/ | ||
public function edit($vendorBundleId, array $bundle) | ||
{ | ||
return $this->put(sprintf('/vendor-bundles/%s/', $vendorBundleId), $bundle); | ||
} | ||
|
||
/** | ||
* @param int $vendorBundleId | ||
*/ | ||
public function remove($vendorBundleId) | ||
{ | ||
return $this->delete(sprintf('/vendor-bundles/%s/', $vendorBundleId)); | ||
} | ||
|
||
public function packages(): \PrivatePackagist\ApiClient\Api\VendorBundles\Packages | ||
{ | ||
return new \PrivatePackagist\ApiClient\Api\VendorBundles\Packages($this->client); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/* | ||
* (c) Packagist Conductors GmbH <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace PrivatePackagist\ApiClient\Api\VendorBundles; | ||
|
||
use PrivatePackagist\ApiClient\Api\AbstractApi; | ||
use PrivatePackagist\ApiClient\Exception\InvalidArgumentException; | ||
|
||
class Packages extends AbstractApi | ||
{ | ||
/** | ||
* @param int $vendorBundleIds | ||
* @return array[] | ||
*/ | ||
public function listPackages($vendorBundleIds) | ||
{ | ||
return $this->get(sprintf('/vendor-bundles/%s/packages/', $vendorBundleIds)); | ||
} | ||
|
||
/** | ||
* @param int $vendorBundleId | ||
* @param array{name: string, versionConstraint?: string, minimumAccessibleStability?: string}[] $packages | ||
* @return array[] | ||
*/ | ||
public function addOrEditPackages($vendorBundleId, array $packages) | ||
{ | ||
foreach ($packages as $package) { | ||
if (!isset($package['name'])) { // @phpstan-ignore-line | ||
throw new InvalidArgumentException('Parameter "name" is required.'); | ||
} | ||
} | ||
|
||
return $this->post(sprintf('/vendor-bundles/%s/packages/', $vendorBundleId), $packages); | ||
} | ||
|
||
/** | ||
* @param int $vendorBundleId | ||
* @param string $packageName | ||
*/ | ||
public function removePackage($vendorBundleId, $packageName) | ||
{ | ||
return $this->delete(sprintf('/vendor-bundles/%s/packages/%s/', $vendorBundleId, $packageName)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace PrivatePackagist\ApiClient\Api\Customers; | ||
|
||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PrivatePackagist\ApiClient\Api\ApiTestCase; | ||
|
||
class VendorBundlesTest extends ApiTestCase | ||
{ | ||
public function testListVendorBundles() | ||
{ | ||
$expected = [ | ||
[ | ||
'expirationDate' => null, | ||
'vendorBundle' => ['id' => 12], | ||
], | ||
]; | ||
|
||
/** @var VendorBundles&MockObject $api */ | ||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with($this->equalTo('/customers/1/vendor-bundles/')) | ||
->willReturn($expected); | ||
|
||
$this->assertSame($expected, $api->listVendorBundles(1)); | ||
} | ||
|
||
public function testAddOrEditVendorBundle() | ||
{ | ||
$expected = [ | ||
'expirationDate' => null, | ||
'vendorBundle' => ['id' => 12], | ||
]; | ||
|
||
/** @var VendorBundles&MockObject $api */ | ||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('post') | ||
->with($this->equalTo('/customers/1/vendor-bundles/'), $this->equalTo([ | ||
'vendorBundleId' => 12, | ||
'expirationDate' => null, | ||
])) | ||
->willReturn($expected); | ||
|
||
$this->assertSame($expected, $api->addOrEditVendorBundle(1, 12)); | ||
} | ||
|
||
public function testRemoveVendorBundle() | ||
{ | ||
$expected = ''; | ||
|
||
/** @var VendorBundles&MockObject $api */ | ||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('delete') | ||
->with($this->equalTo(sprintf('/customers/1/vendor-bundles/%s/', 12))) | ||
->willReturn($expected); | ||
|
||
$this->assertSame($expected, $api->removeVendorBundle(1, 12)); | ||
} | ||
|
||
protected function getApiClass() | ||
{ | ||
return VendorBundles::class; | ||
} | ||
} |
Oops, something went wrong.