Actually making some progress
This commit is contained in:
parent
1ac069bf28
commit
a4c2d0abd5
11 changed files with 155 additions and 7 deletions
55
gitea/gitea.v
Normal file
55
gitea/gitea.v
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
module gitea
|
||||
|
||||
import net.http
|
||||
import json
|
||||
|
||||
const api_prefix = '/api/v1'
|
||||
|
||||
pub struct Client {
|
||||
base_url string
|
||||
api_key string
|
||||
}
|
||||
|
||||
[params]
|
||||
pub struct PagingConfig {
|
||||
page int
|
||||
limit int
|
||||
}
|
||||
|
||||
fn (p PagingConfig) str() string {
|
||||
if p.page == 0 && p.limit == 0 {
|
||||
return ''
|
||||
}
|
||||
|
||||
mut parts := []string{}
|
||||
|
||||
if p.page != 0 {
|
||||
parts << 'page=$p.page'
|
||||
}
|
||||
|
||||
if p.limit != 0 {
|
||||
parts << 'limit=$p.limit'
|
||||
}
|
||||
|
||||
return parts.join('&')
|
||||
}
|
||||
|
||||
pub fn new(base_url string, api_key string) Client {
|
||||
return Client{
|
||||
base_url: base_url.trim_right('/') + gitea.api_prefix
|
||||
api_key: api_key
|
||||
}
|
||||
}
|
||||
|
||||
fn (c &Client) get<T>(path string, conf PagingConfig) !T {
|
||||
mut url := '$c.base_url$path'
|
||||
|
||||
if conf.str() != '' {
|
||||
url += '&$conf.str()'
|
||||
}
|
||||
|
||||
res := http.get(url)!
|
||||
data := json.decode(T, res.body)!
|
||||
|
||||
return data
|
||||
}
|
||||
13
gitea/orgs.v
Normal file
13
gitea/orgs.v
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
module gitea
|
||||
|
||||
pub struct Repository {
|
||||
pub:
|
||||
id i64
|
||||
name string
|
||||
description string
|
||||
clone_url string
|
||||
}
|
||||
|
||||
pub fn (c &Client) org_repos(name string, conf PagingConfig) ![]Repository {
|
||||
return c.get<[]Repository>('/orgs/$name/repos', conf)
|
||||
}
|
||||
4
gitea/v.mod
Normal file
4
gitea/v.mod
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Module{
|
||||
name: 'gitea'
|
||||
description: 'Wrapper around the Gitea API'
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue