use std::collections::HashMap;
use futures::Future;
use {Error, Request, Service};
use dispatch::PrimitiveDispatch;
#[derive(Clone, Debug)]
pub enum Grant {
ClientCredentials,
}
impl Grant {
fn ty(&self) -> &str {
match *self {
Grant::ClientCredentials => "client_credentials",
}
}
}
enum Method {
TicketFull,
}
impl Into<u64> for Method {
#[inline]
fn into(self) -> u64 {
match self {
Method::TicketFull => 1,
}
}
}
#[derive(Clone, Debug)]
pub struct Tvm {
service: Service,
}
impl Tvm {
pub fn new(service: Service) -> Self {
Self { service: service }
}
pub fn into_inner(self) -> Service {
self.service
}
pub fn ticket(&self, id: u32, secret: &str, grant: &Grant) ->
impl Future<Item = String, Error = Error>
{
let method = Method::TicketFull.into();
let ty = grant.ty();
let args: HashMap<String, String> = HashMap::new();
let (dispatch, future) = PrimitiveDispatch::pair();
match *grant {
Grant::ClientCredentials => {
self.service.call(Request::new(method, &(id, secret, ty, args)).unwrap(), dispatch);
}
}
future
}
}
#[cfg(test)]
mod test {}