Skip to content
This repository was archived by the owner on Dec 5, 2023. It is now read-only.

Commit cac2381

Browse files
committed
Merge branch 'master' of https://github.com/tinaun/mastodon-rs
2 parents aa6d0f3 + 0d68c7b commit cac2381

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/mastodon.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,24 @@ pub struct Mastodon {
3535
client: Client,
3636
}
3737

38+
#[macro_export]
39+
macro_rules! new_mastodon_instance {
40+
($envar: expr) => { Mastodon::from_access_token($envar, "mastodon.social") };
41+
($envar: expr, $domain: expr) => { Mastodon::from_access_token($envar, $domain) };
42+
() => { Mastodon::from_access_token("MASTODON_TOKEN", "mastodon.social") }
43+
}
44+
3845
impl Mastodon {
3946
/// create mastodon session from access_token (as environment variable)
40-
pub fn from_access_token(envar: &str) -> Result<Self> {
47+
pub fn from_access_token(envar: &str, domain: &str) -> Result<Self> {
4148
let token = env::var(envar).chain_err(|| "missing environment variable");
4249
let ssl = NativeTlsClient::new().chain_err(|| "error establishing tls?")?;
4350
let connector = HttpsConnector::new(ssl);
4451

4552
token.map(|access| {
4653
Mastodon {
4754
access_token: access,
48-
domain: "mastodon.social".to_string(),
55+
domain: domain.to_string(),
4956
client: Client::with_connector(connector),
5057
}
5158
})

0 commit comments

Comments
 (0)