Commit 681db60c authored by Mikael Löwgren's avatar Mikael Löwgren

Implemented create folder

parent 41ab8073
......@@ -9,15 +9,17 @@ use QBNK\MarketoApi\Model\FolderResponse;
class FolderController extends BaseController {
protected $rootFolderId = '10092';
/**
* @param string|null $rootFolderId
* @return FolderResponse[]
*/
public function list(string $rootFolderId = null ): array {
public function list(int $rootFolderId ): array {
$queryParameters['root'] = "{ \"id\":".$parentFolderId.", \"type\":\"Folder\"}";
$queryParameters['maxDepth'] = '2';
$queryParameters['maxReturn'] = '20';
//TODO need to loop and page
$queryParameters['root'] = "{ \"id\":".$rootFolderId.", \"type\":\"Folder\"}";
$queryParameters['maxDepth'] = '20';
$queryParameters['maxReturn'] = '200';
$queryParameters['offset'] = '0';
$queryParameters['workspace'] = '';
......@@ -35,20 +37,20 @@ class FolderController extends BaseController {
}
/**
* TODO: Implement for Marketo. ../folders.json might not be the correct create for folders
* @param Folder $folder
* @return FolderResponse
*/
public function create(Folder $folder): FolderResponse {
$response = $this->apiHttpClient->post('/rest/asset/v1/folders.json', ['json' => $folder]);
$folderId = \GuzzleHttp\json_decode($response->getBody(), true);
return FolderResponse::fromArray([
'id' => $folderId,
'name' => $folder->getName(),
'parentFolderId' => $folder->getParentFolderId(),
'navigationPath' => ''
]);
}
$queryParameters['parent'] = "{ \"id\":".$folder->getParentFolderId().", \"type\":\"Folder\"}";
$queryParameters['name'] = $folder->getName();
$response = $this->apiHttpClient->post('/rest/asset/v1/folders.json', [RequestOptions::QUERY => $queryParameters]);
$responseData = \GuzzleHttp\json_decode($response->getBody(), true);
$folderId = $responseData['result']['id'];
return FolderResponse::fromArray( reset($responseData['result']) );
}
/**
* TODO: Check API for get operation. This is not correct.
......@@ -58,7 +60,7 @@ class FolderController extends BaseController {
public function get(string $id): FolderResponse {
$response = $this->apiHttpClient->get('/rest/asset/v1/folders.json'.$id);
$responseData = \GuzzleHttp\json_decode($response->getBody(), true);
return FolderResponse::fromArray($responseData);
return FolderResponse::fromArray( reset($responseData['result']) );
}
/**
......@@ -76,6 +78,6 @@ class FolderController extends BaseController {
* @return FolderResponse
*/
public function delete(string $id): void {
$this->apiHttpClient->delete('/folders/'.$id);
$this->apiHttpClient->delete('/rest/asset/v1/folder/'.$id.'/delete.json');
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment