ozone-development/ozp-iwc — pull request #75 by MidnightJava (2014-08-24 20:00:26+00:00)
Title: Feature client api wrapper merged

This feature provides a client API wrapper, as described in #74.

API General specification:

client.api(apiName).action(resource,packetFragment, callback) -> promise

apiName :== 'names.api' || 'system.api' || 'intents.api' || 'data.api'

action :== any of the actions defined in the wiki for the api you're invoking

resource :== the resource on which the action is to be performed

fragment (optional) :== {entity: my_entity} //you can add other keys as desired. All the keys will be merged into the packet that the wrapper will create and send to the api

callback (optional) :== function to be invoked repeatedly when replies to the sent packet are received. Return a truthy value to continue this. Ater returning a falsy value, the callback will be de-registered and no longer invoked

promise :== an ECMA6 Promise

A general example of API usage

```var client=...
client.api('some.api').action('/resource, {}, function (packet) {
/*Will be invoked every time a reply packet is received
(e.g., replies to a “watch” action invoked for a resource).
Rern true to continue receiving replies to the packet,
false to de-register the callback
}
})
.then(function(reply) {
//will be invoked one time if there was no error
//on the invocation of the API
})
.catch(function(error) {
//will be invoked once with error text if an error occurred
});
```

Legacy integration tests were translated to use the API wrapper instead of accessing the APIs directly.