There's no reason for Registration::complete to take an owned string

master
Paul Woolcock 6 years ago
parent 009798d17f
commit 1057e58343
  1. 2
      README.md
  2. 2
      examples/register.rs
  3. 2
      src/lib.rs
  4. 4
      src/registration.rs

@ -68,7 +68,7 @@ fn register() -> Result<Mastodon, Box<Error>> {
io::stdin().read_line(&mut input)?;
let code = input.trim().to_string();
let mastodon = registration.complete(code)?;
let mastodon = registration.complete(&code)?;
// Save app data for using on the next run.
toml::to_file(&*mastodon, "mastodon-data.toml")?;

@ -39,7 +39,7 @@ pub fn register() -> Result<Mastodon, Box<Error>> {
println!("Click this link to authorize on Mastodon: {}", url);
let code = read_line("Paste the returned authorization code: ")?;
let mastodon = registration.complete(code)?;
let mastodon = registration.complete(&code)?;
// Save app data for using on the next run.
toml::to_file(&*mastodon, "mastodon-data.toml")?;

@ -18,7 +18,7 @@
//! // Here you now need to open the url in the browser
//! // And handle a the redirect url coming back with the code.
//! let code = String::from("RETURNED_FROM_BROWSER");
//! let mastodon = registration.complete(code)?;
//! let mastodon = registration.complete(&code)?;
//!
//! println!("{:?}", mastodon.get_home_timeline()?.initial_items);
//! # Ok(())

@ -103,7 +103,7 @@ impl<'a, H: HttpSend> Registration<'a, H> {
/// // Here you now need to open the url in the browser
/// // And handle a the redirect url coming back with the code.
/// let code = String::from("RETURNED_FROM_BROWSER");
/// let mastodon = registration.complete(code)?;
/// let mastodon = registration.complete(&code)?;
///
/// println!("{:?}", mastodon.get_home_timeline()?.initial_items);
/// # Ok(())
@ -144,7 +144,7 @@ impl<H: HttpSend> Registered<H> {
/// Create an access token from the client id, client secret, and code
/// provided by the authorisation url.
pub fn complete(self, code: String) -> Result<Mastodon<H>> {
pub fn complete(self, code: &str) -> Result<Mastodon<H>> {
let url = format!(
"{}/oauth/token?client_id={}&client_secret={}&code={}&grant_type=authorization_code&redirect_uri={}",
self.base,

Loading…
Cancel
Save