fauna-api 1.0.861

The Fauna SDK for Rust: accounts, Drive, groups, calendar, chats, payments, Parrot and live rooms.
Documentation
use serde_json::{Value, json};

use crate::authentification::Credentials;
use crate::error::Result;
use crate::http::{client, ok};

// Private: whether Fauna's newsletter goes to the signed in person. Fauna's own Account tab
// reads and sets it; every newsletter's unsubscribe link turns it off too.

pub async fn subscription(credentials: &Credentials) -> Result<bool> {
    let response = client()
        .get(format!("{}/newsletter/subscription", crate::get_url()))
        .header("Authorization", format!("Token {}", credentials.token))
        .send()
        .await?;
    let json: Value = ok(response).await?.json().await?;
    Ok(json["subscribed"].as_bool().unwrap_or(false))
}

pub async fn set_subscription(credentials: &Credentials, subscribed: bool) -> Result<bool> {
    let response = client()
        .put(format!("{}/newsletter/subscription", crate::get_url()))
        .header("Authorization", format!("Token {}", credentials.token))
        .json(&json!({ "subscribed": subscribed }))
        .send()
        .await?;
    let json: Value = ok(response).await?.json().await?;
    Ok(json["subscribed"].as_bool().unwrap_or(false))
}