Created
March 12, 2013 12:18
-
-
Save kevinsimper/5142464 to your computer and use it in GitHub Desktop.
Function for adding messages to Iron.io MQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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