Update to the 2018 edition

Only 2 years later :eyeroll:
This commit is contained in:
Paul Woolcock
2020-06-11 12:09:52 -04:00
parent 17c727f5c6
commit 16bc060407
29 changed files with 30247 additions and 88 deletions
+1
View File
@@ -8,6 +8,7 @@ readme = "README.md"
repository = "https://github.com/pwoolcoc/elefren.git"
keywords = ["api", "web", "social", "mastodon", "wrapper"]
categories = ["web-programming", "web-programming::http-client", "api-bindings"]
edition = "2018"
[dependencies]
doc-comment = "0.3"
+2 -2
View File
@@ -5,11 +5,11 @@ extern crate pretty_env_logger;
extern crate elefren;
mod register;
use register::MastodonClient;
use crate::register::MastodonClient;
use std::error;
#[cfg(feature = "toml")]
fn main() -> Result<(), Box<error::Error>> {
fn main() -> Result<(), Box<dyn error::Error>> {
let mastodon = register::get_mastodon_data()?;
let input = register::read_line("Enter the account id you'd like to follow: ")?;
let new_follow = mastodon.follow(input.trim())?;
+2 -2
View File
@@ -5,11 +5,11 @@ extern crate pretty_env_logger;
extern crate elefren;
mod register;
use register::MastodonClient;
use crate::register::MastodonClient;
use std::error;
#[cfg(feature = "toml")]
fn main() -> Result<(), Box<error::Error>> {
fn main() -> Result<(), Box<dyn error::Error>> {
let mastodon = register::get_mastodon_data()?;
for account in mastodon.follows_me()?.items_iter() {
println!("{}", account.acct);
+2 -2
View File
@@ -5,11 +5,11 @@ extern crate pretty_env_logger;
extern crate elefren;
mod register;
use register::MastodonClient;
use crate::register::MastodonClient;
use std::error;
#[cfg(feature = "toml")]
fn main() -> Result<(), Box<error::Error>> {
fn main() -> Result<(), Box<dyn error::Error>> {
let mastodon = register::get_mastodon_data()?;
let tl = mastodon.get_home_timeline()?;
+2 -2
View File
@@ -5,11 +5,11 @@ extern crate pretty_env_logger;
extern crate elefren;
mod register;
use register::MastodonClient;
use crate::register::MastodonClient;
use std::error;
#[cfg(feature = "toml")]
fn main() -> Result<(), Box<error::Error>> {
fn main() -> Result<(), Box<dyn error::Error>> {
let mastodon = register::get_mastodon_data()?;
let you = mastodon.verify_credentials()?;
+4 -4
View File
@@ -11,14 +11,14 @@ use elefren::helpers::toml;
#[allow(dead_code)]
#[cfg(feature = "toml")]
fn main() -> Result<(), Box<Error>> {
fn main() -> Result<(), Box<dyn Error>> {
register()?;
Ok(())
}
#[allow(dead_code)]
#[cfg(feature = "toml")]
pub fn get_mastodon_data() -> Result<Mastodon, Box<Error>> {
pub fn get_mastodon_data() -> Result<Mastodon, Box<dyn Error>> {
if let Ok(data) = toml::from_file("mastodon-data.toml") {
Ok(Mastodon::from(data))
} else {
@@ -27,7 +27,7 @@ pub fn get_mastodon_data() -> Result<Mastodon, Box<Error>> {
}
#[cfg(feature = "toml")]
pub fn register() -> Result<Mastodon, Box<Error>> {
pub fn register() -> Result<Mastodon, Box<dyn Error>> {
let website = read_line("Please enter your mastodon instance url:")?;
let registration = Registration::new(website.trim())
.client_name("elefren-examples")
@@ -43,7 +43,7 @@ pub fn register() -> Result<Mastodon, Box<Error>> {
}
#[cfg(feature = "toml")]
pub fn read_line(message: &str) -> Result<String, Box<Error>> {
pub fn read_line(message: &str) -> Result<String, Box<dyn Error>> {
println!("{}", message);
let mut input = String::new();
+2 -2
View File
@@ -5,11 +5,11 @@ extern crate pretty_env_logger;
extern crate elefren;
mod register;
use register::MastodonClient;
use crate::register::MastodonClient;
use std::error;
#[cfg(feature = "toml")]
fn main() -> Result<(), Box<error::Error>> {
fn main() -> Result<(), Box<dyn error::Error>> {
let mastodon = register::get_mastodon_data()?;
let input = register::read_line("Enter the term you'd like to search: ")?;
let result = mastodon.search(&input, false)?;
+2 -2
View File
@@ -5,11 +5,11 @@ extern crate pretty_env_logger;
extern crate elefren;
mod register;
use register::MastodonClient;
use crate::register::MastodonClient;
use std::error;
#[cfg(feature = "toml")]
fn main() -> Result<(), Box<error::Error>> {
fn main() -> Result<(), Box<dyn error::Error>> {
let mastodon = register::get_mastodon_data()?;
let input = register::read_line("Enter the path to the photo you'd like to post: ")?;
+30158
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -2,8 +2,8 @@ use std::borrow::Cow;
use try_from::TryInto;
use errors::{Error, Result};
use scopes::Scopes;
use crate::errors::{Error, Result};
use crate::scopes::Scopes;
/// Represents an application that can be registered with a mastodon instance
#[derive(Clone, Debug, Default, Serialize, PartialEq)]
+1 -1
View File
@@ -2,7 +2,7 @@
use chrono::prelude::*;
use serde::de::{self, Deserialize, Deserializer, Unexpected};
use status_builder;
use crate::status_builder;
use std::path::PathBuf;
/// A struct representing an Account.
+1 -1
View File
@@ -1,4 +1,4 @@
use entities::{notification::Notification, status::Status};
use crate::entities::{notification::Notification, status::Status};
#[derive(Debug, Clone)]
/// Events that come from the /streaming/user API call
+2 -2
View File
@@ -1,5 +1,5 @@
use http_send::HttpSend;
use page::Page;
use crate::http_send::HttpSend;
use crate::page::Page;
use serde::Deserialize;
/// Abstracts away the `next_page` logic into a single stream of items
+2 -2
View File
@@ -2,8 +2,8 @@
use super::prelude::*;
use chrono::prelude::*;
use entities::card::Card;
use status_builder::Visibility;
use crate::entities::card::Card;
use crate::status_builder::Visibility;
/// A status from the instance.
#[derive(Debug, Clone, Deserialize, PartialEq)]
+4 -4
View File
@@ -8,9 +8,9 @@ use serde_json::Error as SerdeError;
use serde_qs::Error as SerdeQsError;
use serde_urlencoded::ser::Error as UrlEncodedError;
#[cfg(feature = "toml")]
use tomlcrate::de::Error as TomlDeError;
use crate::tomlcrate::de::Error as TomlDeError;
#[cfg(feature = "toml")]
use tomlcrate::ser::Error as TomlSerError;
use crate::tomlcrate::ser::Error as TomlSerError;
use url::ParseError as UrlError;
use tungstenite::error::Error as WebSocketError;
@@ -128,7 +128,7 @@ macro_rules! from {
$(#[$met])*
impl From<$typ> for Error {
fn from(from: $typ) -> Self {
use Error::*;
use crate::Error::*;
$variant(from)
}
}
@@ -237,7 +237,7 @@ mod tests {
#[cfg(feature = "toml")]
#[test]
fn from_toml_de_error() {
use tomlcrate;
use crate::tomlcrate;
let err: TomlDeError = tomlcrate::from_str::<()>("not valid toml").unwrap_err();
let err: Error = Error::from(err);
assert_is!(err, Error::TomlDe(..));
+4 -4
View File
@@ -1,9 +1,9 @@
use std::io::{self, BufRead, Write};
use errors::Result;
use http_send::HttpSend;
use registration::Registered;
use Mastodon;
use crate::errors::Result;
use crate::http_send::HttpSend;
use crate::registration::Registered;
use crate::Mastodon;
/// Finishes the authentication process for the given `Registered` object,
/// using the command-line
+2 -2
View File
@@ -1,7 +1,7 @@
use envy;
use data::Data;
use Result;
use crate::data::Data;
use crate::Result;
/// Attempts to deserialize a Data struct from the environment
pub fn from_env() -> Result<Data> {
+2 -2
View File
@@ -6,8 +6,8 @@ use std::{
use serde_json;
use data::Data;
use Result;
use crate::data::Data;
use crate::Result;
/// Attempts to deserialize a Data struct from a string
pub fn from_str(s: &str) -> Result<Data> {
+3 -3
View File
@@ -4,10 +4,10 @@ use std::{
path::Path,
};
use tomlcrate;
use crate::tomlcrate;
use data::Data;
use Result;
use crate::data::Data;
use crate::Result;
/// Attempts to deserialize a Data struct from a string
pub fn from_str(s: &str) -> Result<Data> {
+1 -1
View File
@@ -1,6 +1,6 @@
use reqwest::{Client, Request, RequestBuilder, Response};
use std::fmt::Debug;
use Result;
use crate::Result;
/// Abstracts away the process of turning an HTTP request into an HTTP response
pub trait HttpSend: Clone + Debug {
+19 -19
View File
@@ -5,9 +5,9 @@
//! ```no_run
//! # extern crate elefren;
//! # fn main() {
//! # try().unwrap();
//! # run().unwrap();
//! # }
//! # fn try() -> elefren::Result<()> {
//! # fn run() -> elefren::Result<()> {
//! use elefren::{helpers::cli, prelude::*};
//!
//! let registration = Registration::new("https://mastodon.social")
@@ -114,23 +114,23 @@ use reqwest::{Client, RequestBuilder, Response};
use tap_reader::Tap;
use tungstenite::client::AutoStream;
use entities::prelude::*;
use http_send::{HttpSend, HttpSender};
use page::Page;
use crate::entities::prelude::*;
use crate::http_send::{HttpSend, HttpSender};
use crate::page::Page;
pub use data::Data;
pub use errors::{ApiError, Error, Result};
pub use crate::data::Data;
pub use crate::errors::{ApiError, Error, Result};
pub use isolang::Language;
pub use mastodon_client::{MastodonClient, MastodonUnauthenticated};
pub use registration::Registration;
pub use requests::{
pub use crate::mastodon_client::{MastodonClient, MastodonUnauthenticated};
pub use crate::registration::Registration;
pub use crate::requests::{
AddFilterRequest,
AddPushRequest,
StatusesRequest,
UpdateCredsRequest,
UpdatePushRequest,
};
pub use status_builder::{NewStatus, StatusBuilder};
pub use crate::status_builder::{NewStatus, StatusBuilder};
/// Registering your App
pub mod apps;
@@ -159,14 +159,14 @@ pub mod status_builder;
mod macros;
/// Automatically import the things you need
pub mod prelude {
pub use scopes::Scopes;
pub use Data;
pub use Mastodon;
pub use MastodonClient;
pub use NewStatus;
pub use Registration;
pub use StatusBuilder;
pub use StatusesRequest;
pub use crate::scopes::Scopes;
pub use crate::Data;
pub use crate::Mastodon;
pub use crate::MastodonClient;
pub use crate::NewStatus;
pub use crate::Registration;
pub use crate::StatusBuilder;
pub use crate::StatusesRequest;
}
/// Your mastodon application client, handles all requests to and from Mastodon.
+6 -6
View File
@@ -1,17 +1,17 @@
use std::borrow::Cow;
use entities::prelude::*;
use errors::Result;
use http_send::{HttpSend, HttpSender};
use page::Page;
use requests::{
use crate::entities::prelude::*;
use crate::errors::Result;
use crate::http_send::{HttpSend, HttpSender};
use crate::page::Page;
use crate::requests::{
AddFilterRequest,
AddPushRequest,
StatusesRequest,
UpdateCredsRequest,
UpdatePushRequest,
};
use status_builder::NewStatus;
use crate::status_builder::NewStatus;
/// Represents the set of methods that a Mastodon Client can do, so that
/// implementations might be swapped out for testing
+2 -2
View File
@@ -1,11 +1,11 @@
use super::{deserialise, Mastodon, Result};
use entities::itemsiter::ItemsIter;
use crate::entities::itemsiter::ItemsIter;
use hyper_old_types::header::{parsing, Link, RelationType};
use reqwest::{header::LINK, Response};
use serde::Deserialize;
use url::Url;
use http_send::HttpSend;
use crate::http_send::HttpSend;
macro_rules! pages {
($($direction:ident: $fun:ident),*) => {
+8 -8
View File
@@ -4,14 +4,14 @@ use reqwest::{Client, RequestBuilder, Response};
use try_from::TryInto;
use url::percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET};
use apps::{App, AppBuilder};
use http_send::{HttpSend, HttpSender};
use scopes::Scopes;
use Data;
use Error;
use Mastodon;
use MastodonBuilder;
use Result;
use crate::apps::{App, AppBuilder};
use crate::http_send::{HttpSend, HttpSender};
use crate::scopes::Scopes;
use crate::Data;
use crate::Error;
use crate::Mastodon;
use crate::MastodonBuilder;
use crate::Result;
const DEFAULT_REDIRECT_URI: &'static str = "urn:ietf:wg:oauth:2.0:oob";
+1 -1
View File
@@ -1,4 +1,4 @@
use entities::filter::FilterContext;
use crate::entities::filter::FilterContext;
use std::time::Duration;
/// Form used to create a filter
+5 -5
View File
@@ -1,5 +1,5 @@
use entities::push::{add_subscription, update_data};
use errors::Result;
use crate::entities::push::{add_subscription, update_data};
use crate::errors::Result;
/// Container for the key & auth strings for an AddPushRequest
///
@@ -169,7 +169,7 @@ impl AddPushRequest {
}
pub(crate) fn build(&self) -> Result<add_subscription::Form> {
use entities::push::{
use crate::entities::push::{
add_subscription::{Data, Form, Keys, Subscription},
Alerts,
};
@@ -326,7 +326,7 @@ impl UpdatePushRequest {
}
pub(crate) fn build(&self) -> update_data::Form {
use entities::push::{
use crate::entities::push::{
update_data::{Data, Form},
Alerts,
};
@@ -361,7 +361,7 @@ impl UpdatePushRequest {
#[cfg(test)]
mod tests {
use super::*;
use entities::push::{add_subscription, update_data, Alerts};
use crate::entities::push::{add_subscription, update_data, Alerts};
#[test]
fn test_keys_new() {
+1 -1
View File
@@ -1,4 +1,4 @@
use errors::Error;
use crate::errors::Error;
use serde_qs;
use std::{borrow::Cow, convert::Into};
+5 -5
View File
@@ -3,9 +3,9 @@ use std::{
path::{Path, PathBuf},
};
use entities::account::{Credentials, MetadataField, UpdateSource};
use errors::Result;
use status_builder;
use crate::entities::account::{Credentials, MetadataField, UpdateSource};
use crate::errors::Result;
use crate::status_builder;
/// Builder to pass to the Mastodon::update_credentials method
///
@@ -202,8 +202,8 @@ impl UpdateCredsRequest {
#[cfg(test)]
mod tests {
use super::*;
use entities::account::{Credentials, MetadataField, UpdateSource};
use status_builder::Visibility;
use crate::entities::account::{Credentials, MetadataField, UpdateSource};
use crate::status_builder::Visibility;
#[test]
fn test_update_creds_request_new() {
+1 -1
View File
@@ -8,7 +8,7 @@ use std::{
use serde::ser::{Serialize, Serializer};
use errors::Error;
use crate::errors::Error;
use serde::{Deserialize, Deserializer};
use serde::de::{self, Visitor};