Skip to content

Commit 65f304d

Browse files
committed
Magento: add legacy keys endpoints to list, create and delete entries
1 parent d12ebbf commit 65f304d

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed

Diff for: README.md

+20
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,26 @@ $job = $client->jobs()->show($jobId);
341341
```
342342
Returns the job.
343343

344+
#### Magento legacy keys
345+
346+
##### List all legacy keys for a customer
347+
```php
348+
$customerId = 42;
349+
$job = $client->customers()->magentoLegacyKeys()->all($customerId);
350+
```
351+
Returns a list of Magento legacy keys.
352+
353+
##### Create a new legacy keys for a customer
354+
```php
355+
$job = $client->customers()->magentoLegacyKeys()->create($customerId, $publicKey, $privateKey);
356+
```
357+
Returns the new Magento legacy key.
358+
359+
##### Delete a legacy keys from a customer
360+
```php
361+
$job = $client->customers()->magentoLegacyKeys()->remove($customerId, $publicKey);
362+
```
363+
344364
## License
345365

346366
`private-packagist/api-client` is licensed under the MIT License

Diff for: src/Api/Customers.php

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PrivatePackagist\ApiClient\Api;
44

5+
use PrivatePackagist\ApiClient\Api\Customers\MagentoLegacyKeys;
56
use PrivatePackagist\ApiClient\Exception\InvalidArgumentException;
67

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

8586
return $this->post(sprintf('/customers/%s/token/regenerate', $customerIdOrUrlName), $confirmation);
8687
}
88+
89+
public function magentoLegacyKeys()
90+
{
91+
return new MagentoLegacyKeys($this->client);
92+
}
8793
}

Diff for: src/Api/Customers/MagentoLegacyKeys.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace PrivatePackagist\ApiClient\Api\Customers;
4+
5+
use PrivatePackagist\ApiClient\Api\AbstractApi;
6+
7+
class MagentoLegacyKeys extends AbstractApi
8+
{
9+
public function all($customerIdOrUrlName)
10+
{
11+
return $this->get(sprintf('/api/customers/%s/magento-legacy-keys/', $customerIdOrUrlName));
12+
}
13+
14+
public function create($customerIdOrUrlName, $publicKey, $privateKey)
15+
{
16+
return $this->post(sprintf('/api/customers/%s/magento-legacy-keys/', $customerIdOrUrlName), [
17+
'publicKey' => $publicKey,
18+
'privateKey' => $privateKey,
19+
]);
20+
}
21+
22+
public function remove($customerIdOrUrlName, $publicKey)
23+
{
24+
return $this->delete(sprintf('/api/customers/%s/magento-legacy-keys/%s/', $customerIdOrUrlName, $publicKey));
25+
}
26+
}

Diff for: tests/Api/Customers/MagentoLegacyKeysTest.php

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace PrivatePackagist\ApiClient\Api\Customers;
4+
5+
use PrivatePackagist\ApiClient\Api\ApiTestCase;
6+
7+
class MagentoLegacyKeysTest extends ApiTestCase
8+
{
9+
public function testAll()
10+
{
11+
$expected = [
12+
[
13+
'publicKey' => 'public-jdgkfdgk233443554mn45',
14+
'privateKey' => 'private-fjdgkfdgk233443554mn45',
15+
],
16+
];
17+
18+
/** @var MagentoLegacyKeys&\PHPUnit_Framework_MockObject_MockObject $api */
19+
$api = $this->getApiMock();
20+
$api->expects($this->once())
21+
->method('get')
22+
->with($this->equalTo('/api/customers/13/magento-legacy-keys/'))
23+
->willReturn($expected);
24+
25+
$this->assertSame($expected, $api->all(13));
26+
}
27+
28+
public function testCreate()
29+
{
30+
$expected = [
31+
'publicKey' => 'public-jdgkfdgk233443554mn45',
32+
'privateKey' => 'private-fjdgkfdgk233443554mn45',
33+
];
34+
35+
/** @var MagentoLegacyKeys&\PHPUnit_Framework_MockObject_MockObject $api */
36+
$api = $this->getApiMock();
37+
$api->expects($this->once())
38+
->method('post')
39+
->with($this->equalTo('/api/customers/13/magento-legacy-keys/'), $this->equalTo($expected))
40+
->willReturn($expected);
41+
42+
$this->assertSame($expected, $api->create(13, 'public-jdgkfdgk233443554mn45', 'private-fjdgkfdgk233443554mn45'));
43+
}
44+
45+
public function testRemove()
46+
{
47+
$expected = [];
48+
49+
/** @var MagentoLegacyKeys&\PHPUnit_Framework_MockObject_MockObject $api */
50+
$api = $this->getApiMock();
51+
$api->expects($this->once())
52+
->method('delete')
53+
->with($this->equalTo('/api/customers/13/magento-legacy-keys/public-jdgkfdgk233443554mn45/'))
54+
->willReturn($expected);
55+
56+
$this->assertSame($expected, $api->remove(13, 'public-jdgkfdgk233443554mn45'));
57+
}
58+
59+
protected function getApiClass()
60+
{
61+
return MagentoLegacyKeys::class;
62+
}
63+
}

0 commit comments

Comments
 (0)