PHP code example of nmirceac / api-client-tools

1. Go to this page and download the library: Download nmirceac/api-client-tools library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nmirceac / api-client-tools example snippets


return \App\Api\Project::get(3)['thumbnail'];
// ApiClientTools\App\ApiImageStore {#284 ▼
//  +modifierString: null
//  +"id": 22
//  +"hash": "db16b0f3fe1533135914df5fa455e3c5"
//  +"name": "Collaboration Maersk 001"
//  +"type": "jpeg"
//  +"size": 48227
//  +"width": 471
//  +"height": 471
//  +"metadata": array:12 [▶]
//  +"colors": array:5 [▶]
//  +"created_at": "2019-12-12 14:37:06"
//  +"updated_at": "2019-12-12 14:37:08"
//  +"canDelete": true
//  +"orientation": "L"
//  +"basename": "Collaboration Maersk 001.jpeg"
//  +"details": array:1 [▶]
//  +"pivot": array:6 [▶]
//  +"url": "https://admin-collaboration.weanswer.it/images/db16b0f3fe1533135914df5fa455e3c5.jpeg"
//}

return \App\Api\Project::get(3)['thumbnail']->url;
// https://admin-collaboration.weanswer.it/images/db16b0f3fe1533135914df5fa455e3c5.jpeg

$thumbnail=\App\Api\Project::get(3)['thumbnail'];
$thumbnail->modifyImage(function(\ColorTools\Image $img) {
    $img->fit(100, 100);
});
return $thumbnail->publish();
// https://admin-collaboration.weanswer.it/images/db16b0f3fe1533135914df5fa455e3c5-ft=100+100.jpeg

$thumbnail=\App\Api\Project::get(3)['thumbnail'];
return $thumbnail->modifyImage(function(\ColorTools\Image $img) {
    $img->fit(100, 100);
})->publish();
// https://admin-collaboration.weanswer.it/images/db16b0f3fe1533135914df5fa455e3c5-ft=100+100.jpeg

$thumbnail=\App\Api\Project::get(3)['thumbnail'];
return $thumbnail->modifyImage(function(\ColorTools\Image $img) {
    $img->fit(100, 100);
})->publish('png');
// https://admin-collaboration.weanswer.it/images/db16b0f3fe1533135914df5fa455e3c5-ft=100+100.png

$thumbnail=\App\Api\Project::get(3)['thumbnail'];
$thumbnail->modifyImagePublish(function(\ColorTools\Image $img) {
    $img->fit(100, 100);
});
// https://admin-collaboration.weanswer.it/images/db16b0f3fe1533135914df5fa455e3c5-ft=100+100.png

$thumbnail=\App\Api\Project::get(3)['thumbnail'];
$thumbnail->modifyImagePublish(function(\ColorTools\Image $img) {
    $img->fit(100, 100);
}, 'png');
// https://admin-collaboration.weanswer.it/images/db16b0f3fe1533135914df5fa455e3c5-ft=100+100.png

$thumbnail=\App\Api\Project::get(2)['thumbnail'];
$thumbnail->modifyImagePublish(function($img) {
    $img->fit(100, 100);
});
// https://admin-collaboration.weanswer.it/thumbnail/project/2-s=100x100.jpeg

$thumbnail=\App\Api\Project::get(2)['thumbnail'];
$thumbnail->modifyImagePublish(function($img) {
    $img->fit(400, 270);
}, 'png');
// https://admin-collaboration.weanswer.it/thumbnail/project/2-s=400x270.png

$thumbnail=\App\Api\Project::get(2)['thumbnail'];
$thumbnail->modifyImagePublish(function($img) {
    $img->fit(400, 270);
    $img->applyFilter(\ColorTools\Image::FILTER_GRAYSCALE);
});
// https://admin-collaboration.weanswer.it/thumbnail/project/2-s=400x270.jpeg

$thumbnail=\App\Api\Project::get(4)['thumbnail'];
$thumbnail->modifyImagePublish(function($img) {
    $img->fit(400, 270);
    $img->applyFilter(\ColorTools\Image::FILTER_GRAYSCALE);
});
// https://admin-collaboration.weanswer.it/images/45771d1cdfe109aa6e5b3fd48c925ebd-fi=1+-ft=400+270.jpeg

// you can create the payload from a file path
$filePayloadFromPath=\App\Api\Project::createFileFromPath('/path/to/file.extension');
// or from a request
$filePayloadFromRequest=\App\Api\Extension::createFileFromRequest(request(), 'file');


// you can also optionally specify the individual file role or order 
$anotherFilePayload==\App\Api\Project::createFileFromPath('/path/to/another.file', 'guide', 1);

// you can then just upload the files to the proper endpoing
\App\Api\Endpoint::attachFile($id, ['files'=>[$filePayloadFromPath, $filePayloadFromRequest, $anotherFilePayload]]);

// you can also create the file from string and populate your own metadata
\App\Api\Endpoint::createFilePayload($metadata, $fileContents);

$metadata should contain at least name, mime, extension and size