voucherify_rs

Crates.iovoucherify_rs
lib.rsvoucherify_rs
version1.0.0
sourcesrc
created_at2017-03-09 11:56:24.88041
updated_at2019-07-19 09:55:56.594192
descriptionRust SDK for Voucherify.io
homepagehttps://github.com/voucherifyio/voucherify-rust-sdk
repositoryhttps://github.com/voucherifyio/voucherify-rust-sdk.git
max_upload_size
id8896
size34,649
(awilczek)

documentation

README

voucherify-rust-sdk

Setup

Add crate to your Cargo.toml

[dependencies]
voucherify_rs = "1.0.0"

Import voucherify-rs crate

extern crate voucherify_rs;

Create voucherify api object

let voucherify = Voucherify::new("<YOUR_APP_ID_GOES_HERE>",
                                 "<YOUR_SECRET_KEY_GOES_HERE>");

API Endpoint

Optionally, you can specify API Endpoint if you want to use Voucherify running in a specific region.

let voucherify: &mut Voucherify = &mut Voucherify::new("<YOUR_APP_ID_GOES_HERE>",
                                                       "<YOUR_SECRET_KEY_GOES_HERE>");

voucherify.set_endpoint("https://<region>.api.voucherify.io");

Vouchers API

Provided methods:

Create Voucher

let new_voucher = Voucher::new()
    .voucher_type(VoucherType::DISCOUNT_VOUCHER)
    .discount(DiscountType::AMOUNT, 20)
    .build();

let created_voucher = voucherify.voucher_create(new_voucher).send().unwrap();

Get Voucher

let single_voucher: Voucher = voucherify.voucher_get("D1dsWQVE").send().unwrap();

Update Voucher

let updated_metadata = Metadata::new()
    .number("number", 32)
    .string("is", "working")
    .boolean("is_amazing", true)
    .build();

let updated_voucher = voucherify.voucher_update("D1dsWQVE")
                                .category("hello_world")
                                .active(true)
                                .metadata(updated_metadata)
                                // .gift_amount(1234)
                                .send().unwrap();

Delete Voucher

let was_voucher_deleted: bool = voucherify.voucher_delete(created_voucher_code.as_str()).send().unwrap();

List Vouchers

let voucher_list: Vec<Voucher> = voucherify.voucher_list().limit(19).page(1).send().unwrap();

Enable Voucher

let was_voucher_enabled: bool = voucherify.voucher_enable("D1dsWQVE").send().unwrap();

Disable Voucher

let was_voucher_disabled: bool = voucherify.voucher_disable("D1dsWQVE").send().unwrap();

License

Licensed under MIT license (LICENSE or http://opensource.org/licenses/MIT)

Changelog

  • 2019-06-19 - 1.0.0 - Added support for custom API endpoint, that allows to connect to projects created in specific Voucherify region. Additionally, updated the model here and there (more Option-al variables + added simple VouchersList).
Commit count: 30

cargo fmt