- astro-engine: forecast module (solar return moment, slow-planet transits
with exact dates and periods, natal house ingresses, secondary
progressions, annual profection, eclipses via Swiss Ephemeris)
- horoscope-api: POST /v1/forecast, solar return chart cast for the place
of the birthday
- backend: forecasts table, /v1/charts/{id}/forecasts, /v1/forecasts/{id}
and its analyses using a new 'forecast' unit; current year of life open,
the next one 30 days before the birthday
- packages: Páros and Család include forecasts (6 000 / 11 000 Ft),
+1 éves előrejelzés add-on 2 500 Ft; Egy elemzés unchanged
- worker and prompt: forecast kind with five sections and forecast rules
(trends, no event predictions); no birth data, place or exact age sent
- frontend: /kepletek/{id}/elorejelzes with the solar return wheel, the
keys of the year, a monthly timeline, transit list and detailed forecast
- data export: forecasts added, model name removed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
70 lines
2.4 KiB
Rust
70 lines
2.4 KiB
Rust
//! Client of the horoscope-api service (`POST /v1/natal`, `POST /v1/synastry`).
|
|
//!
|
|
//! Requests and responses are passed as JSON: the horoscope service validates
|
|
//! the birth data itself, and its error objects are handed back unchanged so
|
|
//! callers can show them to the user.
|
|
|
|
use std::time::Duration;
|
|
|
|
use serde_json::Value;
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum HoroscopeError {
|
|
/// The service rejected the input (4xx); `body` is its `{"error": {...}}` object.
|
|
#[error("horoscope service rejected the request ({status})")]
|
|
Rejected { status: u16, body: Value },
|
|
/// The service is unreachable or failed (5xx, timeout, invalid response).
|
|
#[error("horoscope service unavailable: {0}")]
|
|
Unavailable(String),
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct HoroscopeClient {
|
|
base_url: String,
|
|
http: reqwest::Client,
|
|
}
|
|
|
|
impl HoroscopeClient {
|
|
pub fn new(base_url: impl Into<String>) -> Self {
|
|
let http = reqwest::Client::builder()
|
|
.timeout(Duration::from_secs(15))
|
|
.build()
|
|
.expect("static reqwest configuration is valid");
|
|
Self { base_url: base_url.into().trim_end_matches('/').to_string(), http }
|
|
}
|
|
|
|
/// `POST /v1/natal`
|
|
pub async fn natal(&self, request: &Value) -> Result<Value, HoroscopeError> {
|
|
self.post("/v1/natal", request).await
|
|
}
|
|
|
|
/// `POST /v1/synastry`
|
|
pub async fn synastry(&self, request: &Value) -> Result<Value, HoroscopeError> {
|
|
self.post("/v1/synastry", request).await
|
|
}
|
|
|
|
/// `POST /v1/forecast`
|
|
pub async fn forecast(&self, request: &Value) -> Result<Value, HoroscopeError> {
|
|
self.post("/v1/forecast", request).await
|
|
}
|
|
|
|
async fn post(&self, path: &str, body: &Value) -> Result<Value, HoroscopeError> {
|
|
let response = self
|
|
.http
|
|
.post(format!("{}{path}", self.base_url))
|
|
.json(body)
|
|
.send()
|
|
.await
|
|
.map_err(|e| HoroscopeError::Unavailable(e.to_string()))?;
|
|
let status = response.status();
|
|
let body: Value = response.json().await.map_err(|e| HoroscopeError::Unavailable(e.to_string()))?;
|
|
if status.is_success() {
|
|
Ok(body)
|
|
} else if status.is_client_error() {
|
|
Err(HoroscopeError::Rejected { status: status.as_u16(), body })
|
|
} else {
|
|
Err(HoroscopeError::Unavailable(format!("{status}: {body}")))
|
|
}
|
|
}
|
|
}
|