function api_spec_methods() { $export_keys = array('method', 'description', 'requires_auth', 'parameters', 'errors', 'notes', 'example'); $defaults = array('method' => 'GET', 'requires_auth' => 0, 'description' => '', 'parameters' => array(), 'errors' => array()); $methods = array(); foreach ($GLOBALS['cfg']['api']['methods'] as $name => $details) { if (!$details['enabled']) { continue; } if (!$details['documented']) { continue; } $details = array_merge($defaults, $details); $method = array('name' => $name); foreach ($export_keys as $k) { if (!isset($details[$k])) { continue; } $v = $details[$k]; $method[$k] = $v; } $rsp = api_spec_utils_example_for_method($name); if ($rsp['ok']) { $method['example'] = $rsp['example']; } $methods[] = $method; } api_output_ok(array('methods' => $methods)); }
} } if (!$include) { continue; } $methods[$method_name] = $method_details; } # Header (maybe?) # $GLOBALS['smarty']->assign("page_title", "{$GLOBALS['cfg']['site_name']} API documentation"); # fwrite($fh, $GLOBALS['smarty']->fetch("inc_head.txt")); # Table of contents $GLOBALS['smarty']->assign_by_ref("methods", $methods); fwrite($fh, $GLOBALS['smarty']->fetch("inc_api_methods_toc.txt")); # The actual API methods foreach ($methods as $method_name => $method_details) { $rsp = api_spec_utils_example_for_method($method_name); if ($rsp['ok']) { $details['example_response'] = $rsp['example']; } $GLOBALS['smarty']->assign_by_ref("method", $method_name); $GLOBALS['smarty']->assign_by_ref("details", $method_details); fwrite($fh, $GLOBALS['smarty']->fetch("inc_api_method.txt")); } # Footer (maybe?) # fwrite($fh, $GLOBALS['smarty']->fetch("inc_foot.txt")); fclose($fh); # clean up dirty hack (above) foreach (glob($tmpdir . '/*.php') as $file) { unlink($file); } rmdir($tmpdir);