0.11.2 • Published 1 year ago

boomack-js v0.11.2

Weekly downloads
4
License
MIT
Repository
-
Last release
1 year ago

Boomack API Client Library

A JavaScript library for sending display and configuration requests to a Boomack server.

See https://boomack.com for further information about the Boomack server.

For the library documentation see: https://docs.boomack.com/client/boomack-js/.

Getting Started

import { Boomack } from 'boomack-js'

async function main() {
    const client = new Boomack({
        server: { url: 'http://127.0.0.1:3000' },
    })

    const response = await client.displayMediaItems({
        panel: 'default',
        slot: 'default',
        text: 'Hello World!',
        type: 'text/plain',
    })
    if (response.success) {
        console.log("Request was successful.")
    } else {
        console.error("Request failed with:", response.statusMessage)
        console.log(response.body)
    }
}

main().catch(console.error)

Loading Configuration

The configuration for the Boomack API client is by convention loaded from the following sources and merged in the given order:

  • Default configuration
  • Default configuration files
    • .boomack-server[.json|.yaml|.yml] in the user profile directory
    • boomack-server[.json|.yaml|.yml] in the current working directory
    • .boomack[.json|.yaml|.yml] in the user profile directory
    • boomack[.json|.yaml|.yml] in the current working directory
  • Additional configuration files (JSON/YAML)
  • Environment Variables starting with BOOMACK_
    • BOOMACK_SERVER_URL
    • BOOMACK_CLIENT_TIMEOUT
    • BOOMACK_CLIENT_TOKEN
    • ...
  • An explizit configuration map

The default configuration has lowest priority and the explicit configuration map has the highest.

import boomack from 'boomack-js'

async function main() {
    const client = await boomack.withConfig({
        loadDefaultFiles: true,
        additionalFiles: ['./my-config.json'],
        loadEnvironmentVars: true,
        config: {
            // explicit configuration
            client: { timeout: 5000 },
        },
    })

    await client.display({
        text: 'Hello World!',
        type: 'text/plain',
    })
}

main().catch(console.error)

Using Response Data

The methods of the Boomack client are returning HTTP response objects. If the property success is true, the body property contains the parsed JSON data.

import boomack from 'boomack-js'

async function main() {
    const client = await boomack.withConfig({
        loadDefaultFiles: true,
        loadEnvironmentVars: true,
        config: {
            client: {
                // use application/json as accepted response format
                format: 'application/json',
            },
        },
    })

    const response = await client.listPanels()
    if (response.success) {
        // the body property contains the parsed JSON response
        const panelIds = response.body
        console.log("Panel IDs:", panelIds)
    } else {
        console.error("Request failed with:", response.statusMessage)
    }
}

main().catch(console.error)

The expected output is:

Panel IDs: [ 'default' ]
0.11.0

1 year ago

0.11.1

1 year ago

0.11.2

1 year ago

0.10.1

1 year ago

0.10.2

1 year ago

0.10.3

1 year ago

0.10.0

2 years ago

0.9.0

2 years ago

0.8.0

3 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago