Skip to content
Snippets Groups Projects

Read values from endpoint.

All threads resolved!
Files
4
@@ -9,22 +9,41 @@ require_once __DIR__ . '/../tests/modules/project_browser_test/src/DrupalOrgClie
use Drupal\project_browser_test\DrupalOrgClientMiddleware;
$path_to_fixture = DrupalOrgClientMiddleware::ENDPOINT_TO_FIXTURE_MAP;
$endpoint_url = 'https://www.drupal.org/jsonapi';
/**
* Generate the fixtures requested.
*
* @param array $map
* Map of path and destination file.
* @param string $endpoint_base_url
* Base URL of the endpoint.
* @param string $destination_folder
* Destination folder.
*/
function generate_fixtures($map, $endpoint_base_url, $destination_folder) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Curl.ProjectBrowser');
foreach ($map as $jsonapi_path => $fixture_file_name) {
// Wait between requests as otherwise they could be blocked.
sleep(1);
curl_setopt($ch, CURLOPT_URL, $endpoint_base_url . $jsonapi_path);
$contents = curl_exec($ch);
if ($contents) {
file_put_contents($destination_folder . $fixture_file_name, $contents);
}
}
curl_close($ch);
}
// Begin script.
$destination_folder = __DIR__ . '/../tests/fixtures/drupalorg_jsonapi/';
// Make sure the folder exists.
if (!is_dir($destination_folder)) {
mkdir(rtrim($destination_folder, '/'));
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Curl.ProjectBrowser');
foreach ($path_to_fixture as $jsonapi_path => $fixture_file_name) {
// Wait between requests as otherwise they could be blocked.
sleep(1);
curl_setopt($ch, CURLOPT_URL, $endpoint_url . $jsonapi_path);
$contents = curl_exec($ch);
if ($contents) {
file_put_contents($destination_folder . $fixture_file_name, $contents);
}
}
curl_close($ch);
// Generate the fixtures for both the json:api and non json:api paths.
generate_fixtures(DrupalOrgClientMiddleware::DRUPALORG_JSONAPI_ENDPOINT_TO_FIXTURE_MAP, 'https://www.drupal.org/jsonapi', $destination_folder);
generate_fixtures(DrupalOrgClientMiddleware::DRUPALORG_ENDPOINT_TO_FIXTURE_MAP, 'https://www.drupal.org', $destination_folder);
Loading