Skip to content

dkoleev/UniPantry

Repository files navigation

UniPantry

Unity wrapper for the Pantry API - https://getpantry.cloud

Getting started

Install via UPM package with git reference or asset package(UniPantry...*.unitypackage) available in UniPantry/releases.

UPM Package

Install via git URL

Use UPM to install the package via the following git URL:

https://github.com/dkoleev/UniPantry.git

Usage

Create a new client

using Yogi.UniPantry.Runtime;

var pantry = new Pantry();

Get Pantry

Given a PantryID, return the details of the pantry, including a list of baskets currently stored inside it.

using Yogi.UniPantry.Runtime;

private void GetPantry() {
    StartCoroutine(
        pantry.GetPantry(pantryId,
            info => {
                if (info is not null) {
                    Debug.Log($"name: {info.name} description: {info.description} percentFull: {info.percentFull} errors: {info.errors}");
                    foreach (var infoBasket in info.baskets) {
                        Debug.Log(infoBasket.name);
                    }
                }
            })
    );
}

Update Pantry Details

using Yogi.UniPantry.Runtime;

private void UpdatePantryInfo() {
    StartCoroutine(
        pantry.UpdatePantryInfo(pantryId, "new name", "new description",
            info => {
                if (info is not null) {
                    Debug.Log($"name: {info.name} description: {info.description} percentFull: {info.percentFull} errors: {info.errors}");
                    foreach (var infoBasket in info.baskets) {
                        Debug.Log(infoBasket.name);
                    }
                }
            })
    );
}

Get Basket

Given a basket name, return the full contents of the basket.

using Yogi.UniPantry.Runtime;

private void GetBasket() {
    StartCoroutine(_pantry.GetBasket(pantryId, basketId, Debug.Log));
}

Create Basket

Given a basket name as provided in the url, this will either create a new basket inside your pantry, or replace an existing one.

using Yogi.UniPantry.Runtime;

private void CreateBasket() {
    var content = JsonUtility.ToJson(SOME_SERIALIZABLE_CLASS);
    StartCoroutine(_pantry.CreateBasket(pantryId, basketId, content, Debug.Log));
}

Update Basket

Given a basket name, this will update the existing contents and return the contents of the newly updated basket. This operation performs a deep merge and will overwrite the values of any existing keys, or append values to nested objects or arrays.

using Yogi.UniPantry.Runtime;

private void UpdateBasket() {
    var content = JsonUtility.ToJson(SOME_SERIALIZABLE_CLASS);
    StartCoroutine(_pantry.UpdateBasket(pantryId, basketId, content, Debug.Log));
}

Delete Basket

Delete the entire basket. Warning, this action cannot be undone.

using Yogi.UniPantry.Runtime;

private void DeleteBasket() {
    StartCoroutine(_pantry.DeleteBasket(pantryId, basketId, Debug.Log));
}