https://github.com/open-zhy/podio-ts
Podio client module for Deno and Typescript programming
https://github.com/open-zhy/podio-ts
deno hacktoberfest podio podio-api typescript
Last synced: 4 months ago
JSON representation
Podio client module for Deno and Typescript programming
- Host: GitHub
- URL: https://github.com/open-zhy/podio-ts
- Owner: open-zhy
- License: mit
- Created: 2020-05-17T18:58:59.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-10-22T01:09:17.000Z (over 5 years ago)
- Last Synced: 2025-10-20T18:26:33.867Z (8 months ago)
- Topics: deno, hacktoberfest, podio, podio-api, typescript
- Language: TypeScript
- Homepage:
- Size: 19.5 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Podio client written in Typescript
This module aims to provide a Podio client implementation for [Deno](https://deno.land/) and/or general Typescript programming

# Version Note
```
deno >= 1.2
```
# Basic Usage
### Import
Most of public modules has been exported in `mod.ts`.
Some modules that are arbitrary have to be exported explicitly from its placement
```typescript
import {
Client,
PodioResponse,
PodioError,
} from "https://deno.land/x/podio/mod.ts";
import { RuntimeStore } from "https://deno.land/x/podio/store/store_runtime.ts";
```
### Podio client setup and authentication
```typescript
const podio = new Client("the-api-client", "the-client-secret-here", {
// store can be left empty.
// in that case, each authentication
// process will attempt to retrieve token
// directly from Podio, which can potentialy
// lead into some rate limit issue
// RuntimeStore is a built-in storage, using Map data type
// see https://github.com/open-zhy/podio-ts/blob/master/store/store_runtime.ts
store: new RuntimeStore(),
});
// authenticate client
const response = await podio.authenticate("app", {
app_id: 1234567,
app_token: "a92239400b574cfca761cdf213a27975",
});
const oAuthToken = response.asOAuthObject();
console.log({ oAuthToken });
```
After this process, an `OAuthObject` will be bound on the client instance, it will be used for any following requests which uses the same client instance
### Make request
```typescript
// simple GET request
const response = await podio.request("GET", `/app/1234567`);
if (response instanceof PodioResponse) {
console.log(response.asObject()); // PodioObject data
}
```
We use native `fetch` and `Request` object to perform these client request. The 3rd options is passed through parameters for the native request object
```typescript
const response = await podio.request("PUT", `/item/123456789`, {
body: {
fields: {
title: "Hello Deno",
"category-1": [1],
},
},
});
// response is either PodioError or PodioResponse
```
# Data objects
_(coming soon)_
# Events listeners
For now we can subscribe to 3 types of events emitted during each API call
- **podio.request** - Executed when a request has been created and ready to fire, args: the `Request` object
- **podio.response** - Fired once we get an healthy response from Podio, args: the `PodioResponse` object
- **podio.error** - When a Podio error caught, args: `PodioError` object
#### Example
```typescript
// just right after client creation
// here we will just print information about Rate Limit contained in response headers
podio.event?.on("podio.response", (response: PodioResponse) => {
response.headers?.forEach((value, key) => {
if (
[
"x-rate-limit-remaining",
"x-rate-limit-limit",
"x-podio-auth-ref",
].includes(key)
) {
console.log(`--> ${key}=${value}`);
}
});
});
```
# Contribute? Welcome!!
Everyone is welcome to contribute to this project.
Therefore, here is some list of what I planned to implement in the future
- **Tests** - Implement more test suite cases., just add \*\_test.ts file OR add more statement on existing ones
- **Data Objects** - It would be good to have an abstraction of each type of data Podio can handle, here is the [complete references](https://developers.podio.com/doc)
- **Session Manager** - Add common used session manager: filesystem, redis, in-memory db like [this](https://docs.rs/memdb/1.0.0/memdb/)
- **Sandbox / Explorer** - Leverage simplicity of Deno to implement a sandox / explorer that can be used to test some API features