use super::{ApiLinks, ApiMeta};
use super::{HasPagination, HasResponse, HasValue};
use {ROOT_URL, STATIC_URL_ERROR};
use chrono::{DateTime, Utc};
use method::{Get, List};
use request::ActionRequest;
use request::Request;
use url::Url;
const ACTIONS_SEGMENT: &'static str = "actions";
#[derive(Deserialize, Serialize, Debug, Clone, Getters, Setters)]
pub struct Action {
#[get = "pub"]
id: usize,
#[get = "pub"]
status: String,
#[get = "pub"]
started_at: DateTime<Utc>,
#[get = "pub"]
completed_at: Option<DateTime<Utc>>,
#[get = "pub"]
resource_id: usize,
#[get = "pub"]
resource_type: String,
#[get = "pub"]
region_slug: Option<String>,
}
impl Action {
pub fn get(id: usize) -> ActionRequest<Get, Action> {
let mut url = ROOT_URL.clone();
url.path_segments_mut()
.expect(STATIC_URL_ERROR)
.push(ACTIONS_SEGMENT)
.push(&id.to_string());
Request::new(url)
}
pub fn list() -> ActionRequest<List, Vec<Action>> {
let mut url = ROOT_URL.clone();
url.path_segments_mut().expect(STATIC_URL_ERROR).push(
ACTIONS_SEGMENT,
);
Request::new(url)
}
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ActionResponse {
action: Action,
}
impl HasValue for ActionResponse {
type Value = Action;
fn value(self) -> Action {
self.action
}
}
impl HasResponse for Action {
type Response = ActionResponse;
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ActionListResponse {
actions: Vec<Action>,
links: ApiLinks,
meta: ApiMeta,
}
impl HasResponse for Vec<Action> {
type Response = ActionListResponse;
}
impl HasPagination for ActionListResponse {
fn next_page(&self) -> Option<Url> {
self.links.next()
}
}
impl HasValue for ActionListResponse {
type Value = Vec<Action>;
fn value(self) -> Vec<Action> {
self.actions
}
}