#api #voucherify #voucher

voucherify_rs

Rust SDK for Voucherify.io

3 releases (1 stable)

Uses old Rust 2015

1.0.0 Jul 19, 2019
0.1.1 Mar 9, 2017
0.1.0 Mar 9, 2017

#1599 in #api

MIT license

31KB
611 lines

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).

Dependencies

~7–15MB
~225K SLoC