Initial commit & PoC
commit
442e01c53f
|
@ -0,0 +1,3 @@
|
|||
*.so
|
||||
main.v
|
||||
vls.log
|
|
@ -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.
|
|
@ -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]
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue