-
-
Save SebSept/88ed2637c5b43279e0b7a030a2f99fdc to your computer and use it in GitHub Desktop.
PrestaShop Validator API (Example)
This file contains 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 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 | |
], | |
[ | |
'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