From: Christian Weiske Date: Sun, 23 Mar 2014 12:34:38 +0000 (+0100) Subject: add JSON api to fetch links for a given URL X-Git-Url: https://git.cweiske.de/stapibas.git/commitdiff_plain/bf40e716956f0884c430bf564b82d2ac2019aeef add JSON api to fetch links for a given URL --- diff --git a/www/api/links.php b/www/api/links.php new file mode 100644 index 0000000..a52d4af --- /dev/null +++ b/www/api/links.php @@ -0,0 +1,63 @@ +query( + 'SELECT * FROM feedentries WHERE fe_url = ' . $db->quote($url) +); +$urlRow = $res->fetch(PDO::FETCH_OBJ); +if ($urlRow === false) { + header('HTTP/1.0 404 Not Found'); + echo "Url not found\n"; + exit(1); +} +$json = (object) array( + 'url' => $urlRow->fe_url, + 'updated' => $urlRow->fe_updated, + 'needsUpdate' => (bool) $urlRow->fe_needs_update, + 'links' => array() +); + +$res = $db->query( + 'SELECT * FROM feedentryurls' + . ' WHERE feu_fe_id = ' . $db->quote($urlRow->fe_id) +); +while ($linkRow = $res->fetch(\PDO::FETCH_OBJ)) { + $status = null; + if (!$linkRow->feu_pinged) { + $status = 'queued'; + } else if ($linkRow->feu_retry && $linkRow->feu_tries < 5) { + $status = 'pinging'; + } else if ($linkRow->feu_error) { + $status = 'error'; + } else { + $status = 'ok'; + } + $json->links[] = (object) array( + 'url' => $linkRow->feu_url, + 'pinged' => (bool) $linkRow->feu_pinged, + 'updated' => $linkRow->feu_updated, + 'status' => $status, + 'error' => (object) array( + 'code' => $linkRow->feu_error_code, + 'message' => $linkRow->feu_error_message + ), + 'tries' => $linkRow->feu_tries + ); +} + +header('Content-type: application/json'); +echo json_encode($json) . "\n"; +?>