oauth1_twitter/objects/
consumer_key.rs

1use reqwest_oauth1::Secrets;
2
3use crate::objects::{
4    authentication_access_token::AuthenticationAccessToken,
5    authentication_request_token::AuthenticationRequestToken,
6};
7
8//
9#[derive(Debug, Clone)]
10pub struct ConsumerKey {
11    pub key: String,
12    pub secret: String,
13}
14
15impl ConsumerKey {
16    pub fn new(key: impl AsRef<str>, secret: impl AsRef<str>) -> Self {
17        Self {
18            key: key.as_ref().into(),
19            secret: secret.as_ref().into(),
20        }
21    }
22
23    pub fn secrets(&self) -> Secrets {
24        Secrets::new(&self.key, &self.secret)
25    }
26
27    pub fn secrets_with_request_token(
28        &self,
29        authentication_request_token: &AuthenticationRequestToken,
30    ) -> Secrets {
31        Secrets::new(&self.key, &self.secret).token(
32            authentication_request_token.request_token.to_owned(),
33            authentication_request_token.secret.to_owned(),
34        )
35    }
36
37    pub fn secrets_with_access_token(
38        &self,
39        authentication_access_token: &AuthenticationAccessToken,
40    ) -> Secrets {
41        Secrets::new(&self.key, &self.secret).token(
42            authentication_access_token.access_token.to_owned(),
43            authentication_access_token.secret.to_owned(),
44        )
45    }
46}