1111
1212use PrivatePackagist \ApiClient \Api \Packages \Artifacts ;
1313use PrivatePackagist \ApiClient \Exception \InvalidArgumentException ;
14+ use PrivatePackagist \ApiClient \Payload \ArtifactPackageConfig ;
15+ use PrivatePackagist \ApiClient \Payload \CustomPackageConfig ;
16+ use PrivatePackagist \ApiClient \Payload \VcsPackageConfig ;
1417
1518class Packages extends AbstractApi
1619{
@@ -55,23 +58,25 @@ public function show($packageName)
5558 return $ this ->get (sprintf ('/packages/%s/ ' , $ packageName ));
5659 }
5760
58- public function createVcsPackage ($ url , $ credentialId = null , $ type = 'vcs ' )
61+ public function createVcsPackage ($ url , $ credentialId = null , $ type = 'vcs ' , $ defaultSubrepositoryAccess = null )
5962 {
60- return $ this ->post ('/packages/ ' , ['repoType ' => $ type , 'repoUrl ' => $ url , 'credentials ' => $ credentialId ]);
63+ $ data = new VcsPackageConfig ($ url , $ credentialId , $ type , $ defaultSubrepositoryAccess );
64+
65+ return $ this ->post ('/packages/ ' , $ data ->toParameters ());
6166 }
6267
63- public function createCustomPackage ($ customJson , $ credentialId = null )
68+ public function createCustomPackage ($ customJson , $ credentialId = null , $ defaultSubrepositoryAccess = null )
6469 {
65- if (is_array ($ customJson ) || is_object ($ customJson )) {
66- $ customJson = json_encode ($ customJson );
67- }
70+ $ data = new CustomPackageConfig ($ customJson , $ credentialId , $ defaultSubrepositoryAccess );
6871
69- return $ this ->post ('/packages/ ' , [ ' repoType ' => ' package ' , ' repoConfig ' => $ customJson , ' credentials ' => $ credentialId ] );
72+ return $ this ->post ('/packages/ ' , $ data -> toParameters () );
7073 }
7174
72- public function createArtifactPackage (array $ artifactPackageFileIds )
75+ public function createArtifactPackage (array $ artifactPackageFileIds, $ defaultSubrepositoryAccess = null )
7376 {
74- return $ this ->post ('/packages/ ' , ['repoType ' => 'artifact ' , 'artifactIds ' => $ artifactPackageFileIds ]);
77+ $ data = new ArtifactPackageConfig ($ artifactPackageFileIds , $ defaultSubrepositoryAccess );
78+
79+ return $ this ->post ('/packages/ ' , $ data ->toParameters ());
7580 }
7681
7782 /**
@@ -82,27 +87,33 @@ public function updateVcsPackage($packageName, $url, $credentialId = null)
8287 return $ this ->editVcsPackage ($ packageName , $ url , $ credentialId );
8388 }
8489
85- public function editVcsPackage ($ packageName , $ url , $ credentialId = null , $ type = 'vcs ' )
90+ public function editVcsPackage ($ packageName , $ url , $ credentialId = null , $ type = 'vcs ' , $ defaultSubrepositoryAccess = null )
8691 {
87- return $ this ->put (sprintf ('/packages/%s/ ' , $ packageName ), ['repoType ' => $ type , 'repoUrl ' => $ url , 'credentials ' => $ credentialId ]);
92+ $ data = new VcsPackageConfig ($ url , $ credentialId , $ type , $ defaultSubrepositoryAccess );
93+
94+ return $ this ->put (sprintf ('/packages/%s/ ' , $ packageName ), $ data ->toParameters ());
8895 }
8996
90- public function editArtifactPackage ($ packageName , array $ artifactPackageFileIds )
97+ public function editArtifactPackage ($ packageName , array $ artifactPackageFileIds, $ defaultSubrepositoryAccess = null )
9198 {
92- return $ this ->put (sprintf ('/packages/%s/ ' , $ packageName ), ['repoType ' => 'artifact ' , 'artifactIds ' => $ artifactPackageFileIds ]);
99+ $ data = new ArtifactPackageConfig ($ artifactPackageFileIds , $ defaultSubrepositoryAccess );
100+
101+ return $ this ->put (sprintf ('/packages/%s/ ' , $ packageName ), $ data ->toParameters ());
93102 }
94103
95104 /**
96105 * @deprecated Use editCustomPackage instead
97106 */
98107 public function updateCustomPackage ($ packageName , $ customJson , $ credentialId = null )
99108 {
100- return $ this ->editVcsPackage ($ packageName , $ customJson , $ credentialId );
109+ return $ this ->editCustomPackage ($ packageName , $ customJson , $ credentialId );
101110 }
102111
103- public function editCustomPackage ($ packageName , $ customJson , $ credentialId = null )
112+ public function editCustomPackage ($ packageName , $ customJson , $ credentialId = null , $ defaultSubrepositoryAccess = null )
104113 {
105- return $ this ->put (sprintf ('/packages/%s/ ' , $ packageName ), ['repoType ' => 'package ' , 'repoConfig ' => $ customJson , 'credentials ' => $ credentialId ]);
114+ $ data = new CustomPackageConfig ($ customJson , $ credentialId , $ defaultSubrepositoryAccess );
115+
116+ return $ this ->put (sprintf ('/packages/%s/ ' , $ packageName ), $ data ->toParameters ());
106117 }
107118
108119 public function remove ($ packageName )
0 commit comments