refactor: trello client: clean up headers
This commit is contained in:
parent
090e4a4345
commit
022bb697fb
1 changed files with 13 additions and 12 deletions
|
@ -35,19 +35,14 @@ impl<'ctx> TrelloClient<'ctx> {
|
||||||
let api_secret = &self.ctx.cfg.trello.api_secret;
|
let api_secret = &self.ctx.cfg.trello.api_secret;
|
||||||
HashMap::from([(
|
HashMap::from([(
|
||||||
s!("Authorization"),
|
s!("Authorization"),
|
||||||
f!(r#"OAuth oauth_consumer_key="{api_key}", oauth_token="{api_secret}""#,),
|
f!(r#"OAuth oauth_consumer_key="{api_key}", oauth_token="{api_secret}""#),
|
||||||
)])
|
)])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn common_headers(&self) -> HashMap<String, String> {
|
fn common_headers(&self) -> HashMap<String, String> {
|
||||||
let api_key = &self.ctx.cfg.trello.api_key;
|
|
||||||
let api_secret = &self.ctx.cfg.trello.api_secret;
|
|
||||||
HashMap::from([
|
HashMap::from([
|
||||||
(s!("accept"), s!("application/json")),
|
|
||||||
(s!("content-type"), s!("application/json")),
|
(s!("content-type"), s!("application/json")),
|
||||||
(
|
(s!("accept"), s!("application/json")),
|
||||||
s!("Authorization"),
|
|
||||||
f!(r#"OAuth oauth_consumer_key="{api_key}", oauth_token="{api_secret}""#,),
|
|
||||||
),
|
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +56,7 @@ impl<'ctx> TrelloClient<'ctx> {
|
||||||
with_exponential_backoff!(
|
with_exponential_backoff!(
|
||||||
&self.ctx,
|
&self.ctx,
|
||||||
custom(&self.ctx.net, self.url(url.clone()))
|
custom(&self.ctx.net, self.url(url.clone()))
|
||||||
|
.headers(self.auth_headers())
|
||||||
.headers(self.common_headers())
|
.headers(self.common_headers())
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
|
@ -90,6 +86,7 @@ impl<'ctx> TrelloClient<'ctx> {
|
||||||
.net
|
.net
|
||||||
.get(url.clone())
|
.get(url.clone())
|
||||||
.headers(self.auth_headers())
|
.headers(self.auth_headers())
|
||||||
|
.header("content-type", "application/json")
|
||||||
.header("accept", "application/octet")
|
.header("accept", "application/octet")
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
|
@ -123,14 +120,18 @@ impl<'ctx> TrelloClient<'ctx> {
|
||||||
impl<'ctx> TrelloClient<'ctx> {
|
impl<'ctx> TrelloClient<'ctx> {
|
||||||
// https://developer.atlassian.com/cloud/trello/rest/api-group-members/#api-members-id-boards-get
|
// https://developer.atlassian.com/cloud/trello/rest/api-group-members/#api-members-id-boards-get
|
||||||
pub(crate) async fn boards(&self) -> APIResult<Vec<TrelloBoard>> {
|
pub(crate) async fn boards(&self) -> APIResult<Vec<TrelloBoard>> {
|
||||||
self.request("/members/me/boards?lists=open", |net, url| net.get(url))
|
self.request("/members/me/boards", |net, url| {
|
||||||
.await
|
net.get(url).query("lists", "open")
|
||||||
|
})
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-get
|
// https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-get
|
||||||
pub(crate) async fn board(&self, board_id: &TrelloBoardId) -> APIResult<TrelloBoard> {
|
pub(crate) async fn board(&self, board_id: &TrelloBoardId) -> APIResult<TrelloBoard> {
|
||||||
self.request(f!("/boards/{board_id}?lists=open"), |net, url| net.get(url))
|
self.request(f!("/boards/{board_id}"), |net, url| {
|
||||||
.await
|
net.get(url).query("lists", "open")
|
||||||
|
})
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://developer.atlassian.com/cloud/trello/rest/api-group-lists/#api-lists-id-cards-get
|
// https://developer.atlassian.com/cloud/trello/rest/api-group-lists/#api-lists-id-cards-get
|
||||||
|
|
Loading…
Reference in a new issue