proto_blue_api/generated/app/bsky/notification/
registerPush.rs1use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Input {
11 #[serde(skip_serializing_if = "Option::is_none")]
12 pub age_restricted: Option<bool>,
13 pub app_id: String,
14 pub platform: String,
15 pub service_did: String,
16 pub token: String,
17}
18
19#[derive(Debug, thiserror::Error)]
21pub enum CallError {
22 #[error("{0}")]
23 Xrpc(proto_blue_xrpc::XrpcError),
24 #[error(transparent)]
25 Transport(#[from] proto_blue_xrpc::Error),
26 #[error(transparent)]
27 Json(#[from] serde_json::Error),
28}
29
30fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
31 CallError::Xrpc(err)
32}
33
34pub async fn call(
36 client: &proto_blue_xrpc::XrpcClient,
37 input: &Input,
38 opts: Option<&proto_blue_xrpc::CallOptions>,
39) -> Result<serde_json::Value, CallError> {
40 let qp_ref: Option<&proto_blue_xrpc::QueryParams> = None;
41 let body = proto_blue_xrpc::XrpcBody::Json(serde_json::to_value(input)?);
42 let response = match client.procedure("app.bsky.notification.registerPush", qp_ref, Some(body), opts).await {
43 Ok(r) => r,
44 Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
45 Err(e) => return Err(CallError::Transport(e)),
46 };
47 Ok(response.data)
48}
49
50#[cfg(feature = "server")]
52pub fn register<F, Fut>(
53server: proto_blue_xrpc::XrpcServer,
54handler: F,
55) -> proto_blue_xrpc::XrpcServer
56where
57 F: Fn(proto_blue_xrpc::HandlerContext, Option<Input>) -> Fut + Send + Sync + 'static,
58 Fut: std::future::Future<Output = Result<serde_json::Value, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
59{
60 let handler = std::sync::Arc::new(handler);
61 server.procedure("app.bsky.notification.registerPush", move |ctx| {
62 let handler = handler.clone();
63 async move {
64 let input = match ctx.json_body()? {
65 Some(v) => Some(serde_json::from_value::<Input>(v).map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InvalidRequest, format!("input deserialize: {e}")))?),
66 None => None,
67 };
68 let out = handler(ctx, input).await?;
69 Ok::<_, proto_blue_xrpc::XrpcServerError>(out)
70 }
71 })
72}
73