Merge pull request #2 from vberger/master
Add support for authenticated endpoints.
This commit is contained in:
commit
324fc5dc0d
@ -14,6 +14,8 @@ pub enum Error {
|
|||||||
SerdeJson(SerdeJsonError),
|
SerdeJson(SerdeJsonError),
|
||||||
/// An error when serializing a query string value.
|
/// An error when serializing a query string value.
|
||||||
SerdeUrlEncodedSerialize(SerdeUrlEncodedSerializeError),
|
SerdeUrlEncodedSerialize(SerdeUrlEncodedSerializeError),
|
||||||
|
/// Queried endpoint requires authentication but was called on an anonymous client
|
||||||
|
AuthenticationRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<HyperError> for Error {
|
impl From<HyperError> for Error {
|
||||||
|
@ -84,6 +84,14 @@ impl Client {
|
|||||||
|
|
||||||
url.set_query(Some(&serde_urlencoded::to_string(&query_params)?));
|
url.set_query(Some(&serde_urlencoded::to_string(&query_params)?));
|
||||||
|
|
||||||
|
if E::requires_authentication() {
|
||||||
|
if let Some(ref session) = self.session {
|
||||||
|
url.query_pairs_mut().append_pair("access_token", &session.access_token);
|
||||||
|
} else {
|
||||||
|
return Err(Error::AuthenticationRequired)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut request = HyperRequest::new(E::method().into_hyper(), url);
|
let mut request = HyperRequest::new(E::method().into_hyper(), url);
|
||||||
|
|
||||||
match E::method() {
|
match E::method() {
|
||||||
|
@ -4,7 +4,10 @@ use url::Host;
|
|||||||
/// An active user session with a Matrix homeserver, allowing authenticated requests.
|
/// An active user session with a Matrix homeserver, allowing authenticated requests.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Session {
|
pub struct Session {
|
||||||
access_token: String,
|
/// The access token of this session
|
||||||
homeserver: Host,
|
pub access_token: String,
|
||||||
user_id: UserId,
|
/// The homeserver this session is associated with
|
||||||
|
pub homeserver: Host,
|
||||||
|
/// the ID of the user owning this session
|
||||||
|
pub user_id: UserId,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user