hew

Interface to the HP Cloud API (unofficial)

Hew

Unofficial Node interface to HP Cloud. (The official interface is here.)

Currently Hew supports a subset of the HP Cloud API:

  • ✔ Authentication Tokens — complete
  • ✔ Messaging — complete
  • Identity — in progress
  • DNS — in progress

See api.md.

npm install hew

For clarity, examples use the popular async module. Hew works just as well without it, or with an alternative async utility.

var Hew = require('hew')
  , async = require('async')
  ;
  
// things you need to set 
var yourRegion = Hew.DEFAULT_REGION;
var yourAccessKey = '';
var yourSecretKey = '';
var yourTenantName = '';
var qname = 'my-test-message-queue';
 
// obtain an authentication token 
var token = new Hew.AuthToken(yourRegion, yourAccessKey, yourSecretKey,
  yourTenantName);
 
// create a Messaging controller 
var messaging = new Hew.Messaging(token);
 
async.series([
  // create the test queue 
  function(cb) { messaging.createQueue(qname, cb); },
 
  // post a message to the queue 
  function(cb) {
    var message = {
      temperature: 22,
      scale: 'Celsius',
      weather: 'sunny'
    };
    messaging.send(qname, message, cb);
  },
 
  // retrieve a message from the queue 
  function(cb) {
    messaging.receive(qname, function(errmessage) {
      if (err) { return cb(err); }
      console.log(message);
      cb();
    });
  },
 
  // delete the test queue 
  function(cb) { messaging.deleteQueue(qname, cb); }
],
function(err) {
  if (err) { console.error('error:', err); }
  else { console.log('done'); }
});
 

Warning: Do not run unit tests against your production HP Cloud account. Create an additional account for testing. Testing will create, update and delete resources in your HP Cloud account. While the tests try to avoid affecting “real” data, and they do clean up after themselves, there is no guarantee that everything will work properly.

  1. Check out the Hew git repo.
  2. Create tests/config.json (an example is provided).
  3. Add the following key to tests/config.json:
  • "i-created-this-account-for-testing-only": true
  1. From the the top of the repo, run npm test.