[PATCH] Introduce API v6

2019-02-12 Thread Kevin Morris
Add new method of multiple by[] search in API v6.
The 'provides' by field is also supported in the new
multiple by[] method included with this patch.

'provides' may not be used in legacy (v5) singular by search.
A helpful json error message is returned to the user to indicate so.

This patch is a follow-up implementation to 
https://patchwork.archlinux.org/patch/479/

Signed-off-by: Kevin Morris 
---
 doc/rpc.txt   |  24 ++---
 web/lib/aurjson.class.php | 105 --
 2 files changed, 116 insertions(+), 13 deletions(-)

diff --git a/doc/rpc.txt b/doc/rpc.txt
index 3148ebe..486a49d 100644
--- a/doc/rpc.txt
+++ b/doc/rpc.txt
@@ -5,7 +5,7 @@ Package Search
 --
 
 Package searches can be performed by issuing HTTP GET requests of the form
-+/rpc/?v=5=search=_field_=_keywords_+ where _keywords_ is the
++/rpc/?v=6=search[]=_field_[]=_keywords_+ where _keywords_ is the
 search argument and _field_ is one of the following values:
 
 * `name` (search by package name only)
@@ -15,31 +15,39 @@ search argument and _field_ is one of the following values:
 * `makedepends` (search for packages that makedepend on _keywords_)
 * `optdepends` (search for packages that optdepend on _keywords_)
 * `checkdepends` (search for packages that checkdepend on _keywords_)
+* `provides` (search by package provides; v6 multiple by[] only)
 
 The _by_ parameter can be skipped and defaults to `name-desc`.
 
 If a maintainer search is performed and the search argument is left empty, a
 list of orphan packages is returned.
 
+Note: Legacy v5 support is still enabled for singular _by_ searches.
+
 Package Details
 ---
 
 Package information can be obtained by issuing HTTP GET requests of the form
-+/rpc/?v=5=info[]=_pkg1_[]=_pkg2_&...+ where _pkg1_, _pkg2_, ...
++/rpc/?v=6=info[]=_pkg1_[]=_pkg2_&...+ where _pkg1_, _pkg2_, ...
 are the names of packages to retrieve package details for.
 
 Examples
 
 
 `search`::
-  `/rpc/?v=5=search=foobar`
+  `/rpc/?v=6=search=foobar`
 `search` by maintainer::
-  `/rpc/?v=5=search=maintainer=john`
+  `/rpc/?v=6=search[]=maintainer=john`
 `search` packages that have _boost_ as `makedepends`::
-  `/rpc/?v=5=search=makedepends=boost`
+  `/rpc/?v=6=search[]=makedepends=boost`
 `search` with callback::
-  `/rpc/?v=5=search=foobar=jsonp1192244621103`
+  `/rpc/?v=6=search=foobar=jsonp1192244621103`
+`search` by provides::
+  `/rpc/?v=6=search[]=provides[]=gcc`
+`search` by provides and name::
+  `/rpc/?v=6=search[]=name[]=provides[]=gcc`
 `info`::
-  `/rpc/?v=5=info[]=foobar`
+  `/rpc/?v=6=info[]=foobar`
 `info` with multiple packages::
-  `/rpc/?v=5=info[]=foo[]=bar`
+  `/rpc/?v=6=info[]=foo[]=bar`
+
diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index c275d21..ab4eb19 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -80,7 +80,8 @@ class AurJSON {
if (isset($http_data['v'])) {
$this->version = intval($http_data['v']);
}
-   if ($this->version < 1 || $this->version > 5) {
+
+   if ($this->version < 1 || $this->version > 6) {
return $this->json_error('Invalid version specified.');
}
 
@@ -94,8 +95,14 @@ class AurJSON {
if (isset($http_data['search_by']) && !isset($http_data['by'])) 
{
$http_data['by'] = $http_data['search_by'];
}
-   if (isset($http_data['by']) && !in_array($http_data['by'], 
self::$exposed_fields)) {
-   return $this->json_error('Incorrect by field 
specified.');
+
+   if (isset($http_data['by']) && !is_array($http_data['by'])) {
+   if ($http_data['by'] === 'provides') {
+   return $this->json_error("The 'provides' by 
field " .
+   "may only be used via multiple by[] 
search.");
+   } elseif (!in_array($http_data['by'], 
self::$exposed_fields)) {
+   return $this->json_error('Incorrect by field 
specified.');
+   }
}
 
$this->dbh = DB::connect();
@@ -360,7 +367,7 @@ class AurJSON {
} elseif ($this->version >= 2) {
if ($this->version == 2 || $this->version == 3) {
$fields = implode(',', self::$fields_v2);
-   } else if ($this->version == 4 || $this->version == 5) {
+   } else if ($this->version == 4 || $this->version == 5 
|| $this->version == 6) {
$fields = implode(',', self::$fields_v4);
}
$query = "SELECT {$fields} " .
@@ -470,6 +477,10 @@ class AurJSON {
 * @return mixed Returns an array of package matches.
 */
private function search($http_data) {
+

Re: PR Regarding v6 multiple by and provides field

2019-02-12 Thread Eli Schwartz
On 2/12/19 5:00 PM, Kevin Morris wrote:
> Please let me know if there are any blockers or questions you may have, I
> hope it works out well!

Discussed on IRC how to do a git-formatted patch.

Observation: docs should advocate for the v6 API, so merge the docs
together: discuss how "multiple by[] and arg[] are possible", and add a
new example in the unified examples section showing how that can be done.

-- 
Eli Schwartz
Bug Wrangler and Trusted User



signature.asc
Description: OpenPGP digital signature


PR Regarding v6 multiple by and provides field

2019-02-12 Thread Kevin Morris
Hello AUR Maintainers,

This pull request is in reference to
https://patchwork.archlinux.org/patch/578/ and satisfies back-compat
requirements and multiple by[] search implementation that the original
requester intended, including the 'provides' field search.


> The following changes since commit
> 042f3f2622e1adbc7546cfa25a5d138486b99341:
>   Quote MySql 8.0 reserved keywords (2019-01-14 14:45:37 -0500)
> are available in the Git repository at:
>   https://github.com/kevr/aurweb master
> for you to fetch changes up to ac80bee46ae3fe0362c134fe598304d58d1db3fb:
>   Introduce API v6 (2019-02-12 13:39:08 -0800)
> 
> Kevin Morris (1):
>   Introduce API v6
>  doc/rpc.txt   | 15 ++-
>  web/lib/aurjson.class.php | 99
> +++
>  2 files changed, 109 insertions(+), 5 deletions(-)


Please let me know if there are any blockers or questions you may have, I
hope it works out well!

Regards,
Kevin

-- 
Kevin Morris
Personal Inquiries: kevr.gt...@gmail.com

Technologies: C++, Python, Django, Ruby, Rails, ReactJS, jQuery,
Javascript, SQL, Redux