Skip to content

Instantly share code, notes, and snippets.

@kevinsimper
Created March 12, 2013 12:18
Show Gist options
  • Select an option

  • Save kevinsimper/5142464 to your computer and use it in GitHub Desktop.

Select an option

Save kevinsimper/5142464 to your computer and use it in GitHub Desktop.
Function for adding messages to Iron.io MQ
var request = require('request');
function Queue(token, projectId, queue){
this.options = {
url: 'http://mq-aws-us-east-1.iron.io/1/projects/' + projectId + '/queues/' + queue + '/messages',
headers: {
'Content-Type': 'application/json',
'Authorization': 'OAuth ' + token
},
body: '{"messages":[{"body":"hello world!"}]}'
}
}
Queue.prototype.post = function(message){
var options = this.options;
options.method = 'POST';
if(message){
options.body = '{"messages":[{"body":"' + message + '"}]}';
}
request(this.options, function(error, response, body){
console.log(body);
});
}
Queue.prototype.get = function(){
var options = this.options;
options.method = 'GET';
request(this.options, function(error, response, body){
console.log(response, body);
});
}
var token = '1scwH6b3MHWXW-cGfVCuxxxxx'
, projectId = '50a01d5865e2ea17xxxxxx';
var queue = new Queue(token, projectId, 'domains');
queue.post('message');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment