napi-bindings
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "napi-bindings", | ||
"description": "Nymi API bindings to work with Nymi SDK 4.x", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"license": "Apache-2.0", | ||
@@ -6,0 +6,0 @@ "keywords": ["napi", "nymi", "nymi api", "nymi bindings"], |
@@ -1,1 +0,59 @@ | ||
todo | ||
# node-napi-bindings | ||
Simple Node bindings for the Nymi API (NAPI) 4.0. | ||
Please refer to the official [Nymi Github](https://github.com/Nymi/JSON-API) or [SDK Documentation](https://downloads.nymi.com/sdkDoc/latest/index.html) for details. | ||
## Support | ||
Currently the bindings are only support Windows. | ||
When macOS Sierra is officially supported i will give it a go to support it. | ||
Feel free to participate and create a pull request if you need Mac support sooner. | ||
## Install | ||
``` | ||
npm i napi-bindings | ||
``` | ||
## Prerequisite | ||
Create a file in the root directory of your project named `config.json` with the following content. | ||
````json | ||
{ | ||
"neaName" : "sample", | ||
"sigAlgorithm" : "NIST256P", | ||
"automaticFirmwareVersion" : false | ||
} | ||
```` | ||
## Example | ||
This example will initialize the NAPI, request info about all provisioned Nymi Bands and print the result. | ||
The example makes the assumption you are using the Nymulator on your local machine on default port 9088. | ||
````javascript | ||
const napi = require('napi-bindings'); | ||
try { | ||
let init, put, get; | ||
init = napi.jsonNapiConfigureD('.', 0, 9088, '127.0.0.1'); | ||
console.assert(init === napi.ConfigOutcome.OKAY, 'INIT: %s', Object.keys(napi.ConfigOutcome)[init]); | ||
put = napi.jsonNapiPutD(JSON.stringify({path: 'info/get', exchange: 'provisions'})); | ||
console.assert(put === napi.JsonPutOutcome.OKAY, 'PUT: %s', Object.keys(napi.JsonPutOutcome)[put]); | ||
get = napi.jsonNapiGetD(); | ||
console.assert(get.outcome === napi.JsonGetOutcome.OKAY, 'GET: %s', Object.keys(napi.JsonGetOutcome)[get]); | ||
console.log(JSON.parse(get.message)); | ||
} catch(err) { | ||
console.error(err.message); | ||
} finally { | ||
napi.jsonNapiTerminateD(); | ||
} | ||
```` | ||
### License | ||
See LICENSE file. |
'use strict'; | ||
var FFI = require('ffi'), | ||
Struct = require('ref-struct'), | ||
NapiReturn = new Struct({ | ||
message: 'string', | ||
outcome: 'int', | ||
quit: 'bool' | ||
}); | ||
const FFI = require('ffi'), | ||
Struct = require('ref-struct'), | ||
path = require('path'), | ||
NapiReturn = new Struct({ | ||
message: 'string', | ||
outcome: 'int', | ||
quit: 'bool' | ||
}), | ||
LogLevel = { | ||
NORMAL: 0, | ||
INFO: 1, | ||
DEBUG: 2, | ||
VEBOSE: 3 | ||
}, | ||
ConfigOutcome = { | ||
OKAY: 0, | ||
FAILED_TO_INIT: 1, | ||
CONFIGURATION_FILE_NOT_FOUND: 2, | ||
CONFIGURATION_FILE_NOT_READABLE: 3, | ||
CONFIGURATION_FILE_NOT_PARSED: 4, | ||
IMPOSSIBLE: 5 | ||
}, | ||
JsonPutOutcome = { | ||
OKAY: 0, | ||
NAPI_NOT_RUNNING: 1, | ||
IMPOSSIBLE: 2 | ||
}, | ||
JsonGetOutcome = { | ||
OKAY: 0, | ||
NAPI_NOT_RUNNING: 1, | ||
TIMED_OUT: 2, | ||
QUIT_SIGNALED: 3, | ||
NAPI_FINISHED: 4, | ||
IMPOSSIBLE: 5 | ||
}; | ||
module.exports = new FFI.Library('./bin/napi', { | ||
module.exports = new FFI.Library(path.resolve(__dirname, '../bin/napi'), { | ||
jsonNapiConfigureD: ['int', ['string', 'int', 'int', 'string']], | ||
@@ -16,2 +44,7 @@ jsonNapiGetD: [NapiReturn, []], | ||
jsonNapiTerminateD: ['void', []] | ||
}, { | ||
LogLevel: LogLevel, | ||
ConfigOutcome: ConfigOutcome, | ||
JsonGetOutcome: JsonGetOutcome, | ||
JsonPutOutcome: JsonPutOutcome | ||
}); |
Sorry, the diff of this file is not supported yet
46
59
15454792
13