There's no reason for Registration::complete to take an owned string
This commit is contained in:
@@ -68,7 +68,7 @@ fn register() -> Result<Mastodon, Box<Error>> {
|
|||||||
io::stdin().read_line(&mut input)?;
|
io::stdin().read_line(&mut input)?;
|
||||||
|
|
||||||
let code = input.trim().to_string();
|
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.
|
// Save app data for using on the next run.
|
||||||
toml::to_file(&*mastodon, "mastodon-data.toml")?;
|
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);
|
println!("Click this link to authorize on Mastodon: {}", url);
|
||||||
let code = read_line("Paste the returned authorization code: ")?;
|
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.
|
// Save app data for using on the next run.
|
||||||
toml::to_file(&*mastodon, "mastodon-data.toml")?;
|
toml::to_file(&*mastodon, "mastodon-data.toml")?;
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@
|
|||||||
//! // Here you now need to open the url in the browser
|
//! // Here you now need to open the url in the browser
|
||||||
//! // And handle a the redirect url coming back with the code.
|
//! // And handle a the redirect url coming back with the code.
|
||||||
//! let code = String::from("RETURNED_FROM_BROWSER");
|
//! let code = String::from("RETURNED_FROM_BROWSER");
|
||||||
//! let mastodon = registration.complete(code)?;
|
//! let mastodon = registration.complete(&code)?;
|
||||||
//!
|
//!
|
||||||
//! println!("{:?}", mastodon.get_home_timeline()?.initial_items);
|
//! println!("{:?}", mastodon.get_home_timeline()?.initial_items);
|
||||||
//! # Ok(())
|
//! # Ok(())
|
||||||
|
|||||||
+2
-2
@@ -103,7 +103,7 @@ impl<'a, H: HttpSend> Registration<'a, H> {
|
|||||||
/// // Here you now need to open the url in the browser
|
/// // Here you now need to open the url in the browser
|
||||||
/// // And handle a the redirect url coming back with the code.
|
/// // And handle a the redirect url coming back with the code.
|
||||||
/// let code = String::from("RETURNED_FROM_BROWSER");
|
/// let code = String::from("RETURNED_FROM_BROWSER");
|
||||||
/// let mastodon = registration.complete(code)?;
|
/// let mastodon = registration.complete(&code)?;
|
||||||
///
|
///
|
||||||
/// println!("{:?}", mastodon.get_home_timeline()?.initial_items);
|
/// println!("{:?}", mastodon.get_home_timeline()?.initial_items);
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
@@ -144,7 +144,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: String) -> 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,
|
||||||
|
|||||||
Reference in New Issue
Block a user