use RequestBuilder.query to manage url encoding

This commit is contained in:
softprops 2019-08-25 23:40:13 -04:00
parent aa1c0dedfd
commit 471be87ecf

View file

@ -79,17 +79,6 @@ impl Releaser for Client {
} }
} }
fn asset_url(
github_repo: &str,
release_id: usize,
name: &str,
) -> String {
format!(
"http://uploads.github.com/repos/{}/releases/{}/assets?name={}",
github_repo, release_id, name
)
}
impl<A: Into<Body>> AssetUploader<A> for Client { impl<A: Into<Body>> AssetUploader<A> for Client {
// https://developer.github.com/v3/repos/releases/#upload-a-release-asset // https://developer.github.com/v3/repos/releases/#upload-a-release-asset
fn upload( fn upload(
@ -102,9 +91,13 @@ impl<A: Into<Body>> AssetUploader<A> for Client {
asset: A, asset: A,
) -> Result<StatusCode, Box<dyn Error>> { ) -> Result<StatusCode, Box<dyn Error>> {
Ok(self Ok(self
.post(&asset_url(github_repo, release_id, name)) .post(&format!(
"http://uploads.github.com/repos/{}/releases/{}/assets",
github_repo, release_id
))
.header("Authorization", format!("bearer {}", github_token)) .header("Authorization", format!("bearer {}", github_token))
.header("Content-Type", mime.to_string()) .header("Content-Type", mime.to_string())
.query(&[("name", name)])
.body(asset) .body(asset)
.send()? .send()?
.status()) .status())
@ -113,12 +106,6 @@ impl<A: Into<Body>> AssetUploader<A> for Client {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*;
#[test] #[test]
fn asset_url_formats_urls() { fn it_works() {}
assert_eq!(
"http://uploads.github.com/repos/foo/bar/releases/1/assets?name=release.txt",
asset_url("foo/bar", 1, "release.txt")
)
}
} }