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 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
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);
}
});