Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ire4ever1190/pantry-nim
SDK for connecting to https://getpantry.cloud/
https://github.com/ire4ever1190/pantry-nim
Last synced: 11 days ago
JSON representation
SDK for connecting to https://getpantry.cloud/
- Host: GitHub
- URL: https://github.com/ire4ever1190/pantry-nim
- Owner: ire4ever1190
- License: mit
- Created: 2022-03-20T21:44:31.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-11-04T02:42:05.000Z (about 1 year ago)
- Last Synced: 2024-05-02T02:34:48.781Z (6 months ago)
- Language: Nim
- Size: 45.9 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
## pantry-nim
Easy SDK for interacting with [Pantry](https://getpantry.cloud/).
**This is not an official project of pantry and is just fan made**
[Docs here](https://ire4ever1190.github.io/pantry-nim/pantry)
#### Installation
`nimble install pantry`
#### Examples
(While this examples are synchronous you can use `newAsyncPantryClient` to use async version)
Connecting to your pantry
```nim
let pc = newPantryClient(your-pantry-token)
```Getting information about pantry
```nim
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 information
- `update`: Updates the information currently in a basket
- `get`: Gets the information stored inside a basket
- `delete`: Deletes the basket```nim
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`
```nim
type
User = object
id: int
email: stringpc.create("admin", User(id: 9, email: "[email protected]"))
assert pc.get("admin", User).email == "[email protected]"
assert pc.update("admin", User(id: 9, email: "[email protected]")).email == "[email protected]"
# 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()```