1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use crate::{TweetResult, TwitterAPI};
use anyhow::Result;
use std::collections::HashMap;

impl TwitterAPI {
    /// # Example
    /// ```
    /// # use anyhow::Result;
    /// # async fn doc() -> Result<()> {
    ///
    /// let api = kuon::TwitterAPI::new_using_env().await?;
    /// let res = api.tweet("これはてすとなんだなも").await?;
    /// # Ok(())
    /// # }
    /// ```
    pub async fn tweet(&self, status: &str) -> Result<TweetResult> {
        let endpoint = "https://api.twitter.com/1.1/statuses/update.json";
        let params = maplit::hashmap! { "status" => status };

        self.raw_post(endpoint, &params).await
    }

    pub async fn tweet_with_params(
        &self,
        status: &str,
        params: &HashMap<&str, &str>,
    ) -> Result<TweetResult> {
        let endpoint = "https://api.twitter.com/1.1/statuses/update.json";
        let mut params = params.clone();
        params.insert("status", status);

        self.raw_post(endpoint, &params).await
    }
}