Initial commit & PoC

main
Jef Roosens 2022-06-22 11:42:16 +02:00
commit 442e01c53f
Signed by: Jef Roosens
GPG Key ID: B580B976584B5F30
7 changed files with 112 additions and 0 deletions

3
.gitignore vendored 100644
View File

@ -0,0 +1,3 @@
*.so
main.v
vls.log

8
README.md 100644
View File

@ -0,0 +1,8 @@
# AUR
This library provides a wrapper around the [aurweb RPC
interface](https://aur.archlinux.org/rpc).
This library is largely inspired by
[raur](https://gitlab.com/davidbittner/raur); this is basically a re-write of
raur in V.

10
aur.v 100644
View File

@ -0,0 +1,10 @@
module aur
const aur_rpc_url = 'https://aur.archlinux.org/rpc/'
pub struct Package {
pub:
id u32 [json: ID]
name string [json: Name]
package_base_id u32 [json: PackageBaseID]
}

49
client.v 100644
View File

@ -0,0 +1,49 @@
module aur
import net.urllib
import net.http
import json
pub struct Client {
url string = aur_rpc_url
}
pub fn new() &Client {
return &Client{}
}
pub fn new_with_url(url string) &Client {
if !url.ends_with('/') {
return &Client{url: '$url/'}
}
return &Client{url: url}
}
struct SuccessResponse {
result_count int [json: resultCount]
results []Package
}
fn (c Client) request(params map[string]string) ?[]Package {
mut params_escaped := map[string]string{}
for k, v in params {
params_escaped[k] = urllib.query_escape(v)
}
params_str := params_escaped.keys().map('$it=${params[it]}').join('&')
url := '$c.url?$params_str'
res := http.get(url)?
if res.status_code < 200 || res.status_code >= 300 {
// temporary
return error('error')
}
data := json.decode(SuccessResponse, res.body)?
return data.results
}

1
request.v 100644
View File

@ -0,0 +1 @@
module aur

34
search.v 100644
View File

@ -0,0 +1,34 @@
module aur
pub enum SearchType {
name
name_desc
maintainer
depends
make_depends
opt_depends
check_depends
}
pub fn (st SearchType) str() string {
return match st {
.name { 'name' }
.name_desc { 'name-desc' }
.maintainer { 'maintainer' }
.depends { 'depends' }
.make_depends { 'makedepends' }
.opt_depends { 'optdepends' }
.check_depends { 'checkdepends' }
}
}
pub fn (c Client) search_by(arg string, st SearchType) ?[]Package {
params := {
'v': '5'
'type': 'search'
'by': '$st'
'arg': arg
}
return c.request(params)
}

7
v.mod 100644
View File

@ -0,0 +1,7 @@
Module {
name: 'aur'
description: 'Library for interacting with the AUR RPC interface'
version: '0.0.0'
license: 'MIT'
dependencies: []
}