Skip to content

Commit 3a706ee

Browse files
committed
feat: add the VedAstro Java client SDK with 684 generated calculators
A server-oriented Java 21 client for the VedAstro API, matching the Python, Node.js and Go SDKs in surface while reading the way Java developers expect. Library (org.vedastro), hand-written: - VedAstroClient - immutable, thread-safe, one pooled java.net.http.HttpClient, built through a builder (apiKey, timeout, defaultAyanamsa, baseUrl, transport, silent). An empty key uses the free tier. - Calculators - the 684 generated endpoints, exposed as client.calculate(). - Time / GeoLocation - records that validate eagerly, so a bad chart fails at the call site instead of as a confusing API error. Time.from(ZonedDateTime) and friends preserve the supplied offset. - Json - a small dependency-free codec. Objects decode to LinkedHashMap, arrays to ArrayList, every number to Double (matching the Go SDK's float64), and a single-property payload is unwrapped exactly as the other SDKs do. - ApiException / VedAstroException - unchecked, with the API key redacted from every message. - Calculate - a static facade over a shared client for scripts and tests. - withAyanamsa(...) - scopes an ayanamsa to the calling thread, so concurrent server requests cannot interfere. Generated by StaticTableGenerator Task 12 into org.vedastro.calculate: - Calculators.java (684 methods, 30 with nullable option classes) - one enum per API enum, plus PlanetName as a value type with wire values - api_manifest.json listing every method, parameter and default Zero runtime dependencies: transport is java.net.http and JSON is bundled, so the library drops into Spring Boot, Jakarta EE, Quarkus or a plain main without adding a transitive tree. Also included: a Maven wrapper, a JUnit 5 suite (36 tests, covering the codec, Time/GeoLocation validation, request building, payload unwrapping, SVG responses, error paths and key redaction - all against a fake transport, so no API key or network is needed), 12 runnable demos, and a CI workflow testing Java 21 and 23 on Linux and Windows. Verified: mvn verify passes, the jar and sources jar build, and a live exec:java run against the API prints "Sun Sign: Libra".
0 parents  commit 3a706ee

60 files changed

Lines changed: 36791 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Java SDK CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
os: [ubuntu-latest, windows-latest]
16+
java: ['21', '23']
17+
name: Java ${{ matrix.java }} on ${{ matrix.os }}
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-java@v4
21+
with:
22+
distribution: temurin
23+
java-version: ${{ matrix.java }}
24+
cache: maven
25+
# Tests run against a fake transport, so no API key or network access is needed.
26+
- name: Build and test
27+
run: mvn -B --no-transfer-progress verify

‎.gitignore‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Build output
2+
target/
3+
4+
# IDE
5+
.idea/
6+
*.iml
7+
*.ipr
8+
*.iws
9+
.vscode/
10+
.settings/
11+
.classpath
12+
.project
13+
14+
# OS
15+
.DS_Store
16+
Thumbs.db
17+
18+
# Demo output
19+
*.svg
20+
astro_data.json

‎.mvn/wrapper/maven-wrapper.jar‎

61.6 KB
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
wrapperVersion=3.3.2
2+
distributionType=bin
3+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip

‎FAQ.md‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# FAQ
2+
3+
Short answers to the questions that come up most. The [README](README.md) has runnable examples
4+
for each of them.
5+
6+
**Which Java versions are supported?** Java 21 or newer. The library uses records, pattern
7+
matching, and `java.net.http.HttpClient`, all of which are standard since Java 21.
8+
9+
**Is this a calculation engine?** No. It is a client for the remote VedAstro API, so every
10+
calculation needs network access. The astrology itself runs on VedAstro's servers.
11+
12+
**Does it have any dependencies?** No runtime dependencies. Transport uses the JDK's
13+
`java.net.http`, and a small JSON codec is bundled, so there is no transitive tree to resolve and
14+
no version conflicts with your framework. JUnit is test-scoped only.
15+
16+
**How do I add it to my build?** Use `org.vedastro:vedastro:1.0.0` from Maven Central. The library
17+
also builds from source with the included Maven wrapper (`./mvnw -B verify`), so you can vendor it
18+
if you prefer.
19+
20+
**Are calls blocking?** Yes. Every calculator blocks the calling thread until the API responds.
21+
That suits a servlet thread or a Java 21 virtual thread; give each request its own thread rather
22+
than serialising calls behind one lock.
23+
24+
**Is the client thread-safe?** Yes. A `VedAstroClient` is immutable after construction and holds a
25+
pooled `HttpClient`, so build one at start-up and share it. Creating a client per request would
26+
throw away connection reuse.
27+
28+
**How do I set the API key?** `VedAstroClient.builder().apiKey(System.getenv("VEDASTRO_API_KEY"))`,
29+
or `Calculate.setApiKey(...)` for the static facade. An empty key uses the free tier. Never embed a
30+
paid key in a distributed JAR — they are trivially unpacked.
31+
32+
**What are the rate limits?** The free tier allows five requests per minute, counted per key across
33+
every thread and process in your application. Paid keys are quoted as 200 calls per minute by the
34+
API's own rate-limit error. Confirm current limits at [vedastro.org/API.html](https://vedastro.org/API.html).
35+
36+
**Does it retry or throttle automatically?** Neither. Only the caller knows whether a second
37+
request is safe, so the library leaves both to you. `BatchProcessing` in the demos shows a paced
38+
multi-threaded version.
39+
40+
**Why do methods return `Object`?** Results vary per calculator: objects, arrays, scalars, or SVG
41+
markup. Decoded values are `Map`, `List`, `String`, `Double`, `Boolean`, or `null`. Read them with
42+
`Json.asMap`, `Json.asList`, `Json.asString`, `Json.asInt`, or a checked cast.
43+
44+
**Why is my number `3.0` instead of `3`?** JSON has one number type, so every number decodes as
45+
`Double`, matching the Go SDK where all numbers are `float64`. Use `Json.asInt(value, fallback)`
46+
when you need a whole number.
47+
48+
**Why did my payload come back as a plain value instead of a map?** A payload object with exactly
49+
one property is unwrapped to that property's value, the same rule the Python, Node.js and Go SDKs
50+
use. So `planetRasiD1Sign` may return a `Map` with `Name` and `DegreesIn`, while `houseSignName`
51+
returns a bare `String`.
52+
53+
**A call failed — what should I check?** In order: the API key, the time string
54+
(`"HH:MM DD/MM/YYYY +HH:MM"`, 24-hour, DD/MM/YYYY), the coordinate order
55+
(`GeoLocation.of(name, longitude, latitude)`), and the rate limit. `ApiException.getMessage()`
56+
carries the API's own explanation.
57+
58+
**How do I cancel a request?** Set a short `timeout(...)` on the client, or interrupt the calling
59+
thread. An interruption restores the interrupt flag and raises a `VedAstroException`. To stop a
60+
long batch, check `Thread.currentThread().isInterrupted()` between calls.
61+
62+
**Can two requests use different ayanamsas at once?** Yes. `client.withAyanamsa(...)` scopes the
63+
choice to the calling thread for the duration of the lambda and restores the previous value
64+
afterwards, even if the lambda throws. A client-wide default is set with `defaultAyanamsa(...)`.
65+
66+
**Which ayanamsa should I use?** `Ayanamsa.LAHIRI` for Indian astrology (and it is the server
67+
default when you set nothing), `Ayanamsa.KRISHNAMURTI` for KP, `Ayanamsa.FAGAN_BRADLEY` for
68+
Western sidereal.
69+
70+
**Can I use it with Spring Boot?** Yes, and it is the recommended integration: declare one
71+
`VedAstroClient` as a `@Bean` and inject it. See [Using it in a server](README.md#-using-it-in-a-server).
72+
73+
**Can I call an endpoint that the library does not wrap yet?** Yes:
74+
`client.call("NewEndpointName", Map.of("time", birth))`. This is useful while the server is ahead of
75+
a regenerated client.
76+
77+
**Can I use this commercially?** Yes. MIT licensed, and both the free and paid tiers permit
78+
commercial use.

‎LICENSE‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 VedAstro
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎QUICKSTART.md‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Quick start
2+
3+
Requires **Java 21 or newer**. There is nothing else to install — no native code, no ephemeris
4+
files, and no third-party runtime dependencies.
5+
6+
## 1. Add the dependency
7+
8+
Maven:
9+
10+
```xml
11+
<dependency>
12+
<groupId>org.vedastro</groupId>
13+
<artifactId>vedastro</artifactId>
14+
<version>1.0.0</version>
15+
</dependency>
16+
```
17+
18+
Gradle:
19+
20+
```groovy
21+
implementation 'org.vedastro:vedastro:1.0.0'
22+
```
23+
24+
## 2. Make a calculation
25+
26+
Save this as `src/main/java/Main.java`:
27+
28+
```java
29+
import org.vedastro.Calculate;
30+
import org.vedastro.GeoLocation;
31+
import org.vedastro.Time;
32+
import org.vedastro.calculate.PlanetName;
33+
34+
public class Main {
35+
public static void main(String[] args) {
36+
// 'FreeAPIUser' is the free-tier key (5 requests per minute).
37+
// For a paid key, set VEDASTRO_API_KEY and read it with System.getenv.
38+
Calculate.setApiKey("FreeAPIUser");
39+
40+
// Time format: "HH:MM DD/MM/YYYY +TZ:TZ".
41+
// GeoLocation takes the name, then LONGITUDE, then latitude.
42+
Time birth = Time.of("14:30 25/10/1992 +05:30",
43+
GeoLocation.of("Mumbai", 72.8777, 19.0760));
44+
45+
Object result = Calculate.planetRasiD1Sign(PlanetName.SUN, birth);
46+
System.out.println("Sun Sign: " + Calculate.name(result)); // Libra
47+
}
48+
}
49+
```
50+
51+
## 3. Run it
52+
53+
```bash
54+
mvn -q compile exec:java -Dexec.mainClass=Main
55+
```
56+
57+
Expected output:
58+
59+
```
60+
Sun Sign: Libra
61+
```
62+
63+
## Where to go next
64+
65+
- **Runnable demos** — `./mvnw -q exec:java` runs the quick start; see the [demo list](README.md#-common-use-cases--demo-files)
66+
for the other eleven, for example
67+
`./mvnw -q exec:java -Dexec.mainClass=org.vedastro.demos.DailyPanchanga`
68+
- **Results are dynamic** — calculators return `Object`. Use `Json.asMap`, `Json.asList`,
69+
`Json.asString` and `Json.asInt` rather than casting blindly.
70+
- **Optional arguments** — thirty calculators have an options class; omit it for the server
71+
defaults, or set only the fields you need.
72+
- **Servers** — build one `VedAstroClient` at start-up and share it; it is thread-safe. See
73+
[Using it in a server](README.md#-using-it-in-a-server).
74+
- **Rate limits** — the free tier allows five requests per minute, so pace calls 13 seconds apart.
75+
- **Errors** — catch `ApiException` for API failures and `VedAstroException` for transport
76+
failures. The API key is always redacted.
77+
- **Common problems** — [FAQ](FAQ.md)

0 commit comments

Comments
 (0)