# relayr-adapter

> Adapter Library used to abstract the communication between the relayr backend and the manufacturer API.

Latest version **0.0.6** (published 2015-07-10) · 0 weekly downloads

## Install

```sh
npm install relayr-adapter
pnpm add relayr-adapter
yarn add relayr-adapter
bun add relayr-adapter
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2015-07-10 |
| First published | 2015-04-20 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Known vulnerabilities | 0 (+10 in 3 direct dependencies) |
| Install scripts | no |
| Maintainers | hudomju |

## Links

- npm: https://www.npmjs.com/package/relayr-adapter
- Repository: https://github.com/relayr/node-adapter-library
- Homepage: https://github.com/relayr/node-adapter-library#readme
- Issues: https://github.com/relayr/node-adapter-library/issues
- npm.io page: https://npm.io/package/relayr-adapter

## Dependencies (8)

- [pg](https://npm.io/package/pg.md) ^4.3.0
- [rc](https://npm.io/package/rc.md) ^1.0.0
- [amqp](https://npm.io/package/amqp.md) ^0.2.4
- [nconf](https://npm.io/package/nconf.md) ^0.7.1
- [bunyan](https://npm.io/package/bunyan.md) ^1.3.4
- [request](https://npm.io/package/request.md) ^2.53.0
- [pg-hstore](https://npm.io/package/pg-hstore.md) ^2.3.1
- [sequelize](https://npm.io/package/sequelize.md) ^3.0.0

## Recent versions

- 0.0.6 (latest) — 2015-07-10
- 0.0.5 — 2015-05-15
- 0.0.4 — 2015-05-06
- 0.0.3 — 2015-05-06
- 0.0.2 — 2015-05-04
- 0.0.1 — 2015-04-20

## README

# Adapter-Library
Adapter Library used to abstract the communication between the relayr backend and the manufacturer API.

## Getting started
    npm install --save

## Config
We use [rc](https://github.com/dominictarr/rc#standards) for configuration. For example, for 'shiny', our *{appname}* would be **shiny-adapter**.
It should look like:

    {
        "test": {
            "oauth": {
              "clientId": "id",
              "clientSecret": "id"
            },
            "database": {
              "connectionString": "postgres://postgres:postgres@localhost:4444/shiny-test"
            },
            "amqp": {
              "host": "",
              "port": "",
              "login": "",
              "password": "",
              "vhost": ""
            }
        },
        "develop": { ... },
        "staging": { ... },
        "production": { ... }
    }

## Database
To create the database go into node_modules/relayr-adapter/vagrant/Vagrantfile and change the line:
sudo -u postgres createdb adapter
            <to>
sudo -u postgres createdb shiny

If it's the first time, when you run 'vagrant up' everything will be nicely initialised. Otherwise you will have to
update it by running 'vagrant provision'.

NOTE: all the vagrant commands should be sent from node_modules/relayr-adapter/vagrant

## Client Implementation

    var ShinyAdapter = require('relayr-adapter');
    var shinyAdapter = new RelayrAdapter('shiny');
    relayrAdapter.createConnection({
    
        getOauthUrl: function(message, publisher) {
            publisher.publishSuccess({url: 'http://shinyadapter.com/oauth');
        },

        connectAccount: function(message, publisher) {
            // authorization code...
            publisher.publishSuccess();
        },
        
        disconnectAccount: function(adapterToken) {
            // clear cache for the user with this adapter token
        },

        getDevices: function(user, publisher) {
            publisher.publishSuccess(getDevicesForUser(user));
        },

        unsubscribeFromReadings: function(device) {
            // unsubscribeFromReadings for this device...
        },

        sendCommand: function(publisher, device) {
            // send command ...
            publisher.publishSuccess();
        },

        subscribeToData: function(publisher, device) {
            publisher.publishData(getReadings(device), device.relayrDeviceId);
        }

    });

---
_Source: https://npm.io/package/relayr-adapter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
