#!/usr/bin/env php
<?php
require_once __DIR__ . '/../bootstrap/client.php';
$usage = 'usage: ' . PHP_EOL .
' ' . basename(__FILE__) . ' <host> <repository name>' . PHP_EOL;
execute(function () use ($baseUrl, $command, $values) {
throwExceptionIfInvalidNumberOfValuesWasProvided($values, 2);
list($host, $repositoryName) = extractValues($values);
throwExceptionIfValueIsInvalid($host, 'host');
throwExceptionIfValueIsInvalid($repositoryName, 'repository name');
$url = $baseUrl . '/' . $repositoryName;
$lines = $command->get($host, $url);
$repositoriesAreAvailable = ((is_array($lines) && (count($lines) > 0)));
if ($repositoriesAreAvailable) {
foreach ($lines as $line) {
$data = json_decode($line);
echo '[number]' . PHP_EOL;
$uniqueNumbersAreAvailable = ((is_array($data) && (count($data) > 0)));
if ($uniqueNumbersAreAvailable) {
foreach ($data as $uniqueNumber) {
echo $uniqueNumber->number . PHP_EOL;
}
} else {
echo 'unexpected response: ' . var_export($lines, true);
}
}
} else {
echo 'no repository available' . PHP_EOL;
}
}, $usage);
|