0.3.1 • Published 2 years ago

nyx-api v0.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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())
0.3.1

2 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago