Home

Awesome

Meshblu HTTP

A node package to use the Meshblu HTTP API...

Build Status Code Climate Test Coverage npm version Gitter

Usage

Install:

npm install --save meshblu-http

Use:

var MeshbluHttp = require('meshblu-http');

var meshbluHttp = new MeshbluHttp();

meshbluHttp.register({}, function(error, response) {
  // code goes here
})

Functions

Constructor

ParameterTypeRequiredDescription
optionsobjectnocan contain any of these keys: bearerToken, uuid, token, hostname, port, protocol, domain, service, secure, resolveSrv, auth

var meshbluHttp = new MeshbluHttp({uuid: 'fancy_uuid', token: 'fancy_token'})
var meshbluHttp = new MeshbluHttp({bearerToken: 'some-bearer-token'})

Authenticate

ParameterTypeRequiredDescription
callbackfunctionyesa function that returns error and response

meshbluHttp.authenticate(function(error, response) {
  // code goes here
})

Create Hook

ParameterTypeRequiredDescription
uuidstringyes   a string containing the uuid
typestringyes   a string containing the type
urlstringyes   a string containing the url
callbackfunctionyes   a function that returns error

meshbluHttp.createHook('fancy_uuid', 'fancy_token', 'fancy_url', function(error) {
  // code goes here
})

Create Subscription

ParameterTypeRequiredDescription
optionsobjectyes   an object containing three keys: subscriberUuid, emitterUuid, and type
callbackfunctionyesa function that returns error and response

meshbluHttp.createSubscription(
  {
    subscriberUuid: 'fancy_uuid',
    emitterUuid: 'another_fancy_uuid',
    type: 'fancy_type'
  },
  function(error, response){
    // code goes here
  }
)

Delete Subscription

ParameterTypeRequiredDescription
optionsobjectyes   an object containing three keys: subscriberUuid, emitterUuid, and type
callbackfunctionyesa function that returns error and response

meshbluHttp.deleteSubscription(
  {
    subscriberUuid: 'fancy_uuid',
    emitterUuid: 'another_fancy_uuid',
    type: 'fancy_type'
  },
  function(error, response){
    // code goes here
  }
)

Delete Subscriptions

ParameterTypeRequiredDescription
optionsobjectyes   an object containing three keys: subscriberUuid, emitterUuid, and type. Type and emitterUuid are optional and will be used to filter the subscriptions to delete.
callbackfunctionyesa function that returns error and response

meshbluHttp.deleteSubscriptions(
  {
    subscriberUuid: 'fancy_uuid',
    emitterUuid: 'another_fancy_uuid',
    type: 'fancy_type'
  },
  function(error, response){
    // code goes here
  }
)

Device

ParameterTypeRequiredDescription
uuidstringyes   a string containing the uuid of the device
metadataobjectno   an object containing metadata information
callbackfunctionyes   a function that returns error and response

meshbluHttp.device('fancy_uuid', {as: 'another_user_uuid'}, function(error, response){
  // code goes here
})

Devices

ParameterTypeRequiredDescription
queryobjectno    an object containing the keys you want to search for
metadataobjectno   an object containing metadata information
callbackfunctionyes   a function that returns error and response

meshbluHttp.devices({type: 'drone'}, {as: 'another_user_uuid'}, function(error, response){
  // code goes here
})

Find And Update

ParameterTypeRequiredDescription
uuidstringyes   a string containing the uuid of the device
paramsobjectyes   an object containing the new changes to the device
metadataobjectno   an object containing metadata information
callbackfunctionyes   a function that returns error and response

meshbluHttp.findAndUpdate('fancy_uuid', {type: 'new-type'}, function(error, response){
  // code goes here
})

Generate And Store Token

ParameterTypeRequiredDescription
uuidstringyes   a string containing the uuid of the device
callbackfunctionyes   a function that returns error and response

meshbluHttp.generateAndStoreToken('fancy_uuid', function(error, response){
  // code goes here
})

Generate And Store Token With Options

ParameterTypeRequiredDescription
uuidstringyes   a string containing the uuid of the device
optionsobjectnoan object containing the options for the token
callbackfunctionyes   a function that returns error and response

meshbluHttp.generateAndStoreTokenWithOptions('fancy_uuid', {expiresOn: '1485452874'},
  function(error, response){
    // code goes here
  }
)

Generate Key Pair

ParameterTypeRequiredDescription
none   

meshbluHttp.generateKeyPair()

Health Check

ParameterTypeRequiredDescription
callbackfunctionyes   a function that returns error, healthy, and code

meshbluHttp.healthcheck(function(error, healthy, code){
  // code goes here
})

Message

ParameterTypeRequiredDescription
messageobjectyesan object containing the message to send
metadataobjectno   an object containing metadata information
callbackfunctionyes   a function that returns error and response

meshbluHttp.message({data: 'hello_message'}, function(error, response){
  // code goes here
})

My Devices

ParameterTypeRequiredDescription
queryobjectno   an object containing your query
callbackfunctionyes   a function that returns error and response

meshbluHttp.mydevices({type: 'drone'}, function(error, response){
  // code goes here
})

Public Key

ParameterTypeRequiredDescription
uuidstringyes   a string containing the uuid of the device
callbackfunctionyes   a function that returns error and response

meshbluHttp.publicKey('fancy_uuid', function(error, response){
  // code goes here
})

Register

ParameterTypeRequiredDescription
optionsobjectyes   an object containing properties that you would like your device to have. Can be empty object
callbackfunctionyes   a function that returns error and response

meshbluHttp.register({color: 'blue'}, function(error, response){
  // code goes here
})

Reset Token

ParameterTypeRequiredDescription
uuidstringyes   a string containing the uuid of the device
callbackfunctionyes   a function that returns error and response

meshbluHttp.resetToken('fancy_uuid', function(error, response){
  // code goes here
})

Revoke Token

ParameterTypeRequiredDescription
uuidstringyes   a string containing the uuid of the device
tokenstringyes   a string containing the token of the device
callbackfunctionyes   a function that returns error and response

meshbluHttp.revokeToken('fancy_uuid', 'fancy_token', function(error, response){
  // code goes here
})

Revoke Token By Query

ParameterTypeRequiredDescription
uuidstringyes   a string containing the uuid of the device
queryobjectyes   an object containing your query
callbackfunctionyes   a function that returns error and response

meshbluHttp.revokeTokenByQuery('fancy_uuid', {expiresOn: '1485452874'},
  function(error, response){
    // code goes here
  }
)

Search

ParameterTypeRequiredDescription
queryobjectyes   an object containing your query
metadataobjectyes  an object containing metadata information. Can be left empty
callbackfunctionyes   a function that returns error and response

meshbluHttp.search({type: 'drone'}, {as: 'another_uuid'},
  function(error, response){
    // code goes here
  }
)

Search Tokens

ParameterTypeRequiredDescription
queryobjectyes   an object containing your query
metadataobjectyes  an object containing metadata information. Can be left empty
callbackfunctionyes   a function that returns error and response

meshbluHttp.searchTokens({expiresOn: '1485452874'}, {as: 'another_uuid'},
  function(error, response){
    // code goes here
  }
)

Set Private Key

ParameterTypeRequiredDescription
privateKeystring/objectyes  a string or object containing your privateKey

meshbluHttp.setPrivateKey(privateKey)

Sign

ParameterTypeRequiredDescription
data    objectyes   an object containing the data you want to sign your privateKey with

meshbluHttp.sign(data)

Subscriptions

ParameterTypeRequiredDescription
uuidstringyes   a string containing the uuid of the device
metadataobjectno   an object containing metadata information
callbackfunctionyes   a function that returns error and response

meshbluHttp.subscriptions('fancy_uuid', {as: 'another_uuid'},
  function(error, response){
    // code goes here
  }
)

Unregister

ParameterTypeRequiredDescription
deviceobjectyes   an object containing the device credentials
callbackfunctionyes   a function that returns error and response

meshbluHttp.unregister({uuid: 'abc', token: 'asd'}, function(error, response){
  // code goes here
})

Update

ParameterTypeRequiredDescription
uuidstringyes   a string containing the uuid
paramsobjectyes   an object containing the new changes to the device
metadataobjectno   an object containing metadata information
callbackfunctionyesa function that returns error and response

meshbluHttp.update('fancy_uuid', {color: 'green'}, function(error, response){
  // code goes here
})

Verify

ParameterTypeRequiredDescription
messagestring/objectyes   data for encrypting
signaturestringyes   this can be obtained from sign()

meshbluHttp.verify(message, signature)

Whoami

ParameterTypeRequiredDescription
callbackfunctionyesa function that returns error and response

meshbluHttp.whoami(function(error, response){
  // code goes here
})