feat: Add GraphQL support to GhApiClient (#1124)

Fixed #868

 - Add new fn `remote::Client::post`
 - Add new fn `remote::RequestBuilder::body`
 - Re-export `reqwest::Body` in `remote`
 - Add dep percent-encoding v2.2.0 to binstalk-downloader
 - Add dep serde-tuple-vec-map v1.0.1 to binstalk-downloader
 - Add GraphQL to `GhApiClient`, fallback to Restful API if token is not
   provided or authorization failed.
 - Fixed `GhReleaseArtifact::try_extract_artifact_from_str`: decode
   percent encoded http url path and add regression tests
 - Added variant `GhApiError::Context` & `GhApiContextError`
 - Added variant `GhApiError::GraphQLErrors` & `GhGraphQLErrors`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2023-06-05 00:09:49 +10:00 committed by GitHub
parent e87e3534a8
commit 22b3419fce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 518 additions and 99 deletions

View file

@ -6,6 +6,8 @@ use reqwest::Method;
use super::{header, Client, Error, HttpError, StatusCode, Url};
pub use reqwest::Body;
#[cfg(feature = "json")]
pub use serde_json::Error as JsonError;
@ -16,20 +18,27 @@ pub struct RequestBuilder {
}
impl RequestBuilder {
pub fn bearer_auth(self, token: &dyn fmt::Display) -> RequestBuilder {
pub fn bearer_auth(self, token: &dyn fmt::Display) -> Self {
Self {
client: self.client,
inner: self.inner.bearer_auth(token),
}
}
pub fn header(self, key: &str, value: &str) -> RequestBuilder {
pub fn header(self, key: &str, value: &str) -> Self {
Self {
client: self.client,
inner: self.inner.header(key, value),
}
}
pub fn body(self, body: impl Into<Body>) -> Self {
Self {
client: self.client,
inner: self.inner.body(body.into()),
}
}
pub async fn send(self, error_for_status: bool) -> Result<Response, Error> {
let request = self.inner.build()?;
let method = request.method().clone();