Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TODO: write documents of get, and post method #12

Open
hppRC opened this issue Jun 1, 2020 · 0 comments
Open

TODO: write documents of get, and post method #12

hppRC opened this issue Jun 1, 2020 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation WIP

Comments

@hppRC
Copy link
Owner

hppRC commented Jun 1, 2020

kuon::TwitterAPI::get is below

pub(crate) async fn get<T>(&self, endpoint: &str, params: &HashMap<&str, &str>) -> Result<T>
where
    T: DeserializeOwned,
{
    let header_bearer = format!("Bearer {}", self.bearer.access_token);

    let mut headers = HeaderMap::new();
    headers.insert(AUTHORIZATION, header_bearer.parse()?);

    let text = self
        .client
        .get(endpoint)
        .query(&params)
        .headers(headers)
        .send()
        .await?
        .text()
        .await?;

    let result = serde_json::from_str(&text)?;
    Ok(result)
}

This method sets query params in the URL.
The OAuth1.1 needs query params to calculate the OAuth signature and set it in the request header. It's too boring to calculate with each request, so this method provides easy ways for developers to implement a custom API method.

The kuon::TwitterAPI::post method is the same.

@hppRC hppRC self-assigned this Jun 1, 2020
@hppRC hppRC added documentation Improvements or additions to documentation WIP labels Jun 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation WIP
Projects
None yet
Development

No branches or pull requests

1 participant