misardev 1.1.0

Async Rust client for the Misar.Dev API: create projects, write files, build and deploy, start from templates, run OpenAI-compatible chat completions, search code and read usage. Retries, typed plan-limit errors, SSE streaming.
Documentation
// GENERATED by scripts/generate-sdk-resources.mjs from sdks/manifest.json.
// Do not edit by hand — change the route, run `pnpm sdk:sync`, and regenerate.

use crate::error::MisarDevError;
use crate::transport::Transport;
use crate::transport::body_or_empty;
use crate::transport::build_query;
use crate::transport::encode_path;
use reqwest::Method;
use serde_json::Value;

/// The `collections` resource — 6 operation(s).
///
/// Saved-post collections: create, rename, delete, add and remove posts.
///
/// Reached through [`crate::MisarDev::collections`].
#[derive(Debug, Clone, Copy)]
pub struct CollectionsResource<'a> {
    pub(crate) t: &'a Transport,
}

impl CollectionsResource<'_> {
    /// `POST /collections/:id/items`
    ///
    /// Optional query: `postId`.
    ///
    /// misardev:method collections.addPost
    pub async fn add_post(self, id: &str, body: Option<Value>, query: Option<Value>) -> Result<Value, MisarDevError> {
        self.t.request(Method::POST, &format!("/collections/{}/items", encode_path(id)), &build_query(query.as_ref(), &[]), Some(body_or_empty(body))).await
    }

    /// `POST /collections`
    ///
    /// misardev:method collections.create
    pub async fn create(self, body: Option<Value>) -> Result<Value, MisarDevError> {
        self.t.request(Method::POST, "/collections", "", Some(body_or_empty(body))).await
    }

    /// `DELETE /collections/:id`
    ///
    /// misardev:method collections.delete
    pub async fn delete(self, id: &str) -> Result<Value, MisarDevError> {
        self.t.request(Method::DELETE, &format!("/collections/{}", encode_path(id)), "", None).await
    }

    /// `GET /collections`
    ///
    /// misardev:method collections.list
    pub async fn list(self) -> Result<Value, MisarDevError> {
        self.t.request(Method::GET, "/collections", "", None).await
    }

    /// `DELETE /collections/:id/items`
    ///
    /// Optional query: `postId`.
    ///
    /// misardev:method collections.removePost
    pub async fn remove_post(self, id: &str, body: Option<Value>, query: Option<Value>) -> Result<Value, MisarDevError> {
        self.t.request(Method::DELETE, &format!("/collections/{}/items", encode_path(id)), &build_query(query.as_ref(), &[]), Some(body_or_empty(body))).await
    }

    /// `PATCH /collections/:id`
    ///
    /// misardev:method collections.update
    pub async fn update(self, id: &str, body: Option<Value>) -> Result<Value, MisarDevError> {
        self.t.request(Method::PATCH, &format!("/collections/{}", encode_path(id)), "", Some(body_or_empty(body))).await
    }
}