insane-openbazaar-api
Openbazaar API client for Nodejs. WARNING: Incomplete implementation!!
Installation
Usage
var OpenBazaarAPI = require('insane-openbazaar-api');
var ob = new OpenBazaarAPI({
"username": "chris_grimmett",
"password": "rosebud"
});
ob.login(function(err) {
if (err) throw err;
ob.profile(function(err, reply) {
if (err) throw err;
console.log(reply.profile.short_description);
ob.profile(function('a06aa22a38f0e62221ab74464c311bd88305f88c', err, reply) {
if (err) throw err;
console.log(reply.profile.website);
});
});
});
Convenience methods
ob.login
and ob.profile
are simple wrappers to the OpenBazaar-Server API endpoints. You have to make sure that your app is logged into the OpenBazaar-Server before you can call ob.profile
. If the OpenBazaar-Server restarts while your API client is running, your past authentication cookies are invalidated and you have to log in again. This means you have to write extra code to check the state of your login, which can be annoying. To make your job easier, I've made a convenience method for getting information from the API. Just call it and expect a response. Calling .get() will ensure that you have a valid authentication cookie and you're able to receive information from the API.
ob.get('profile', 'a06aa22a38f0e62221ab74464c311bd88305f88c', function(err, reply) {
if (err) throw err;
console.log(reply.profile.handle);
});
Implemented API
GET requests
POST requests
DELETE requests
Roadmap
Development Notes
(Because I forget!)
I'm using node foreman to set environment variables. I keep a .env
file with environment variables; it is ignored by git and not in this repository.
I'm using Drakov in testing to mock OpenBazaar-Server API responses. API mocks are defined in spec.md
and use the API Blueprint format.
I wrote the tests to be flexible with server mocking. I test two different ways. One is running Drakov in the foreground.
Drakov runs in the foreground in a second terminal--
drakov -f ./spec.md -p 3000 --watch
And in my main terminal, I run nf mocha
I do this while I develop locally so I can see that Drakov is responding to the API queries as expected during the mocha tests.
I can also test against a live openbazaar server, by these environment variables in .env
OB_USERNAME=chris_grimmett
OB_PASSWORD=rosebud
OB_HOST=192.168.1.24
OB_PORT=18469
#OB_LIVE_TEST=1
The OB_LIVE_TEST is what tells the mocha test to run against a live OpenBazaar server. I just comment or uncomment that line depending on what type of test I want to run.
When Travic-CI runs the test, TRAVIS
is set in the environment. Mocha sees this environment variable, and calls Drakov from within the test.