Skip to content

Commit 477def1

Browse files
committed
Update package artifacts methods
1 parent d884503 commit 477def1

File tree

6 files changed

+40
-35
lines changed

6 files changed

+40
-35
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@
7070
* [Delete a package](#delete-a-package)
7171
* [List all dependents of a package](#list-all-dependents-of-a-package)
7272
* [List all customers with access to a package](#list-all-customers-with-access-to-a-package)
73-
* [Create a package uploaded file](#create-a-package-uploaded-file)
73+
* [Create an artifact package file](#create-an-artifact-package-file)
7474
* [Create an artifact package](#create-an-artifact-package)
75-
* [Update an artifact package files](#update-an-artifact-package-files)
75+
* [Update artifact files of a package](#update-artifact-files-of-a-package)
7676
* [Credential](#credential)
7777
* [List an organization's credentials](#list-an-organizations-credentials)
7878
* [Show a credential](#show-a-credential)
@@ -98,7 +98,7 @@
9898
* [Validate incoming webhook payloads](#validate-incoming-webhook-payloads)
9999
* [License](#license)
100100

101-
<!-- Added by: wissem, at: Tue Jul 14 11:42:54 CEST 2020 -->
101+
<!-- Added by: wissem, at: Tue Jul 21 10:32:47 CEST 2020 -->
102102

103103
<!--te-->
104104

@@ -583,22 +583,22 @@ Returns a list of customers with access to the package.
583583
```php
584584
$fileName = 'package1.zip'; // your package archive artifact containing a valid composer.json in root directory
585585
$file = file_get_contents($fileName);
586-
$client->packageArtifact()->create($file, 'application/zip', $fileName);
586+
$client->packages()->artifacts()->create($file, 'application/zip', $fileName);
587587
```
588588

589589
#### Create an artifact package
590590

591591
```php
592592
$fileName = 'package1.zip';
593593
$file = file_get_contents($fileName);
594-
$response = $client->packageArtifact()->create($file, 'application/zip', $fileName);
594+
$response = $client->packages()->artifacts()->create($file, 'application/zip', $fileName);
595595
$artifactId = $response['id'];
596596
$client->packages()->createArtifactPackage([$artifactId]);
597597
```
598-
#### Update an artifact package files
598+
#### Update artifact files of a package
599599

600600
```php
601-
$result = $client->packages()->showArtifacts('acme-website/package'); // get artifact files details for a package
601+
$result = $client->packages()->packages()->artifacts()->showPackageArtifacts('acme-website/package'); // get artifact files details for a package
602602
$artifactFileIds = [42, 43];
603603
$client->packages()->editArtifactPackage('acme-website/package', $artifactFileIds);
604604
```

src/Api/PackageArtifacts.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ public function show($artifactId)
2323
{
2424
return $this->get(sprintf('/packages/artifacts/%s/', $artifactId));
2525
}
26+
27+
public function showPackageArtifacts($packageName)
28+
{
29+
return $this->get(sprintf('/packages/%s/artifacts/', $packageName));
30+
}
2631
}

src/Api/Packages.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ public function show($packageName)
5454
return $this->get(sprintf('/packages/%s/', $packageName));
5555
}
5656

57-
public function showArtifacts($packageName)
58-
{
59-
return $this->get(sprintf('/packages/%s/artifacts/', $packageName));
60-
}
61-
6257
public function createVcsPackage($url, $credentialId = null, $type = 'vcs')
6358
{
6459
return $this->post('/packages/', ['repoType' => $type, 'repoUrl' => $url, 'credentials' => $credentialId]);
@@ -123,4 +118,9 @@ public function listDependents($packageName)
123118
{
124119
return $this->get(sprintf('/packages/%s/dependents/', $packageName));
125120
}
121+
122+
public function artifacts()
123+
{
124+
return new PackageArtifacts($this->client, $this->client->getResponseMediator());
125+
}
126126
}

src/Client.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ public function mirroredRepositories()
9898
return new Api\MirroredRepositories($this, $this->responseMediator);
9999
}
100100

101-
public function packageArtifact()
101+
public function getHttpClient()
102102
{
103-
return new Api\PackageArtifacts($this, $this->responseMediator);
103+
return $this->getHttpClientBuilder()->getHttpClient();
104104
}
105105

106-
public function getHttpClient()
106+
public function getResponseMediator()
107107
{
108-
return $this->getHttpClientBuilder()->getHttpClient();
108+
return $this->responseMediator;
109109
}
110110

111111
protected function getHttpClientBuilder()

tests/Api/PackagArtifactsTest.php renamed to tests/Api/PackageArtifactsTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace PrivatePackagist\ApiClient\Api;
1111

12-
class PackagArtifactsTest extends ApiTestCase
12+
class PackageArtifactsTest extends ApiTestCase
1313
{
1414
public function testCreate()
1515
{
@@ -50,6 +50,24 @@ public function testShow()
5050
$this->assertSame($expected, $api->show('1'));
5151
}
5252

53+
public function testShowPackageArtifacts()
54+
{
55+
$expected = [
56+
'name' => 'acme-website/package',
57+
'repoType' => 'artifact',
58+
'artifactFiles' => 'artifact',
59+
];
60+
61+
/** @var PackageArtifacts&\PHPUnit_Framework_MockObject_MockObject $api */
62+
$api = $this->getApiMock();
63+
$api->expects($this->once())
64+
->method('get')
65+
->with($this->equalTo('/packages/acme-website/package/artifacts/'))
66+
->willReturn($expected);
67+
68+
$this->assertSame($expected, $api->showPackageArtifacts('acme-website/package'));
69+
}
70+
5371
/**
5472
* @return string
5573
*/

tests/Api/PackagesTest.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,6 @@ public function testShow()
8787
$this->assertSame($expected, $api->show('acme-website/package'));
8888
}
8989

90-
public function testShowArtifacts()
91-
{
92-
$expected = [
93-
'name' => 'acme-website/package',
94-
'repoType' => 'artifact',
95-
'artifactIds' => 'artifact',
96-
];
97-
98-
/** @var Packages&\PHPUnit_Framework_MockObject_MockObject $api */
99-
$api = $this->getApiMock();
100-
$api->expects($this->once())
101-
->method('get')
102-
->with($this->equalTo('/packages/acme-website/package/artifacts/'))
103-
->willReturn($expected);
104-
105-
$this->assertSame($expected, $api->showArtifacts('acme-website/package'));
106-
}
107-
10890
public function testCreateVcsPackage()
10991
{
11092
$expected = [

0 commit comments

Comments
 (0)