#http-api #http #api #api-bindings #novaposhta

yanked novaposhta-evo

[UPDATED] Api for novapostha

0.2.0 Oct 22, 2021

#185 in #http-api

MIT license

35KB
971 lines

Novaposhta-rs

This a small implementation of novaposhta http api with small abstraction. If you wont use my abstraction you can use instead NovaposhtaRaw with full identityfy with their documentation but their documentation soo shity because outdated and not entirely true.

Usage

Create ttn with backward delivery.

let nova = Novaposhta::default();
let date_time = {
    let now = Local::today() + Duration::days(1);
    format!("{}.{}.{}", now.day(), now.month(), now.year())
};
let payload = CreateNewTtnPayload::new(
    Recipient::new(
        "Киев",
        "имя",
        Some("отчество"),
        "фамилия",
        "номер телефона",
        true, // is_payer
        Address::warehouse(14),
    ),
    Sender::new("Киев", "отделение", "номер телефона"),
    date_time, // Time of
    NovaPaymentMethod::Cash,
    "Аксесуары".to_string(),
    vec![Cargo::new(150, 0.5, None)],
    "Parcel".to_string(),
    Some(BackwardDeliveryData::money(150)),
);
/* CreateNewTtnResponse */ nova.create_ttn(payload).await?;
Novaposhta::default(); // take api_key from env "NOVAPOSHTA_KEY"
Novaposhta::new("API_KEY"); // if you cannot use env

Delete ttns

let nova = Novaposhta::default();
let payload = vec![
    "TTN ref".to_string()
];
/* Vec<String> */ nova.delete_ttn(payload).await?; 
// Always check if your document in delete list from response

Track ttns

let nova = Novaposhta::default();
let payload = vec![
    NovaDocument::new("Number ttn".to_string(), "Phone".to_string()),
    // Sender or Recipient
];
/* Vec<NovaResponseData> */ nova.track_ttn(payload).await?;

For more info and available fields refer to novaposhta.

Disclaimer

This abstraction not so fast because we make 4 requests for simple create ttn... This can be fixed, but then there will be no point in abstractions. If you want to use this api as it was conceived in a novaposhta, please pay attention for NovaposhtaRaw

This is my first project on rust. pull requests and comments welcome in issues

Dependencies

~8–22MB
~330K SLoC