feat: added info function

main
Jef Roosens 2022-06-22 13:42:55 +02:00
parent 3d39132646
commit 7efa42f1e5
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
5 changed files with 80 additions and 46 deletions

28
Makefile 100644
View File

@ -0,0 +1,28 @@
# =====CONFIG=====
V_PATH ?= v
V := $(V_PATH) -showcc
all: aur
# =====COMPILATION=====
.PHONY: aur
aur:
$(V) -g -shared .
# =====DOCS=====
.PHONY: api-docs
api-docs:
rm -rf '_docs'
v doc -f html -m -readme .
# =====OTHER=====
.PHONY: lint
lint:
$(V) fmt -verify .
.PHONY: fmt
fmt:
$(V) fmt -w .

22
aur.v
View File

@ -28,3 +28,25 @@ pub:
license []string [json: License] license []string [json: License]
keywords []string [json: Keywords] keywords []string [json: Keywords]
} }
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' }
}
}

View File

@ -29,16 +29,14 @@ struct SuccessResponse {
results []Package results []Package
} }
fn (c Client) request(params map[string]string) ?[]Package { fn (c Client) request(params map[string][]string) ?[]Package {
mut params_escaped := map[string]string{} mut param_strings := []string{}
for k, v in params { for k, v in params {
params_escaped[k] = urllib.query_escape(v) param_strings << v.map(urllib.query_escape(it)).map('$k=$it')
} }
params_str := params_escaped.keys().map('$it=${params[it]}').join('&') url := '$c.url?${param_strings.join('&')}'
url := '$c.url?$params_str'
res := http.get(url)? res := http.get(url)?
@ -51,3 +49,29 @@ fn (c Client) request(params map[string]string) ?[]Package {
return data.results return data.results
} }
pub fn (c Client) search_by(arg string, st SearchType) ?[]Package {
params := {
'v': ['5']
'type': ['search']
'by': ['$st']
'arg': [arg]
}
return c.request(params)
}
// search performs a search by name_desc.
pub fn (c Client) search(arg string) ?[]Package {
return c.search_by(arg, .name_desc)
}
pub fn (c Client) info(pkgs []string) ?[]Package {
params := {
'v': ['5']
'type': ['info']
'arg[]': pkgs
}
return c.request(params)
}

View File

@ -1 +0,0 @@
module aur

View File

@ -1,39 +0,0 @@
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)
}
// search performs a search by name_desc.
pub fn (c Client) search(arg string) ?[]Package {
return c.search_by(arg, .name_desc)
}