|
| 1 | +# AstroAPI Flutter/Dart SDK |
| 2 | + |
| 3 | +Dart/Flutter SDK for the Astrology API v3. No code generation (no freezed/json_serializable) — uses plain Dart classes with manual `toJson()`. |
| 4 | + |
| 5 | +## Setup |
| 6 | + |
| 7 | +```bash |
| 8 | +dart pub get |
| 9 | +``` |
| 10 | + |
| 11 | +## Development Commands |
| 12 | + |
| 13 | +```bash |
| 14 | +# Install dependencies |
| 15 | +dart pub get |
| 16 | + |
| 17 | +# Analyze code |
| 18 | +dart analyze |
| 19 | + |
| 20 | +# Run tests |
| 21 | +dart test |
| 22 | + |
| 23 | +# Run tests with coverage |
| 24 | +dart test --coverage=coverage |
| 25 | +``` |
| 26 | + |
| 27 | +## Architecture |
| 28 | + |
| 29 | +``` |
| 30 | +lib/ |
| 31 | + astroapi.dart # Barrel export (public API) |
| 32 | + src/ |
| 33 | + client/astrology_client.dart # Main AstrologyClient class |
| 34 | + config/astrology_client_config.dart # Config, RetryConfig, RequestOptions |
| 35 | + http/ |
| 36 | + http_helper.dart # Abstract HttpHelper interface |
| 37 | + dio_http_client.dart # Dio-based implementation with retry |
| 38 | + errors/astrology_exception.dart # AstrologyException |
| 39 | + categories/ # 16 category clients |
| 40 | + models/ |
| 41 | + requests/ # Request types (toJson()) |
| 42 | + responses/ # Response types (fromJson()) |
| 43 | + enums/ # Language, HouseSystem, etc. |
| 44 | +``` |
| 45 | + |
| 46 | +## Usage Example |
| 47 | + |
| 48 | +```dart |
| 49 | +import 'package:astroapi/astroapi.dart'; |
| 50 | +
|
| 51 | +final client = AstrologyClient( |
| 52 | + AstrologyClientConfig( |
| 53 | + apiKey: 'your-api-key', |
| 54 | + timeout: 15000, |
| 55 | + retry: RetryConfig(attempts: 3, delayMs: 500), |
| 56 | + ), |
| 57 | +); |
| 58 | +
|
| 59 | +// Get planetary positions |
| 60 | +final positions = await client.data.getPositions( |
| 61 | + PlanetaryPositionsRequest( |
| 62 | + subject: Subject( |
| 63 | + birthData: BirthData( |
| 64 | + year: 1990, month: 5, day: 11, |
| 65 | + hour: 14, minute: 30, |
| 66 | + city: 'London', countryCode: 'GB', |
| 67 | + ), |
| 68 | + ), |
| 69 | + ), |
| 70 | +); |
| 71 | +print(positions.positions[0].sign); |
| 72 | +
|
| 73 | +// Get natal chart |
| 74 | +final chart = await client.charts.getNatalChart( |
| 75 | + NatalChartRequest(subject: subject), |
| 76 | +); |
| 77 | +
|
| 78 | +// Insights sub-clients |
| 79 | +final compat = await client.insights.relationship.getCompatibility( |
| 80 | + CompatibilityRequest(subjects: [subject1, subject2]), |
| 81 | +); |
| 82 | +
|
| 83 | +// SVG chart |
| 84 | +final svg = await client.svg.getNatalChartSvg( |
| 85 | + NatalChartSvgRequest(subject: subject), |
| 86 | +); |
| 87 | +``` |
| 88 | + |
| 89 | +## Key Design Decisions |
| 90 | + |
| 91 | +- **No code generation**: Plain Dart classes instead of freezed/json_serializable for simplicity and faster compilation |
| 92 | +- **GenericResponse**: Complex API responses use `GenericResponse` (wraps `Map<String, dynamic>`) with typed fields for commonly-used properties |
| 93 | +- **HttpHelper abstraction**: The `HttpHelper` interface enables easy mocking in tests with `mocktail` |
| 94 | +- **Retry logic**: Built into `DioHttpClient`, configurable via `RetryConfig` |
| 95 | +- **SVG responses**: `SvgClient` returns `String` directly instead of JSON |
| 96 | +- **InsightsClient**: Has 5 sub-clients (relationship, pet, wellness, financial, business) |
| 97 | + |
| 98 | +## Testing |
| 99 | + |
| 100 | +Uses `mocktail` to mock `HttpHelper`: |
| 101 | + |
| 102 | +```dart |
| 103 | +class MockHttpHelper extends Mock implements HttpHelper {} |
| 104 | +
|
| 105 | +final client = DataClient(MockHttpHelper()); |
| 106 | +``` |
0 commit comments