Some more http sketching.
This commit is contained in:
parent
114a16e1e8
commit
9ffcf68695
@ -43,18 +43,18 @@ pub int JsonClient : HttpClient
|
|||||||
|
|
||||||
pub int JsonClientOpts {
|
pub int JsonClientOpts {
|
||||||
baseUrl: String
|
baseUrl: String
|
||||||
auth: HttpClientAuth
|
fn getAuth(#[self] client: JsonClient) -> HttpClientAuth
|
||||||
}
|
}
|
||||||
|
|
||||||
pub int HttpClientAuth = (reqBuilder: HttpRequest::Builder) -> Void
|
pub int HttpClientAuth = (reqBuilder: HttpRequest::Builder) -> Void
|
||||||
|
|
||||||
impl : JsonClient {
|
impl : JsonClient {
|
||||||
|
|
||||||
baseUrl: String
|
baseUrl: String
|
||||||
fld auth: HttpClientAuth
|
fld auth: HttpClientAuth
|
||||||
|
|
||||||
ctor (opts: JsonClientOpts) {
|
ctor (opts: JsonClientOpts) {
|
||||||
self.{baseUrl, auth} = opts
|
self.baseUrl = opts.baseUrl
|
||||||
|
self.auth = opts.getAuth(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fn get(path, opts) = IOEither::of || (
|
impl fn get(path, opts) = IOEither::of || (
|
||||||
@ -70,6 +70,11 @@ impl : JsonClient {
|
|||||||
|
|
||||||
pub fn jsonClient(opts: JsonClientOpts): JsonClient = JsonClientImpl(opts)
|
pub fn jsonClient(opts: JsonClientOpts): JsonClient = JsonClientImpl(opts)
|
||||||
|
|
||||||
pub fn bearerToken(tokenGetter: (#[self] client: JsonClient) -> IOEither<HttpRequestError, String>): HttpClientAuth {
|
pub fn bearerToken(tokenGetter: (#[self] client: JsonClient) -> IOEither<HttpRequestError, String>) {
|
||||||
// todo
|
|client: JsonClient| {
|
||||||
|
let token = tokenGetter.hydrate(self: client)().unwrap()
|
||||||
|
|reqBuilder: HttpRequest::Builder| {
|
||||||
|
reqBuilder.headers['Authorization'] = "Bearer $token"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user