User:X!/ECAPI

Hey Developers, I've just written a new tool that could help you write programs! It is an Application programming interface, or API. It provides machine-readable information that can be incorporated into your program with ease. It outputs data in JSON, PHP, XML, YAML formats, as well as various debugging formats. It outputs information about replag, user groups, and edit counts.

Formats
The API has the following formats available:


 * format=json
 * format=php
 * format=xml
 * format=yaml
 * format=txt (PHP's print_r function)
 * format=dbg (PHP's var_export function)

Additionally, appending "fm" to the end of each format prints it in pretty-print HTML. For example, "json" becomes "jsonfm", "xml" becomes "xmlfm", and "dbg" becomes "dbgfm". It's not designed for use in an application, but for debugging purposes.

Usage
The API will respond whether you send parameters with a HTTP GET or a HTTP POST request. The standard url is http://toolserver.org/~soxred93/simplecount/api.php?name=(username)&lang=en&wiki=wikipedia&format=(format). It will work for any wiki that the standard edit counter works for. Here are some examples of the API in use:

Example's edit count on enwiki (in json)
http://toolserver.org/~soxred93/simplecount/api.php?name=Example&lang=en&wiki=wikipedia&format=json ({"query":{"count":{"replag":{"w":0,"d":0,"h":15,"m":33,"s":56,"*":56036},"groups":[],"counts":{"live":"1","deleted":"0","total":1}}}})

Example's edit count on enwiki (in xml)
http://toolserver.org/~soxred93/simplecount/api.php?name=Example&lang=en&wiki=wikipedia&format=xml 56431 

Example's edit count on frwiki (in php)
http://toolserver.org/~soxred93/simplecount/api.php?name=Example&lang=fr&wiki=wikipedia&format=php a:1:{s:5:"query";a:1:{s:5:"count";a:3:{s:6:"replag";a:6:{s:1:"w";i:0;s:1:"d";i:0;s:1:"h";i:0;s:1:"m";i:0;s:1:"s";i:3;s:1:"*";d:3;}s:6:"groups";a:0:{}s:6:"counts";a:3:{s:4:"live";s:1:"1";s:7:"deleted";s:1:"0";s:5:"total";i:1;}}}}

Example's edit count on enwikibooks (pretty-printed in yaml)
http://toolserver.org/~soxred93/simplecount/api.php?name=Example&lang=en&wiki=wikibooks&format=yamlfm --- query: count: replag: w: 0 d: 0 h: 0 m: 3 s: 21 *: 201   groups: counts: live: | 2     deleted: | 0     total: 2

Example's edit count on enwiki (in PHP's print_r format)
http://toolserver.org/~soxred93/simplecount/api.php?name=Example&lang=en&wiki=wikipedia&format=txt Array (   [query] => Array        ( [count] => Array (                   [replag] => Array                        ( [w] => 0 [d] => 0 [h] => 15 [m] => 42 [s] => 49 [*] => 56569                       )

[groups] => Array 

[counts] => Array (                           [live] => 1                            [deleted] => 0                            [total] => 1                        )

)

)

)

Example2's edit count on enwiki (in json, with callback)
The API accepts a callback parameter when called with the json format. If specified, it wraps the output into a given function call. http://toolserver.org/~soxred93/simplecount/api.php?name=Example2&lang=en&wiki=wikipedia&format=json&callback=getexamplecount getexamplecount({"query":{"count":{"replag":{"w":0,"d":0,"h":15,"m":43,"s":45,"*":56625},"groups":[],"counts":{"live":"2","deleted":"0","total":2}}}})

Errors
There will only be a few types of errors that will ever show up, so you will know how to have your application react.

mysqlerror
A MySQL error has occurred. Example: <tt>http://toolserver.org/~soxred93/simplecount/api.php?name=Example&lang=en&wiki=wikipedia</tt> <?xml version="1.0"?> <error code="mysqlerror" info="You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#039;UNIX_TIMESTAMP(rc_timestamp) as replag FROM recentchanges ORDER BY rc_timestamp &#039; at line 1" />

nosuchuser
The user specified does not exist. Example: <tt>http://toolserver.org/~soxred93/simplecount/api.php?name=If%20this%20username%20exists,%20I%20have%20lost%20faith%20in%20Wikipedia&lang=en&wiki=wikipedia</tt> <?xml version="1.0"?> <error code="nosuchuser" info="User does not exist" />

missingusername
No username was specified. Example: <tt>http://toolserver.org/~soxred93/simplecount/api.php?lang=en&wiki=wikipedia</tt> <?xml version="1.0"?> <error code="missingusername" info="No username given" />

missinglanguage
No language was specified. Example: <tt>http://toolserver.org/~soxred93/simplecount/api.php?name=Example&wiki=wikipedia</tt> <?xml version="1.0"?> <error code="missinglanguage" info="No language given" />

missingwiki
No wiki was specified. Example: <tt>http://toolserver.org/~soxred93/simplecount/api.php?name=Example&lang=en</tt> <?xml version="1.0"?> <error code="missingwiki" info="No wiki given" />

Future ideas
This is still a prototype, and a work in progress. Here are some features I will add in the future:


 * Month counts
 * Namespace percentages
 * Namespace edits per month
 * Top edited articles