wielorzeczownik / pepito-client
Pepito cat flap API client: live in and out events, current status and archive statistics. Plain PHP, with the Rust core as opt-in FFI.
Package info
github.com/wielorzeczownik/pepito-client
Type:composer-plugin
pkg:composer/wielorzeczownik/pepito-client
Requires
- php: >=8.2
- composer-plugin-api: ^2.0
- composer-runtime-api: ^2.0
- ext-curl: *
- ext-json: *
- ext-phar: *
- ext-zlib: *
- psr/clock: ^1.0
- psr/event-dispatcher: ^1.0
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.1 || ^2.0
- psr/log: ^1.1 || ^2.0 || ^3.0
- psr/simple-cache: ^1.0 || ^2.0 || ^3.0
Requires (Dev)
- laravel/pint: 1.30.4
- nyholm/psr7: 1.8.2
- phpunit/phpunit: 11.5.58
Suggests
- ext-ffi: The Rust core through Client::withFfi(), for raw speed on large archives
- psr/event-dispatcher-implementation: Events from watch(), through setEventDispatcher()
- psr/http-client-implementation: Your own HTTP client for refresh(), through setHttpClient()
- psr/simple-cache-implementation: Snapshot cache instead of files, through setCache()
Provides
None
Conflicts
None
Replaces
None
README
Pépito Client
A client for the Pepito API, the feed of a cat door that reports when Pépito goes out and comes back. It comes as a Rust crate, an npm package and a Composer package.
| Package | Language | Default backend | Opt-in backend | Docs |
|---|---|---|---|---|
pepito-client |
Rust | Rust | - | crates/core/README.md |
@wielorzeczownik/pepito-client |
JS / TS | plain TypeScript | Rust through wasm | js/README.md |
wielorzeczownik/pepito-client |
PHP 8.2+ | plain PHP | Rust through FFI | php/README.md |
The npm and Composer packages need nothing native by default. The Rust backend is there if you want it, through @wielorzeczownik/pepito-client/wasm or Client::withFfi().
All three do the same things:
- parse the SSE stream into
in/outevents and track whether the cat is home - drop repeats that arrive again after a reconnect
- cache the current status and know how old it is
- watch the heartbeat and reconnect when the stream goes quiet
- compute statistics from the Pepito-data archive
Events, status(), statistics and snapshots are the same in every backend, so a snapshot saved by one restores in any other.
How it fits together
The Rust core does no networking. Each binding brings its own transport, which is why the same core runs in wasm and behind PHP's FFI.
| Path | What it is |
|---|---|
crates/core/ |
the core, published to crates.io. The net feature adds reqwest |
crates/ffi/ |
C ABI over the core, JSON in and out, used by the PHP package |
crates/wasm/ |
wasm-bindgen over the core, used by @wielorzeczownik/pepito-client/wasm |
js/src/ |
the TypeScript port (core.ts), transport (pepito.ts), wasm wrapper |
php/src/ |
the PHP port (Tracker, History), client, FFI wrapper (FfiTracker) |
Each binding is its own crate, so building for PHP doesn't compile wasm-bindgen and the wasm build doesn't pull in reqwest. Parity tests run each port against the Rust core on the same input and fail on any difference.
Building
The default JS and PHP packages need no build step. The Rust backends do:
make wasm # js/src/wasm/ through wasm-bindgen make header # php/lib/pepito.h from crates/ffi make dylib # php/lib/pepito.h and php/lib/libpepito.{dylib,so}
That needs cbindgen and wasm-bindgen-cli at exactly the version in crates/wasm/Cargo.toml:
cargo install cbindgen cargo install wasm-bindgen-cli --version 0.2.130
Disclaimer
Not official and not affiliated with the Pepito API or its author. If the API changes, this will stop working until it's fixed here.
The cat in the logo is from Font Awesome Free, licensed under CC BY 4.0.