[aur-dev] [PATCH 1/6] Add documentation of the RPC interface
Convert the RPC interface documentation from web/html/rpc.php to AsciiDoc and add it to the documentation directory. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- doc/rpc.txt | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 doc/rpc.txt diff --git a/doc/rpc.txt b/doc/rpc.txt new file mode 100644 index 0000000..b379515 --- /dev/null +++ b/doc/rpc.txt @@ -0,0 +1,33 @@ +aurweb RPC interface +==================== + +Allowed methods +--------------- + +* `search` +* `info` +* `multiinfo` +* `msearch` + +Each method requires the following HTTP GET syntax: ++type=_methodname_&arg=_data_+ + +Where _methodname_ is the name of an allowed method, and _data_ is the argument +to the call. + +If you need jsonp type callback specification, you can provide an additional +variable _callback_. + +Examples +-------- + +`search`:: + `http://aur-url/rpc.php?type=search&arg=foobar` +`info`:: + `http://aur-url/rpc.php?type=info&arg=foobar` +`multiinfo`:: + `http://aur-url/rpc.php?type=multiinfo&arg[]=foo&arg[]=bar` +`msearch`:: + `http://aur-url/rpc.php?type=msearch&arg=john` +Callback:: + `http://aur-url/rpc.php?type=search&arg=foobar&callback=jsonp1192244621103` -- 2.6.0
Deprecate the msearch command and add a new search type to the search command. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/lib/aurjson.class.php | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php index 8ca028a..f4d5b3e 100644 --- a/web/lib/aurjson.class.php +++ b/web/lib/aurjson.class.php @@ -17,7 +17,7 @@ class AurJSON { 'suggest-pkgbase', 'get-comment-form' ); private static $exposed_fields = array( - 'name', 'name-desc' + 'name', 'name-desc', 'maintainer' ); private static $fields_v1 = array( 'Packages.ID', 'Packages.Name', @@ -358,23 +358,32 @@ class AurJSON { */ private function search($http_data) { $keyword_string = $http_data['arg']; + if (isset($http_data['search_by'])) { $search_by = $http_data['search_by']; } else { $search_by = 'name-desc'; } - if (strlen($keyword_string) < 2) { - return $this->json_error('Query arg too small'); - } - - $keyword_string = $this->dbh->quote("%" . addcslashes($keyword_string, '%_') . "%"); + if ($search_by === 'name' || $search_by === 'name-desc') { + if (strlen($keyword_string) < 2) { + return $this->json_error('Query arg too small'); + } + $keyword_string = $this->dbh->quote("%" . addcslashes($keyword_string, '%_') . "%"); - if ($search_by === 'name') { - $where_condition = "(Packages.Name LIKE $keyword_string)"; - } else if ($search_by === 'name-desc') { - $where_condition = "(Packages.Name LIKE $keyword_string OR "; - $where_condition .= "Description LIKE $keyword_string)"; + if ($search_by === 'name') { + $where_condition = "(Packages.Name LIKE $keyword_string)"; + } else if ($search_by === 'name-desc') { + $where_condition = "(Packages.Name LIKE $keyword_string OR "; + $where_condition .= "Description LIKE $keyword_string)"; + } + } else if ($search_by === 'maintainer') { + if (empty($keyword_string)) { + $where_condition = "Users.ID is NULL"; + } else { + $keyword_string = $this->dbh->quote($keyword_string); + $where_condition = "Users.Username = $keyword_string "; + } } return $this->process_query('search', $where_condition); @@ -443,16 +452,8 @@ class AurJSON { * @return mixed Returns an array of value data containing the package data */ private function msearch($http_data) { - $maintainer = $http_data['arg']; - - if (empty($maintainer)) { - $where_condition = "Users.ID is NULL"; - } else { - $maintainer = $this->dbh->quote($maintainer); - $where_condition = "Users.Username = $maintainer "; - } - - return $this->process_query('msearch', $where_condition); + $http_data['search_by'] = 'maintainer'; + return $this->search($http_data); } /* -- 2.6.0
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/lib/aurjson.class.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php index f4d5b3e..2bf2e7a 100644 --- a/web/lib/aurjson.class.php +++ b/web/lib/aurjson.class.php @@ -76,7 +76,7 @@ class AurJSON { if (isset($http_data['v'])) { $this->version = intval($http_data['v']); } - if ($this->version < 1 || $this->version > 4) { + if ($this->version < 1 || $this->version > 5) { return $this->json_error('Invalid version specified.'); } @@ -93,6 +93,9 @@ class AurJSON { $this->dbh = DB::connect(); $type = str_replace('-', '_', $http_data['type']); + if ($type == 'info' && $this->version >= 5) { + $type = 'multiinfo'; + } $json = call_user_func(array(&$this, $type), $http_data); $etag = md5($json); @@ -250,7 +253,7 @@ class AurJSON { } elseif ($this->version >= 2) { if ($this->version == 2 || $this->version == 3) { $fields = implode(',', self::$fields_v2); - } else if ($this->version == 4) { + } else if ($this->version == 4 || $this->version == 5) { $fields = implode(',', self::$fields_v4); } $query = "SELECT {$fields} " . -- 2.6.0
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- doc/rpc.txt | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/doc/rpc.txt b/doc/rpc.txt index b379515..ee1fa1e 100644 --- a/doc/rpc.txt +++ b/doc/rpc.txt @@ -1,33 +1,36 @@ -aurweb RPC interface +aurweb RPC Interface ==================== -Allowed methods ---------------- +Package Search +-------------- -* `search` -* `info` -* `multiinfo` -* `msearch` +Package searches can be performed by issuing HTTP GET requests of the form ++/rpc/?v=5&type=search&search_by=_by_&arg=_keywords_+ where _by_ is either +`name` (search by package name only), `name-desc` (search by package name and +description) or `maintainer` (search by package maintainer) and _keywords_ is +the search argument. The _search_by_ parameter can be skipped and defaults to +`name-desc`. -Each method requires the following HTTP GET syntax: -+type=_methodname_&arg=_data_+ +If a maintainer search is performed and the search argument is left empty, a +list of orphan packages is returned. -Where _methodname_ is the name of an allowed method, and _data_ is the argument -to the call. +Package Details +--------------- -If you need jsonp type callback specification, you can provide an additional -variable _callback_. +Package information can be obtained by issuing HTTP GET requests of the form ++/rpc/?v=5&type=info&arg[]=_pkg1_&arg[]=_pkg2_&...+ where _pkg1_, _pkg2_, ... +are the names of packages to retrieve package details for. Examples -------- `search`:: - `http://aur-url/rpc.php?type=search&arg=foobar` + `/rpc/?v=5&type=search&arg=foobar` +`search` by maintainer:: + `/rpc/?v=5&type=search&search_by=maintainer&arg=john` +`search` with callback:: + `/rpc/?v=5&type=search&arg=foobar&callback=jsonp1192244621103` `info`:: - `http://aur-url/rpc.php?type=info&arg=foobar` -`multiinfo`:: - `http://aur-url/rpc.php?type=multiinfo&arg[]=foo&arg[]=bar` -`msearch`:: - `http://aur-url/rpc.php?type=msearch&arg=john` -Callback:: - `http://aur-url/rpc.php?type=search&arg=foobar&callback=jsonp1192244621103` + `/rpc/?v=5&type=info&arg[]=foobar` +`info` with multiple packages:: + `/rpc/?v=5&type=info&arg[]=foo&arg[]=bar` -- 2.6.0
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- doc/Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 doc/Makefile diff --git a/doc/Makefile b/doc/Makefile new file mode 100644 index 0000000..df54c5d --- /dev/null +++ b/doc/Makefile @@ -0,0 +1,9 @@ +all: rpc.html + +clean: + rm -rf *.html + +%.html: %.txt + asciidoc $< + +.PHONY: all clean -- 2.6.0
Instead of hardcoding the RPC interface documentation in rpc.php, include the HTML code of the documentation page generated by AsciiDoc. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/html/rpc.php | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/web/html/rpc.php b/web/html/rpc.php index 415dcb8..64c9562 100644 --- a/web/html/rpc.php +++ b/web/html/rpc.php @@ -12,33 +12,6 @@ if ( isset($_GET['type']) ) { echo $rpc_o->handle($_GET); } else { - // dump a simple usage output for people to use. - // this could be moved to an api doc in the future, or generated from - // the AurJSON class directly with phpdoc. For now though, just putting it - // here. -?> -<html><body> -<h2>Allowed methods</h2> -<ul> - <li><tt>search</tt></li> - <li><tt>info</tt></li> - <li><tt>multiinfo</tt></li> - <li><tt>msearch</tt></li> -</ul> -<p>Each method requires the following HTTP GET syntax:</p> -<pre>type=<em>methodname</em>&arg=<em>data</em></pre> -<p>Where <em>methodname</em> is the name of an allowed method, and <em>data</em> is the argument to the call.</p> -<p>If you need jsonp type callback specification, you can provide an additional variable <em>callback</em>.</p> -<h2>Examples</h2> -<dl> - <dt><tt>search</tt></dt><dd><tt>http://aur-url/rpc.php?type=search&arg=foobar</tt></li></dd> - <dt><tt>info</tt></dt><dd><tt>http://aur-url/rpc.php?type=info&arg=foobar</tt></dd> - <dt><tt>multiinfo</tt></dt><dd><tt>http://aur-url/rpc.php?type=multiinfo&arg[]=foo&arg[]=bar</tt></dd> - <dt><tt>msearch</tt></dt><dd><tt>http://aur-url/rpc.php?type=msearch&arg=john</tt></li></dd> - <dt>Callback</dt><dd><tt>http://aur-url/rpc.php?type=search&arg=foobar&callback=jsonp1192244621103</tt></dd> -</dl> -</body></html> -<?php -// close if statement + echo file_get_contents('../../doc/rpc.html'); } ?> -- 2.6.0
participants (1)
-
Lukas Fleischer