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 `posts` resource — 12 operation(s).
///
/// Posts: the explore grid, one post, share to feed, edit; likes, saves, comments, saved posts, share to a DM.
///
/// Reached through [`crate::MisarDev::posts`].
#[derive(Debug, Clone, Copy)]
pub struct PostsResource<'a> {
    pub(crate) t: &'a Transport,
}

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

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

    /// `GET /posts/:id`
    ///
    /// Public — works without a key, but the client still sends it.
    ///
    /// misardev:method posts.get
    pub async fn get(self, id: &str) -> Result<Value, MisarDevError> {
        self.t.request(Method::GET, &format!("/posts/{}", encode_path(id)), "", None).await
    }

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

    /// `GET /posts`
    ///
    /// Public — works without a key, but the client still sends it.
    ///
    /// Optional query: `cursor`, `limit`.
    ///
    /// misardev:method posts.list
    pub async fn list(self, query: Option<Value>) -> Result<Value, MisarDevError> {
        self.t.request(Method::GET, "/posts", &build_query(query.as_ref(), &[]), None).await
    }

    /// `GET /posts/:id/comments`
    ///
    /// Public — works without a key, but the client still sends it.
    ///
    /// Optional query: `cursor`, `limit`, `parentId`.
    ///
    /// misardev:method posts.listComments
    pub async fn list_comments(self, id: &str, query: Option<Value>) -> Result<Value, MisarDevError> {
        self.t.request(Method::GET, &format!("/posts/{}/comments", encode_path(id)), &build_query(query.as_ref(), &[]), None).await
    }

    /// `GET /me/saved`
    ///
    /// Optional query: `collection`, `cursor`, `limit`.
    ///
    /// misardev:method posts.listSaved
    pub async fn list_saved(self, query: Option<Value>) -> Result<Value, MisarDevError> {
        self.t.request(Method::GET, "/me/saved", &build_query(query.as_ref(), &[]), None).await
    }

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

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

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

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

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