pub mod form;
pub mod settings;
use chrono::{DateTime, FixedOffset};
use serde::{Deserialize, Serialize};
use crate::client::{KintoneClient, RequestBuilder};
use crate::error::ApiError;
use crate::internal::serde_helper::{option_stringified, stringified};
use crate::model::User;
pub fn add_app(name: impl Into<String>) -> AddAppRequest {
let builder = RequestBuilder::new(http::Method::POST, "/v1/preview/app.json");
AddAppRequest {
builder,
body: AddAppRequestBody {
name: name.into(),
space: None,
thread: None,
},
}
}
pub fn get_apps() -> GetAppsRequest {
let builder = RequestBuilder::new(http::Method::GET, "/v1/apps.json");
GetAppsRequest { builder }
}
#[must_use]
pub struct AddAppRequest {
builder: RequestBuilder,
body: AddAppRequestBody,
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct AddAppRequestBody {
name: String,
space: Option<u64>,
thread: Option<u64>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AddAppResponse {
#[serde(with = "stringified")]
pub app: u64,
#[serde(with = "stringified")]
pub revision: u64,
}
impl AddAppRequest {
pub fn space(mut self, space: u64) -> Self {
self.body.space = Some(space);
self
}
pub fn thread(mut self, thread: u64) -> Self {
self.body.thread = Some(thread);
self
}
pub fn send(self, client: &KintoneClient) -> Result<AddAppResponse, ApiError> {
self.builder.send(client, self.body)
}
}
#[must_use]
pub struct GetAppsRequest {
builder: RequestBuilder,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GetAppsResponse {
pub apps: Vec<AppInfo>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AppInfo {
#[serde(with = "stringified")]
pub app_id: u64,
pub code: String,
pub name: String,
pub description: String,
#[serde(with = "option_stringified")]
pub space_id: Option<u64>,
#[serde(with = "option_stringified")]
pub thread_id: Option<u64>,
pub created_at: DateTime<FixedOffset>,
pub creator: User,
pub modified_at: DateTime<FixedOffset>,
pub modifier: User,
}
impl GetAppsRequest {
pub fn ids<I, T>(mut self, ids: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<u64>,
{
let id_strings: Vec<String> = ids.into_iter().map(|id| id.into().to_string()).collect();
self.builder = self.builder.query_array("ids", &id_strings);
self
}
pub fn codes<I, T>(mut self, codes: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<String>,
{
let code_strings: Vec<String> = codes.into_iter().map(Into::into).collect();
self.builder = self.builder.query_array("codes", &code_strings);
self
}
pub fn name(mut self, name: impl Into<String>) -> Self {
self.builder = self.builder.query("name", name.into());
self
}
pub fn space_ids<I, T>(mut self, space_ids: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<u64>,
{
let space_id_strings: Vec<String> =
space_ids.into_iter().map(|id| id.into().to_string()).collect();
self.builder = self.builder.query_array("spaceIds", &space_id_strings);
self
}
pub fn offset(mut self, offset: u64) -> Self {
self.builder = self.builder.query("offset", offset.to_string());
self
}
pub fn limit(mut self, limit: u64) -> Self {
self.builder = self.builder.query("limit", limit.to_string());
self
}
pub fn send(self, client: &KintoneClient) -> Result<GetAppsResponse, ApiError> {
self.builder.call(client)
}
}