Make `Registered::complete` take self by reference

master
Paul Woolcock 6 years ago
parent 107642be1c
commit 15cc5c60de
  1. 4
      Cargo.toml
  2. 14
      src/registration.rs

@ -1,6 +1,6 @@
[package] [package]
name = "elefren" name = "elefren"
version = "0.17.0" version = "0.18.0"
description = "A wrapper around the Mastodon API." description = "A wrapper around the Mastodon API."
authors = ["Aaron Power <theaaronepower@gmail.com>", "Paul Woolcock <paul@woolcock.us>"] authors = ["Aaron Power <theaaronepower@gmail.com>", "Paul Woolcock <paul@woolcock.us>"]
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
@ -28,7 +28,7 @@ version = "0.4"
features = ["serde"] features = ["serde"]
[features] [features]
default-features = [] default = []
json = [] json = []
all = ["toml", "json"] all = ["toml", "json"]

@ -282,7 +282,7 @@ impl<H: HttpSend> Registered<H> {
/// Create an access token from the client id, client secret, and code /// Create an access token from the client id, client secret, and code
/// provided by the authorisation url. /// provided by the authorisation url.
pub fn complete(self, code: &str) -> Result<Mastodon<H>> { pub fn complete(&self, code: &str) -> Result<Mastodon<H>> {
let url = format!( let url = format!(
"{}/oauth/token?client_id={}&client_secret={}&code={}&grant_type=authorization_code&redirect_uri={}", "{}/oauth/token?client_id={}&client_secret={}&code={}&grant_type=authorization_code&redirect_uri={}",
self.base, self.base,
@ -295,15 +295,15 @@ impl<H: HttpSend> Registered<H> {
let token: AccessToken = self.send(self.client.post(&url))?.json()?; let token: AccessToken = self.send(self.client.post(&url))?.json()?;
let data = Data { let data = Data {
base: self.base.into(), base: self.base.clone().into(),
client_id: self.client_id.into(), client_id: self.client_id.clone().into(),
client_secret: self.client_secret.into(), client_secret: self.client_secret.clone().into(),
redirect: self.redirect.into(), redirect: self.redirect.clone().into(),
token: token.access_token.into(), token: token.access_token.into(),
}; };
let mut builder = MastodonBuilder::new(self.http_sender); let mut builder = MastodonBuilder::new(self.http_sender.clone());
builder.client(self.client).data(data); builder.client(self.client.clone()).data(data);
Ok(builder.build()?) Ok(builder.build()?)
} }
} }

Loading…
Cancel
Save