nyx-api
v0.3.1
Published
Javascript library for basic communication with Nyx.cz API
Downloads
4
Readme
nyx-api
Library for basic communication with Nyx.cz API
Install
yarn add nyx-api
or
npm i nyx-api
Browser / React-Native / Cordova / ...
- Nyx doesn't allow cross origin resource sharing, so you need to disable CORS browser check, if you want to test this in actual browser
- follow example here
Node.js
- install fetch and FormData node polyfills in your project
yarn add node-fetch form-data
- follow example here (run
node ./example/index.js
)
Use
get instance of NyxApi:
import NyxApi, { Auth, Bookmark, Context } from 'nyx-api'
const nyx = new NyxApi({
appName: 'test',
})
get token and confirmationCode:
const { confirmationCode, token } = await nyx.createAuthToken('username')
... call random endpoint:
const { discussions } = await nyx.getHistory()
console.log(discussions.map((b: Bookmark) => b.full_name))
you can store your token, on next start call:
const nyx = new NyxApi({
appName: 'test',
auth: {
username: 'foo',
token: 'bar',
}
})
or set Auth object later:
const auth: Auth = {
username: 'foo',
token: 'bar',
}
nyx.setAuth(auth)
subscribe to some events:
nyx.onContextUpdate.subscribe()
.then((ctx: Context) => console.log(ctx.user.notifications_unread))
nyx.onError.subscribe().then((msg: string) => console.error(msg))
nyx.onLogout.subscribe().then(() => storage.cleanup())