Last active
December 14, 2021 16:53
-
-
Save PrestaEdit/56f75ca6fb5880672916890543a18f0a to your computer and use it in GitHub Desktop.
PrestaShop Validator API (Example)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "prestashop/validator", | |
"authors": [ | |
{ | |
"name": "Prestashop" | |
} | |
], | |
"require": { | |
"guzzlehttp/guzzle": "^7.0" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once __DIR__ . '/vendor/autoload.php'; | |
CONST VALIDATOR_URL = 'https://validator.prestashop.com'; | |
const VALIDATOR_API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; | |
$client = new \GuzzleHttp\Client([ | |
'base_uri' => VALIDATOR_URL | |
]); | |
# If you want to validate a GitHub repository | |
$github_link = 'PrestaShop/ps_banner'; | |
$github_branch = 'dev'; | |
# As example, | |
$moduleName = 'modulename.zip'; | |
$modulePath = 'https://localhost/'.$moduleName; | |
// Call validator | |
try { | |
$response = $client->post('/api/modules', [ | |
'multipart' => [ | |
# Use this part to validate a GitHub repository | |
/* | |
[ | |
'name' => 'github_link', | |
'contents' => $github_link | |
], | |
[ | |
'name' => 'github_branch', | |
'contents' => $github_branch, | |
], | |
*/ | |
[ | |
'name' => 'archive', | |
'contents' => file_get_contents($modulePath), | |
'filename' => $moduleName | |
], | |
# PrestaShop 1.7 compliant | |
[ | |
'name' => 'compatibility_1_7', | |
'contents' => true | |
], | |
[ | |
'name' => 'key', | |
'contents' => VALIDATOR_API_KEY | |
] | |
] | |
]); | |
$stdResponse = json_decode($response->getBody()->getContents(), true); | |
} catch (\Throwable $th) { | |
die($th->getMessage()); | |
} | |
# Results are an associate array with differents categories as Details, Errors, Optimizations, ... | |
var_dump($stdResponse); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment