use super::{Client, Error, Future, Owner, State};
use futures::{Future as StdFuture, IntoFuture};
use futures::future;
use hyper::client::Connect;
#[derive(Debug, Deserialize)]
struct JobsWrapper {
jobs: Vec<Job>,
}
#[derive(Debug, Deserialize, Clone)]
pub struct Job {
pub id: usize,
pub number: Option<String>,
pub state: Option<State>,
pub started_at: Option<String>,
pub finished_at: Option<String>,
pub queue: Option<String>,
pub owner: Option<Owner>,
}
pub struct Jobs<'a, C>
where
C: Clone + Connect,
{
pub(crate) travis: &'a Client<C>,
pub(crate) build_id: usize,
}
impl<'a, C> Jobs<'a, C>
where
C: Clone + Connect,
{
pub fn list(&self) -> Future<Vec<Job>> {
Box::new(
self.travis
.get(
format!(
"{host}/build/{build_id}/jobs",
host = self.travis.host,
build_id = self.build_id
).parse()
.map_err(Error::from)
.into_future(),
)
.and_then(|wrapper: JobsWrapper| future::ok(wrapper.jobs)),
)
}
}