This is an implementation of a client for Yammer's Bayeux push-based API, described here: https://developer.yammer.com/realtime. The implementation works with Node.js 0.6.x and newer.
Please note that this is an implementation for the older version of the real-time API (which is still suported by Yammer), and not the newer one that uses https://www.yammer.com/api/v1/realtime as the entry-point to Yammer's real-time data. A future version of the module will provide support for the newer API.
There is a sample application in the samples/ folder. Edit file samples/config.js, provide your own Yammer OAuth 2.0 and then run it with ```node app.js````.
The module is available via npm using 'yammer-push-api-client' as the module name: https://npmjs.org/package/yammer-push-api-client
The module supports reading real-time data with the API from three different enpoints: messages (or rather, the All Company feed), topics and groups. The endpoint selection is via the second parameter object provided to the YammerPushAPI constructor; use values "all", "topics" and "groups" for the "type" key.
The module will try to follow the advice provided by Yammer with regards to intervals between connections as well as socket timeouts (but see the TODO section). Otherwise no delays are used between connectiosn and Node's default socket timeout is used.
You will need a valid OAuth 2.0 token from Yammer. This module will not generate a token for your application, so applications are expected to use other Yammer APIs to generate their own tokens.
The module implements an event emitter using two specific events: 'data' and 'fatal'. The first one is triggered whenever new data was received from the connection while the second is triggered when an unrecoverable error happened, and it gives applications an opportunity to clean up rather than throw an exception upwards.
In your package.json file, add the following dependency:
"dependencies":"yammer-push-api-client": ">= 0.0.0"
npm install so that npm can automatically retrive the module as well as its dependencies.
Import the required modules:
var YammerPushAPI = ;
Second, create a new client:
var client = YammerPushAPI;
Then, implement listener functiosn for the data and fatal events:
After all the previous steps are in place, the client can be started:
The client is constantly running so the application will not exit unless there is an unhandled exception.
Logging is provided by the Log4js-Node library, using the following categories:
No log4js-node configuration is provided in the code so users of this module are free to provide their own log4js layouts, appenders and level settings by configuring log4js accordingly in their code.
During development of clients that use this API it may be useful to use a reliable mechanism to receive a constant stream of messages, as opposed to wait for someone on our network to post something. For that purpose, the library provides a mock implementation that will generate data based on a configurable schedule.
The mock implementation behaves just like the real client:
var YammerPushAPI = ;var client = YammerPushAPI;client;
This will generate a message every 5 seconds. The body of the message is provided in the module's lib/mock/data/data.json, and it currently is not configurable.
Basic unit testing is available and can be run via Grunt. If Grunt is not installed yet, please
install it with
npm -g install grunt-cli.
In order to execute the unit tests, edit file
test/config.js to add your own OAuth 2.0 (as the tests will make
real calls to Yammer's endpoints) and then run the tests with command
Apache Software License 2.0: http://www.apache.org/licenses/LICENSE-2.0