Skip to main content

Crate alpr

Crate alpr 

Source
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.
CamerasService
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.
ClientBuilder
Configures a Client.
HttpRequest
One request, as a Transport sends it.
HttpResponse
One answer, as a Transport reads it.
Page
One page of a list, and the cursor of the next one.
PhotosService
The API’s photos: client.photos().
RecognitionsListParams
The filters of recognitions:list, and the cursor to start from.
RecognitionsService
The API’s recognitions: client.recognitions().
RequestOptions
Options of one call.
UnknownWebhookEvent
An event of a name this SDK does not know yet, kept as it was sent.
UreqTransport
The HTTP the SDK sends through: ureq, blocking, with rustls.

Enums§

Error
What a call answers instead of its resource.
WebhookError
Why a webhook was not accepted.
WebhookEvent
A webhook Alpr.sh sent, verified: one variant a kind of payload, told apart by WebhookEvent::event_name where a payload carries several events, or WebhookEvent::Unknown for 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 to ClientBuilder::transport. A function from HttpRequest to Result<HttpResponse, BoxError> is one.

Functions§

verify_webhook
Checks a webhook Alpr.sh sent and answers its event. Alpr.sh signs the X-Alprsh-Timestamp and X-Alprsh-Delivery-Id headers and the body: X-Alprsh-Signature carries sha256= and the hex HMAC-SHA256 of {timestamp}.{delivery-id}.{body} under the endpoint’s secret (the whole whsec_… 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 the X-Alprsh-Delivery-Id header.
verify_webhook_at
verify_webhook as if it were now.
verify_webhook_signature
Checks a webhook’s signature as verify_webhook does, without reading its body.
verify_webhook_signature_at
verify_webhook_signature as if it were now.

Type Aliases§

AlertTriggeredWebhookEvent
The payload of alert.triggered. The fields are the body’s own, flat: there is no wrapper around them.
BoxError
Any error a Transport answers.
RecognitionCreatedWebhookEvent
The payload of recognition.created. The fields are the body’s own, flat: there is no wrapper around them.
TestWebhookEvent
The payload of webhook.test. The fields are the body’s own, flat: there is no wrapper around them.