Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,26 @@ $job = $client->jobs()->show($jobId);
```
Returns the job.

#### Magento legacy keys

##### List all legacy keys for a customer
```php
$customerId = 42;
$job = $client->customers()->magentoLegacyKeys()->all($customerId);
```
Returns a list of Magento legacy keys.

##### Create a new legacy keys for a customer
```php
$job = $client->customers()->magentoLegacyKeys()->create($customerId, $publicKey, $privateKey);
```
Returns the new Magento legacy key.

##### Delete a legacy keys from a customer
```php
$job = $client->customers()->magentoLegacyKeys()->remove($customerId, $publicKey);
```

## License

`private-packagist/api-client` is licensed under the MIT License
6 changes: 6 additions & 0 deletions src/Api/Customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PrivatePackagist\ApiClient\Api;

use PrivatePackagist\ApiClient\Api\Customers\MagentoLegacyKeys;
use PrivatePackagist\ApiClient\Exception\InvalidArgumentException;

class Customers extends AbstractApi
Expand Down Expand Up @@ -84,4 +85,9 @@ public function regenerateToken($customerIdOrUrlName, array $confirmation)

return $this->post(sprintf('/customers/%s/token/regenerate', $customerIdOrUrlName), $confirmation);
}

public function magentoLegacyKeys()
{
return new MagentoLegacyKeys($this->client);
}
}
26 changes: 26 additions & 0 deletions src/Api/Customers/MagentoLegacyKeys.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace PrivatePackagist\ApiClient\Api\Customers;

use PrivatePackagist\ApiClient\Api\AbstractApi;

class MagentoLegacyKeys extends AbstractApi
{
public function all($customerIdOrUrlName)
{
return $this->get(sprintf('/api/customers/%s/magento-legacy-keys/', $customerIdOrUrlName));
}

public function create($customerIdOrUrlName, $publicKey, $privateKey)
{
return $this->post(sprintf('/api/customers/%s/magento-legacy-keys/', $customerIdOrUrlName), [
'publicKey' => $publicKey,
'privateKey' => $privateKey,
]);
}

public function remove($customerIdOrUrlName, $publicKey)
{
return $this->delete(sprintf('/api/customers/%s/magento-legacy-keys/%s/', $customerIdOrUrlName, $publicKey));
}
}
63 changes: 63 additions & 0 deletions tests/Api/Customers/MagentoLegacyKeysTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace PrivatePackagist\ApiClient\Api\Customers;

use PrivatePackagist\ApiClient\Api\ApiTestCase;

class MagentoLegacyKeysTest extends ApiTestCase
{
public function testAll()
{
$expected = [
[
'publicKey' => 'public-jdgkfdgk233443554mn45',
'privateKey' => 'private-fjdgkfdgk233443554mn45',
],
];

/** @var MagentoLegacyKeys&\PHPUnit_Framework_MockObject_MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with($this->equalTo('/api/customers/13/magento-legacy-keys/'))
->willReturn($expected);

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

public function testCreate()
{
$expected = [
'publicKey' => 'public-jdgkfdgk233443554mn45',
'privateKey' => 'private-fjdgkfdgk233443554mn45',
];

/** @var MagentoLegacyKeys&\PHPUnit_Framework_MockObject_MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with($this->equalTo('/api/customers/13/magento-legacy-keys/'), $this->equalTo($expected))
->willReturn($expected);

$this->assertSame($expected, $api->create(13, 'public-jdgkfdgk233443554mn45', 'private-fjdgkfdgk233443554mn45'));
}

public function testRemove()
{
$expected = [];

/** @var MagentoLegacyKeys&\PHPUnit_Framework_MockObject_MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
->with($this->equalTo('/api/customers/13/magento-legacy-keys/public-jdgkfdgk233443554mn45/'))
->willReturn($expected);

$this->assertSame($expected, $api->remove(13, 'public-jdgkfdgk233443554mn45'));
}

protected function getApiClass()
{
return MagentoLegacyKeys::class;
}
}