forked from vieter-v/vieter
feat(cli): added commands for interacting with build logs
This commit is contained in:
parent
fa6603bd45
commit
5b016df85d
7 changed files with 145 additions and 11 deletions
|
|
@ -18,15 +18,7 @@ pub fn new(address string, api_key string) Client {
|
|||
}
|
||||
}
|
||||
|
||||
// send_request<T> just calls send_request_with_body<T> with an empty body.
|
||||
fn (c &Client) send_request<T>(method Method, url string, params map[string]string) ?Response<T> {
|
||||
return c.send_request_with_body<T>(method, url, params, '')
|
||||
}
|
||||
|
||||
// send_request_with_body<T> is a convenience method for sending requests to
|
||||
// the repos API. It mostly does string manipulation to create a query string
|
||||
// containing the provided params.
|
||||
fn (c &Client) send_request_with_body<T>(method Method, url string, params map[string]string, body string) ?Response<T> {
|
||||
fn (c &Client) send_request_raw(method Method, url string, params map[string]string, body string) ?http.Response {
|
||||
mut full_url := '$c.address$url'
|
||||
|
||||
if params.len > 0 {
|
||||
|
|
@ -46,7 +38,27 @@ fn (c &Client) send_request_with_body<T>(method Method, url string, params map[s
|
|||
req.add_custom_header('X-Api-Key', c.api_key) ?
|
||||
|
||||
res := req.do() ?
|
||||
data := json.decode(Response<T>, res.text) ?
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// send_request<T> just calls send_request_with_body<T> with an empty body.
|
||||
fn (c &Client) send_request<T>(method Method, url string, params map[string]string) ?Response<T> {
|
||||
return c.send_request_with_body<T>(method, url, params, '')
|
||||
}
|
||||
|
||||
// send_request_with_body<T> is a convenience method for sending requests to
|
||||
// the repos API. It mostly does string manipulation to create a query string
|
||||
// containing the provided params.
|
||||
fn (c &Client) send_request_with_body<T>(method Method, url string, params map[string]string, body string) ?Response<T> {
|
||||
res_text := c.send_request_raw_response(method, url, params, body) ?
|
||||
data := json.decode(Response<T>, res_text) ?
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
fn (c &Client) send_request_raw_response(method Method, url string, params map[string]string, body string) ?string {
|
||||
res := c.send_request_raw(method, url, params, body) ?
|
||||
|
||||
return res.text
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue