Easy SDK for interacting with Pantry.
This is not an official project of pantry and is just fan made
nimble install pantry
(While this examples are synchronous you can use newAsyncPantryClient
to use async version)
Connecting to your pantry
let pc = newPantryClient(your-pantry-token)
Getting information about pantry
let pantry = pc.getDetails()
assert pantry.percentFull < 100 # Make sure we are under the limit
# List all your baskets (They are stored has a table)
for basket in pantry.values:
echo basket.name
Information is stored via baskets which is a single JSON object. Each pantry can have up to 100 baskets (max size is 1.44mb each). Baskets can be interacted with the following operations
create
: Sets the data of the basket, overwrites existing informationupdate
: Updates the information currently in a basketget
: Gets the information stored inside a basketdelete
: Deletes the basket
pc.create("test", %* {
"foo": "bar"
})
assert pc.get("test")["foo"] == %"bar"
let newData = pc.update("test", %* {
"foo": "notBar"
})
assert newData["foo"] == %"notBar"
pc.delete("foo")
Objects can be used instead of JsonNode
for create
, get
, and update
type
User = object
id: int
email: string
pc.create("admin", User(id: 9, email: "user@example.com"))
assert pc.get("admin", User).email == "user@example.com"
assert pc.update("admin", User(id: 9, email: "admin@example.com")).email == "admin@example.com"
# Can also use option types when getting to avoid errors
import std/options
assert pc.get("doesntExst", Option[User]).isNone()
assert pc.get("admin", Option[User]).isSome()