Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions cloudflare/src/endpoints/workers/list_schedules.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use serde::{Deserialize, Serialize};

use super::WorkersSchedule;

use crate::framework::{
endpoint::{EndpointSpec, Method},
response::{ApiResult, ApiSuccess},
};

/// List Schedules
/// <https://developers.cloudflare.com/api/resources/workers/subresources/scripts/subresources/schedules/methods/get/>
#[derive(Debug)]
pub struct ListSchedules<'a> {
/// Account ID of owner of the script
pub account_identifier: &'a str,
/// The name of the script to list the schedules
pub script_name: &'a str,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct ListSchedulesResponse {
pub schedules: Vec<WorkersSchedule>,
}

impl ApiResult for ListSchedulesResponse {}

impl EndpointSpec for ListSchedules<'_> {
type JsonResponse = ListSchedulesResponse;
type ResponseType = ApiSuccess<Self::JsonResponse>;

fn method(&self) -> Method {
Method::GET
}

fn path(&self) -> String {
format!(
"accounts/{}/workers/scripts/{}/schedules",
self.account_identifier, self.script_name
)
}
}
15 changes: 15 additions & 0 deletions cloudflare/src/endpoints/workers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ mod delete_secret;
mod delete_tail;
mod list_bindings;
mod list_routes;
mod list_schedules;
mod list_secrets;
mod list_tails;
mod send_tail_heartbeat;
mod update_schedules;

pub use create_route::{CreateRoute, CreateRouteParams};
pub use create_secret::{CreateSecret, CreateSecretParams};
Expand All @@ -27,9 +29,11 @@ pub use delete_secret::DeleteSecret;
pub use delete_tail::DeleteTail;
pub use list_bindings::ListBindings;
pub use list_routes::ListRoutes;
pub use list_schedules::{ListSchedules, ListSchedulesResponse};
pub use list_secrets::ListSecrets;
pub use list_tails::ListTails;
pub use send_tail_heartbeat::SendTailHeartbeat;
pub use update_schedules::{UpdateSchedules, UpdateSchedulesResponse};

/// Workers KV Route
/// Routes are basic patterns used to enable or disable workers that match requests.
Expand Down Expand Up @@ -157,6 +161,17 @@ pub enum WorkersBinding {
impl ApiResult for WorkersBinding {}
impl ApiResult for Vec<WorkersBinding> {}

// Schedule for a Workers Script
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Default, PartialOrd, Ord)]
pub struct WorkersSchedule {
pub cron: Option<String>,
pub created_on: Option<String>,
pub modified_on: Option<String>,
}

impl ApiResult for WorkersSchedule {}
impl ApiResult for Vec<WorkersSchedule> {}

#[cfg(test)]
mod tests {
use std::collections::VecDeque;
Expand Down
49 changes: 49 additions & 0 deletions cloudflare/src/endpoints/workers/update_schedules.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use serde::Deserialize;

use super::WorkersSchedule;

use crate::framework::{
endpoint::{EndpointSpec, Method, RequestBody},
response::{ApiResult, ApiSuccess},
};

/// Update Schedules
/// <https://developers.cloudflare.com/api/resources/workers/subresources/scripts/subresources/schedules/methods/update/>
#[derive(Debug)]
pub struct UpdateSchedules<'a> {
/// Account ID of owner of the script
pub account_identifier: &'a str,
/// Name of the script, used in URLs and route configuration.
pub script_name: &'a str,
/// Schedules to be updated
pub schedules: Vec<WorkersSchedule>,
}

#[derive(Debug, Deserialize)]
pub struct UpdateSchedulesResponse {
pub schedules: Vec<WorkersSchedule>,
}

impl ApiResult for UpdateSchedulesResponse {}

impl EndpointSpec for UpdateSchedules<'_> {
type JsonResponse = UpdateSchedulesResponse;
type ResponseType = ApiSuccess<Self::JsonResponse>;

fn method(&self) -> Method {
Method::PUT
}

fn path(&self) -> String {
format!(
"accounts/{}/workers/scripts/{}/schedules",
self.account_identifier, self.script_name
)
}

#[inline]
fn body(&self) -> Option<RequestBody> {
let body = serde_json::to_string(&self.schedules).unwrap();
Some(RequestBody::Json(body))
}
}