rustfmt pass

master
Paul Woolcock 6 years ago
parent 49a2237803
commit 3330a26760
  1. 2
      examples/register.rs
  2. 2
      src/entities/itemsiter.rs
  3. 2
      src/http_send.rs
  4. 31
      src/lib.rs
  5. 22
      src/registration.rs

@ -6,9 +6,9 @@ use std::{error::Error, io};
use self::elefren::{ use self::elefren::{
apps::{App, Scopes}, apps::{App, Scopes},
data::toml,
Mastodon, Mastodon,
Registration, Registration,
data::toml,
}; };
#[allow(dead_code)] #[allow(dead_code)]

@ -1,5 +1,5 @@
use page::Page;
use http_send::HttpSend; use http_send::HttpSend;
use page::Page;
use serde::Deserialize; use serde::Deserialize;
/// Abstracts away the `next_page` logic into a single stream of items /// Abstracts away the `next_page` logic into a single stream of items

@ -1,5 +1,5 @@
use Result;
use reqwest::{Client, Request, RequestBuilder, Response}; use reqwest::{Client, Request, RequestBuilder, Response};
use Result;
pub trait HttpSend { pub trait HttpSend {
fn execute(&self, client: &Client, request: Request) -> Result<Response>; fn execute(&self, client: &Client, request: Request) -> Result<Response>;

@ -49,13 +49,13 @@ use std::{borrow::Cow, ops};
use reqwest::{ use reqwest::{
header::{Authorization, Bearer, Headers}, header::{Authorization, Bearer, Headers},
Client, Client,
Response,
RequestBuilder, RequestBuilder,
Response,
}; };
use entities::prelude::*; use entities::prelude::*;
use page::Page;
use http_send::{HttpSend, HttpSender}; use http_send::{HttpSend, HttpSender};
use page::Page;
pub use data::Data; pub use data::Data;
pub use errors::{ApiError, Error, Result}; pub use errors::{ApiError, Error, Result};
@ -265,10 +265,9 @@ impl<H: HttpSend> Mastodon<H> {
} }
pub(crate) fn send(&self, req: &mut RequestBuilder) -> Result<Response> { pub(crate) fn send(&self, req: &mut RequestBuilder) -> Result<Response> {
Ok(self.http_sender.send( Ok(self
&self.client, .http_sender
req.headers(self.headers.clone()) .send(&self.client, req.headers(self.headers.clone()))?)
)?)
} }
} }
@ -338,11 +337,7 @@ impl<H: HttpSend> MastodonClient<H> for Mastodon<H> {
fn update_credentials(&self, changes: CredientialsBuilder) -> Result<Account> { fn update_credentials(&self, changes: CredientialsBuilder) -> Result<Account> {
let url = self.route("/api/v1/accounts/update_credentials"); let url = self.route("/api/v1/accounts/update_credentials");
let response = self.send( let response = self.send(self.client.patch(&url).multipart(changes.into_form()?))?;
self.client
.patch(&url)
.multipart(changes.into_form()?)
)?;
let status = response.status().clone(); let status = response.status().clone();
@ -360,7 +355,7 @@ impl<H: HttpSend> MastodonClient<H> for Mastodon<H> {
let response = self.send( let response = self.send(
self.client self.client
.post(&self.route("/api/v1/statuses")) .post(&self.route("/api/v1/statuses"))
.json(&status) .json(&status),
)?; )?;
deserialise(response) deserialise(response)
@ -441,9 +436,7 @@ impl<H: HttpSend> MastodonClient<H> for Mastodon<H> {
url = format!("{}{}", url, request.to_querystring()); url = format!("{}{}", url, request.to_querystring());
} }
let response = self.send( let response = self.send(&mut self.client.get(&url))?;
&mut self.client.get(&url)
)?;
Page::new(self, response) Page::new(self, response)
} }
@ -465,9 +458,7 @@ impl<H: HttpSend> MastodonClient<H> for Mastodon<H> {
url.pop(); url.pop();
} }
let response = self.send( let response = self.send(&mut self.client.get(&url))?;
&mut self.client.get(&url)
)?;
Page::new(self, response) Page::new(self, response)
} }
@ -489,9 +480,7 @@ impl<H: HttpSend> MastodonClient<H> for Mastodon<H> {
following following
); );
let response = self.send( let response = self.send(&mut self.client.get(&url))?;
&mut self.client.get(&url)
)?;
Page::new(self, response) Page::new(self, response)
} }

@ -2,12 +2,12 @@ use reqwest::{Client, RequestBuilder, Response};
use try_from::TryInto; use try_from::TryInto;
use apps::{App, Scopes}; use apps::{App, Scopes};
use http_send::{HttpSend, HttpSender};
use Data; use Data;
use Error; use Error;
use Mastodon; use Mastodon;
use MastodonBuilder; use MastodonBuilder;
use Result; use Result;
use http_send::{HttpSend, HttpSender};
/// Handles registering your mastodon app to your instance. It is recommended /// Handles registering your mastodon app to your instance. It is recommended
/// you cache your data struct to avoid registering on every run. /// you cache your data struct to avoid registering on every run.
@ -56,15 +56,12 @@ impl<H: HttpSend> Registration<H> {
Registration { Registration {
base: base.into(), base: base.into(),
client: Client::new(), client: Client::new(),
http_sender: http_sender, http_sender,
} }
} }
fn send(&self, req: &mut RequestBuilder) -> Result<Response> { fn send(&self, req: &mut RequestBuilder) -> Result<Response> {
Ok(self.http_sender.send( Ok(self.http_sender.send(&self.client, req)?)
&self.client,
req
)?)
} }
/// Register the application with the server from the `base` url. /// Register the application with the server from the `base` url.
@ -96,9 +93,7 @@ impl<H: HttpSend> Registration<H> {
{ {
let app = app.try_into()?; let app = app.try_into()?;
let url = format!("{}/api/v1/apps", self.base); let url = format!("{}/api/v1/apps", self.base);
let oauth: OAuth = self.send( let oauth: OAuth = self.send(self.client.post(&url).form(&app))?.json()?;
self.client.post(&url).form(&app)
)?.json()?;
Ok(Registered { Ok(Registered {
base: self.base, base: self.base,
@ -114,10 +109,7 @@ impl<H: HttpSend> Registration<H> {
impl<H: HttpSend> Registered<H> { impl<H: HttpSend> Registered<H> {
fn send(&self, req: &mut RequestBuilder) -> Result<Response> { fn send(&self, req: &mut RequestBuilder) -> Result<Response> {
Ok(self.http_sender.send( Ok(self.http_sender.send(&self.client, req)?)
&self.client,
req
)?)
} }
/// Returns the full url needed for authorisation. This needs to be opened /// Returns the full url needed for authorisation. This needs to be opened
@ -143,9 +135,7 @@ impl<H: HttpSend> Registered<H> {
self.redirect self.redirect
); );
let token: AccessToken = self.send( let token: AccessToken = self.send(&mut self.client.post(&url))?.json()?;
&mut self.client.post(&url)
)?.json()?;
let data = Data { let data = Data {
base: self.base.into(), base: self.base.into(),

Loading…
Cancel
Save