The REST API allows for accessing the stored metadata and metric results in a structured manner. There are two basic entities for the API, namely Projects and Metrics, and everything else is hierarchically mapped under those. To call the API, the Alitheia Core REST bundle must be enabled.
To access the SQO-OSS project main database repository (or at least a snapshot of it) you need to append API calls to the following
base URL:
http://demo.sqo-oss.org/web/proxy/
This is a bit different from accessing the API from a local Alitheia Core installation, which requires the following prefix:
http://localhost:8080/api
Basically, the project uses a proxy to hide the actual Alitheia Core installation machine behind it. All you need to do is to change /api to /web/proxy. Some of the examples below are actually calling the main SQO-OSS metrics database.
To see some examples for accessing the API, you can see the implementation of the web page that runs at http://demo.sqo-oss.org
The service can return either JSON or XML, using content negotiation. Specifically, if the Accepts HTTP header specifies the application/json content type with higher priority than application/xml then content is returned as JSON. In all other cases, including when Acceptis absent from the request, XML is preferred. The names of JSON keys/XML fields is the same in both cases.
The following example demonstrates how to call the REST API using the code command line HTTP client. The same call is shown using XML and JSON return types.
curl http://$HOST/api/project/31
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <project> <id>31</id> <name>FreeBSD</name> </project>
curl -H "Accept: application/json" http://$HOST/api/project/31
{"project":{"id":31,"name":"FreeBSD"}}
Several API calls can accept a variable number of arguments. As shown in the API descriptions below, in all API calls that accept multiple arguments, those are separated with commas and they always occur at the end of the call.
curl -H "Accept: application/json" http://localhost:8080/api/metrics
[ {"metric":{"id":13,"metrictype":{"id":3, "type":"SOURCE_DIRECTORY"}, "mnemonic":"MNOF", "description":"Number of Source Code Files in Module"}, [...] ]
Example
$ curl -H "Accept: application/json" http://$HOST/api/metrics/types
[ { "metrictype":{ "id":1, "type":"SOURCE_FILE" } }, { "metrictype":{ "id":2, "type":"PROJECT_VERSION" }}, { "metrictype":{ "id":3, "type":"MAILTHREAD"}} ]
Example
curl -H "Accept: application/json" http://localhost:8080/api/metrics/by-type/SOURCE_FILE
[ {"metric":{"id":16, "metrictype":{"id":2, "type":"SOURCE_FILE"}, "mnemonic":"EMCC_TOTAL", "description":"Total Extended McCabe Cyclomatic Complexity"}}, {"metric":{"id":17,"metrictype":{"id":2,"type":"SOURCE_FILE"}, "mnemonic":"HD", "description":"Halstead Difficulty Level"}} ]
Example
curl http://$HOST:8080/api/metrics/by-id/2
<metric> <id>2</id> <metrictype> <id>1</id> <type>PROJECT_VERSION</type> </metrictype> <mnemonic>NOF</mnemonic> <description>Number of Files</description> </metric>
curl -H "Accept: application/json" http://localhost:8080/api/metrics/by-id/2/result/3,4,5
[ {"r":{"artifactId":3,"metricId":2,"result":2,"type":"INTEGER"}}, {"r":{"artifactId":5,"metricId":2,"result":4,"type":"INTEGER"}} ]
curl -H "Accept: application/json" http://localhost:8080/api/metrics/by-mnem/"Wc.loc"
{"metric":{"id":11,"metrictype":{"id":2,"type":"SOURCE_FILE"},"mnemonic":"Wc.loc","description":"Total lines"}}
curl -H "Accept: application/json" http://localhost:8080/api/project
[{"project":{"id":1,"name":"Gnome-VFS"}}]
curl http://$HOST/api/project/33
<project> <id>22</id> <name>JikesRVM</name> </project>
$curl http://$HOST/api/project/33/versions
<collection> <version><id>348819</id><revisionId>0</revisionId><timestamp>1177950980280</timestamp><committer><id>20564</id><username>sqo-oss</username></committer><commitMsg>Artificial revision to include / directory</commitMsg><sequence>0</sequence></version> <version><id>348965</id><revisionId>146</revisionId><timestamp>1021492080000</timestamp><committer><id>20710</id><username>tarantula</username></committer><commitMsg>New repository initialized by cvs2svn.</commitMsg><sequence>1</sequence></version> <version><id>348966</id><revisionId>147</revisionId><timestamp>1021492080000</timestamp><committer><id>20711</id><username>jsiek</username></committer><commitMsg>new file </commitMsg><sequence>2</sequence></version> <version><id>348967</id><revisionId>148</revisionId><timestamp>1021492476000</timestamp><committer><id>20711</id><username>jsiek</username></committer><commitMsg>added minmax algo </commitMsg><sequence>3</sequence></version> <version><id>348968</id><revisionId>149</revisionId><timestamp>1021560222000</timestamp><committer><id>20712</id><username>peti</username></committer><commitMsg>Initial version of the enum_state<> template, which is actually called State<> at the moment. :-)</commitMsg></version> </collection>
$curl http://$HOST/api/project/33/versions/0,1
<collection> <version><id>348819</id><revisionId>0</revisionId><timestamp>1177950980280</timestamp><committer><id>20564</id><username>sqo-oss</username></committer><commitMsg>Artificial revision to include / directory</commitMsg><sequence>0</sequence></version> <version><id>348965</id><revisionId>146</revisionId><timestamp>1021492080000</timestamp><committer><id>20710</id><username>tarantula</username></committer><commitMsg>New repository initialized by cvs2svn.</commitMsg><sequence>1</sequence></version> </collection>
curl http://demo.sqo-oss.org/web/proxy/project/10/version/5551/files/trunk/doc
<collection> <file> <id>97198</id> <name>uri.txt</name> <state> <status>2</status> </state> <isdir>false</isdir> <dir> <id>1136</id> <path>/trunk/doc</path> </dir> </file> <file> <id>102736</id> <name>mime-descriptions-guidelines.txt</name> <state> <status>1</status> </state> <isdir>false</isdir> <dir> <id>1136</id> <path>/trunk/doc</path> </dir> </file> </collection>
curl http://demo.sqo-oss.org/web/proxy/project/10/version/5551/files/changed
<collection> <file> <id>19408686</id> <name>modules</name> <state> <status>2</status> </state> <isdir>true</isdir> <dir> <id>27</id> <path>/trunk</path> </dir> </file> <file> <id>19408684</id> <name>sftp-method.c</name> <state> <status>2</status> </state> <isdir>false</isdir> <dir> <id>1947</id> <path>/trunk/modules</path> </dir> </file> <file> <id>19408685</id> <name>ChangeLog</name> <state> <status>2</status> </state> <isdir>false</isdir> <dir> <id>27</id> <path>/trunk</path> </dir> </file> [...] </collection>
http://$HOST/10/version/5551/dirs/
[{"file":{"id":113233,"name":"tarpet","state":{"status":1},"isdir":true,"dir":{"id":1136,"path":"\/trunk\/doc"}}},{"file":{"id":113317,"name":"mime-test-files","state":{"status":2},"isdir":true,"dir":{"id":1948,"path":"\/trunk\/test"}}}, {"file":{"id":198381,"name":"imported","state":{"status":2},"isdir":true,"dir":{"id":27,"path":"\/trunk"}}},{"file":{"id":198383,"name":"gnome-vfs-tutorial","state":{"status":2},"isdir":true,"dir":{"id":1115,"path":"\/trunk\/devel-docs"}}} ...]
curl http://demo.sqo-oss.org/web/proxy/project/10/version/5551/dirs/trunk/doc
<collection> <file> <id>113233</id> <name>tarpet</name> <state> <status>1</status> </state> <isdir>true</isdir> <dir> <id>1136</id> <path>/trunk/doc</path> </dir> </file> <file> <id>200276</id> <name>tmpl</name> <state> <status>2</status> </state> <isdir>true</isdir> <dir> <id>1136</id> <path>/trunk/doc</path> </dir> </file> </collection>
re
thanks for this use ful shairng..
frases para orkut