Fixed example code, and {un}follow routes.
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
mod register;
|
||||||
|
|
||||||
|
use std::error;
|
||||||
|
|
||||||
|
fn main() -> Result<(), Box<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().parse()?)?;
|
||||||
|
|
||||||
|
println!("{:#?}", new_follow);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
extern crate mammut;
|
|
||||||
extern crate toml;
|
|
||||||
|
|
||||||
use std::io;
|
|
||||||
use std::fs::File;
|
|
||||||
use std::io::prelude::*;
|
|
||||||
|
|
||||||
use mammut::{Data, Mastodon, Registration};
|
|
||||||
use mammut::apps::{AppBuilder, Scopes};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let mastodon = match File::open("mastodon-data.toml") {
|
|
||||||
Ok(mut file) => {
|
|
||||||
let mut config = String::new();
|
|
||||||
file.read_to_string(&mut config).unwrap();
|
|
||||||
let data: Data = toml::from_str(&config).unwrap();
|
|
||||||
Mastodon::from_data(data)
|
|
||||||
},
|
|
||||||
Err(_) => register(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let you = mastodon.verify_credentials().unwrap();
|
|
||||||
|
|
||||||
println!("{:#?}", you);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register() -> Mastodon {
|
|
||||||
let app = AppBuilder {
|
|
||||||
client_name: "mammut-examples",
|
|
||||||
redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
|
|
||||||
scopes: Scopes::Read,
|
|
||||||
website: Some("https://github.com/Aaronepower/mammut"),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut registration = Registration::new("https://mastodon.social");
|
|
||||||
registration.register(app).unwrap();;
|
|
||||||
let url = registration.authorise().unwrap();
|
|
||||||
|
|
||||||
println!("Click this link to authorize on Mastodon: {}", url);
|
|
||||||
println!("Paste the returned authorization code: ");
|
|
||||||
|
|
||||||
let mut input = String::new();
|
|
||||||
io::stdin().read_line(&mut input).unwrap();
|
|
||||||
|
|
||||||
let code = input.trim();
|
|
||||||
let mastodon = registration.create_access_token(code.to_string()).unwrap();
|
|
||||||
|
|
||||||
// Save app data for using on the next run.
|
|
||||||
let toml = toml::to_string(&*mastodon).unwrap();
|
|
||||||
let mut file = File::create("mastodon-data.toml").unwrap();
|
|
||||||
file.write_all(toml.as_bytes()).unwrap();
|
|
||||||
|
|
||||||
mastodon
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
mod register;
|
||||||
|
|
||||||
|
use std::error;
|
||||||
|
|
||||||
|
fn main() -> Result<(), Box<error::Error>> {
|
||||||
|
let mastodon = register::get_mastodon_data()?;
|
||||||
|
let you = mastodon.verify_credentials()?;
|
||||||
|
|
||||||
|
println!("{:#?}", you);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
extern crate mammut;
|
||||||
|
extern crate toml;
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
error::Error,
|
||||||
|
fs,
|
||||||
|
io,
|
||||||
|
};
|
||||||
|
|
||||||
|
use self::mammut::{
|
||||||
|
apps::{
|
||||||
|
AppBuilder,
|
||||||
|
Scopes
|
||||||
|
},
|
||||||
|
Mastodon,
|
||||||
|
Registration
|
||||||
|
};
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn main() -> Result<(), Box<Error>> {
|
||||||
|
register()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn get_mastodon_data() -> Result<Mastodon, Box<Error>> {
|
||||||
|
if let Ok(config) = fs::read_to_string("mastodon-data.toml") {
|
||||||
|
Ok(Mastodon::from_data(toml::from_str(&config)?))
|
||||||
|
} else {
|
||||||
|
register()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn register() -> Result<Mastodon, Box<Error>> {
|
||||||
|
let app = AppBuilder {
|
||||||
|
client_name: "mammut-examples",
|
||||||
|
redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
|
||||||
|
scopes: Scopes::Read,
|
||||||
|
website: Some("https://github.com/Aaronepower/mammut"),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut registration = Registration::new("https://mastodon.social");
|
||||||
|
registration.register(app)?;
|
||||||
|
let url = registration.authorise()?;
|
||||||
|
|
||||||
|
println!("Click this link to authorize on Mastodon: {}", url);
|
||||||
|
let input = read_line("Paste the returned authorization code: ")?;
|
||||||
|
|
||||||
|
let code = input.trim();
|
||||||
|
let mastodon = registration.create_access_token(code.to_string())?;
|
||||||
|
|
||||||
|
// Save app data for using on the next run.
|
||||||
|
let toml = toml::to_string(&*mastodon)?;
|
||||||
|
fs::write("mastodon-data.toml", toml.as_bytes())?;
|
||||||
|
|
||||||
|
Ok(mastodon)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_line(message: &str) -> Result<String, Box<Error>> {
|
||||||
|
println!("{}", message);
|
||||||
|
|
||||||
|
let mut input = String::new();
|
||||||
|
io::stdin().read_line(&mut input)?;
|
||||||
|
|
||||||
|
Ok(input)
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
mod register;
|
||||||
|
|
||||||
|
use std::error;
|
||||||
|
|
||||||
|
fn main() -> Result<(), Box<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_accounts(&input, None, true)?;
|
||||||
|
|
||||||
|
println!("{:#?}", result.initial_items);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@ use std::fmt;
|
|||||||
|
|
||||||
/// Builder struct for defining your application.
|
/// Builder struct for defining your application.
|
||||||
/// ```
|
/// ```
|
||||||
|
/// use mammut::apps::{AppBuilder, Scopes};
|
||||||
|
///
|
||||||
/// let app = AppBuilder {
|
/// let app = AppBuilder {
|
||||||
/// client_name: "mammut_test",
|
/// client_name: "mammut_test",
|
||||||
/// redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
|
/// redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
|
||||||
|
|||||||
+8
-14
@@ -92,9 +92,8 @@ macro_rules! methods {
|
|||||||
macro_rules! paged_routes {
|
macro_rules! paged_routes {
|
||||||
|
|
||||||
(($method:ident) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
(($method:ident) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
||||||
/// Equivalent to `/api/v1/
|
/// Equivalent to /api/v1/
|
||||||
#[doc = $url]
|
#[doc = $url]
|
||||||
/// `
|
|
||||||
///
|
///
|
||||||
#[doc = "# Errors"]
|
#[doc = "# Errors"]
|
||||||
/// If `access_token` is not set.
|
/// If `access_token` is not set.
|
||||||
@@ -116,9 +115,8 @@ macro_rules! paged_routes {
|
|||||||
macro_rules! route {
|
macro_rules! route {
|
||||||
|
|
||||||
((post multipart ($($param:ident: $typ:ty,)*)) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
((post multipart ($($param:ident: $typ:ty,)*)) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
||||||
/// Equivalent to `/api/v1/
|
/// Equivalent to /api/v1/
|
||||||
#[doc = $url]
|
#[doc = $url]
|
||||||
/// `
|
|
||||||
///
|
///
|
||||||
#[doc = "# Errors"]
|
#[doc = "# Errors"]
|
||||||
/// If `access_token` is not set.
|
/// If `access_token` is not set.
|
||||||
@@ -150,9 +148,8 @@ macro_rules! route {
|
|||||||
};
|
};
|
||||||
|
|
||||||
(($method:ident ($($param:ident: $typ:ty,)*)) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
(($method:ident ($($param:ident: $typ:ty,)*)) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
||||||
/// Equivalent to `/api/v1/
|
/// Equivalent to /api/v1/
|
||||||
#[doc = $url]
|
#[doc = $url]
|
||||||
/// `
|
|
||||||
///
|
///
|
||||||
#[doc = "# Errors"]
|
#[doc = "# Errors"]
|
||||||
/// If `access_token` is not set.
|
/// If `access_token` is not set.
|
||||||
@@ -184,9 +181,8 @@ macro_rules! route {
|
|||||||
};
|
};
|
||||||
|
|
||||||
(($method:ident) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
(($method:ident) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
||||||
/// Equivalent to `/api/v1/
|
/// Equivalent to /api/v1/
|
||||||
#[doc = $url]
|
#[doc = $url]
|
||||||
/// `
|
|
||||||
///
|
///
|
||||||
#[doc = "# Errors"]
|
#[doc = "# Errors"]
|
||||||
/// If `access_token` is not set.
|
/// If `access_token` is not set.
|
||||||
@@ -204,9 +200,8 @@ macro_rules! route_id {
|
|||||||
|
|
||||||
($(($method:ident) $name:ident: $url:expr => $ret:ty,)*) => {
|
($(($method:ident) $name:ident: $url:expr => $ret:ty,)*) => {
|
||||||
$(
|
$(
|
||||||
/// Equivalent to `/api/v1/
|
/// Equivalent to /api/v1/
|
||||||
#[doc = $url]
|
#[doc = $url]
|
||||||
/// `
|
|
||||||
///
|
///
|
||||||
#[doc = "# Errors"]
|
#[doc = "# Errors"]
|
||||||
/// If `access_token` is not set.
|
/// If `access_token` is not set.
|
||||||
@@ -220,9 +215,8 @@ macro_rules! route_id {
|
|||||||
macro_rules! paged_routes_with_id {
|
macro_rules! paged_routes_with_id {
|
||||||
|
|
||||||
(($method:ident) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
(($method:ident) $name:ident: $url:expr => $ret:ty, $($rest:tt)*) => {
|
||||||
/// Equivalent to `/api/v1/
|
/// Equivalent to /api/v1/
|
||||||
#[doc = $url]
|
#[doc = $url]
|
||||||
/// `
|
|
||||||
///
|
///
|
||||||
#[doc = "# Errors"]
|
#[doc = "# Errors"]
|
||||||
/// If `access_token` is not set.
|
/// If `access_token` is not set.
|
||||||
@@ -415,8 +409,8 @@ impl Mastodon {
|
|||||||
|
|
||||||
route_id! {
|
route_id! {
|
||||||
(get) get_account: "accounts/{}" => Account,
|
(get) get_account: "accounts/{}" => Account,
|
||||||
(get) follow: "accounts/{}/follow" => Account,
|
(post) follow: "accounts/{}/follow" => Account,
|
||||||
(get) unfollow: "accounts/{}/unfollow" => Account,
|
(post) unfollow: "accounts/{}/unfollow" => Account,
|
||||||
(get) block: "accounts/{}/block" => Account,
|
(get) block: "accounts/{}/block" => Account,
|
||||||
(get) unblock: "accounts/{}/unblock" => Account,
|
(get) unblock: "accounts/{}/unblock" => Account,
|
||||||
(get) mute: "accounts/{}/mute" => Account,
|
(get) mute: "accounts/{}/mute" => Account,
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ struct AccessToken {
|
|||||||
impl Registration {
|
impl Registration {
|
||||||
/// Construct a new registration process to the instance of the `base` url.
|
/// Construct a new registration process to the instance of the `base` url.
|
||||||
/// ```
|
/// ```
|
||||||
|
/// use mammut::registration::Registration;
|
||||||
|
///
|
||||||
/// let registration = Registration::new("https://mastodon.social");
|
/// let registration = Registration::new("https://mastodon.social");
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new<I: Into<String>>(base: I) -> Self {
|
pub fn new<I: Into<String>>(base: I) -> Self {
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ impl StatusBuilder {
|
|||||||
|
|
||||||
/// Create a new status with text.
|
/// Create a new status with text.
|
||||||
/// ```
|
/// ```
|
||||||
|
/// use mammut::status_builder::StatusBuilder;
|
||||||
|
///
|
||||||
/// let status = StatusBuilder::new("Hello World!".into());
|
/// let status = StatusBuilder::new("Hello World!".into());
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new(status: String) -> Self {
|
pub fn new(status: String) -> Self {
|
||||||
|
|||||||
Reference in New Issue
Block a user