Expand description
Alpr.sh’s SDK for Rust, generated from Alpr.sh’s API contract.
A Client calls the API with one workspace’s API key
(alpr_live_…). A refusal is Error::Api.
use alpr::{Client, PhotosRecognizeParams, RecognitionsListParams};
let client = Client::new("alpr_live_…");
let photo = std::fs::read("carro.jpg").unwrap();
let result = client.photos().recognize(&PhotosRecognizeParams::new(photo))?;
for plate in &result.plates {
println!("{} ({})", plate.plate, plate.conf);
}
for reading in client.recognitions().list_iter(RecognitionsListParams::new()) {
println!("{}", reading?.plate);
}Webhooks are checked with verify_webhook before their body is read.
Re-exports§
pub use models::*;
Modules§
- models
- The resources Alpr.sh’s API answers and the bodies its calls take.
Structs§
- ApiError
- A request the API refused.
- Cameras
Service - The API’s cameras:
client.cameras(). - Client
- Alpr.sh’s API with one workspace’s API key (
alpr_live_…), which says the workspace and the scopes the calls may use. - Client
Builder - Configures a
Client. - Http
Request - One request, as a
Transportsends it. - Http
Response - One answer, as a
Transportreads it. - Page
- One page of a list, and the cursor of the next one.
- Photos
Service - The API’s photos:
client.photos(). - Recognitions
List Params - The filters of recognitions:list, and the cursor to start from.
- Recognitions
Service - The API’s recognitions:
client.recognitions(). - Request
Options - Options of one call.
- Unknown
Webhook Event - An event of a name this SDK does not know yet, kept as it was sent.
- Ureq
Transport - The HTTP the SDK sends through: ureq, blocking, with rustls.
Enums§
- Error
- What a call answers instead of its resource.
- Webhook
Error - Why a webhook was not accepted.
- Webhook
Event - A webhook Alpr.sh sent, verified: one variant a kind of payload, told
apart by
WebhookEvent::event_namewhere a payload carries several events, orWebhookEvent::Unknownfor an event this SDK does not know yet.
Constants§
- API_
VERSION - The contract this SDK was generated from.
- DEFAULT_
BASE_ URL - Alpr.sh’s API. There is one environment: the API key (
alpr_live_…) says the workspace. - VERSION
- This SDK’s version.
- WEBHOOK_
TOLERANCE - How far from now a webhook’s timestamp may be.
Traits§
- Transport
- Sends a request and answers what came back, whatever its status. The SDK
sends through
UreqTransport; a test, or a program with its own HTTP client, gives another one toClientBuilder::transport. A function fromHttpRequesttoResult<HttpResponse, BoxError>is one.
Functions§
- verify_
webhook - Checks a webhook Alpr.sh sent and answers its event. Alpr.sh signs the
X-Alprsh-TimestampandX-Alprsh-Delivery-Idheaders and the body:X-Alprsh-Signaturecarriessha256=and the hex HMAC-SHA256 of{timestamp}.{delivery-id}.{body}under the endpoint’s secret (the wholewhsec_…text, as it is), and more than one signature while a secret is rotated: one matching is enough. Pass the body exactly as it arrived, before parsing it, and deduplicate by theX-Alprsh-Delivery-Idheader. - verify_
webhook_ at verify_webhookas if it werenow.- verify_
webhook_ signature - Checks a webhook’s signature as
verify_webhookdoes, without reading its body. - verify_
webhook_ signature_ at verify_webhook_signatureas if it werenow.
Type Aliases§
- Alert
Triggered Webhook Event - The payload of
alert.triggered. The fields are the body’s own, flat: there is no wrapper around them. - BoxError
- Any error a
Transportanswers. - Recognition
Created Webhook Event - The payload of
recognition.created. The fields are the body’s own, flat: there is no wrapper around them. - Test
Webhook Event - The payload of
webhook.test. The fields are the body’s own, flat: there is no wrapper around them.