Created
January 28, 2012 00:46
-
-
Save treeder/1691843 to your computer and use it in GitHub Desktop.
IronMQ Client Code for Titanium Mobile Developers
This file contains 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
//Then in the main "app.js" (or wherever) call it like this: | |
var HTTPironmq = require('iron_mq'); | |
HTTPironmq.call({ | |
paramsJSON : { | |
messages : [ | |
{ | |
"body": "This is my message 1.", | |
"timeout": 30, | |
"delay": 2, | |
"expires_in": 86400 | |
} | |
] | |
}, | |
timeout : 10000 | |
}); |
This file contains 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
exports.call = function (options) { | |
var xhr = Titanium.Network.createHTTPClient(); | |
var paramsStr = JSON.stringify(options.paramsJSON); | |
xhr.setTimeout(options.timeout); | |
xhr.onerror = options.error; | |
//if and when response comes back the success function is called (need to handle reading the response msg here | |
xhr.onload = function(){ | |
Titanium.API.info("xhr response text was: " + xhr.responseText); | |
}; | |
xhr.open('POST', 'https://mq-aws-us-east-1.iron.io/1/projects/4f20a1135023e823541111bc/queues/my_queue/messages', true); | |
xhr.setRequestHeader('Authorization','OAuth ' + 'vNj11tk3TwzjW1z11115a7c35dM'); | |
xhr.setRequestHeader('User-Agent','IronMQ Client'); | |
xhr.setRequestHeader('Content-Type', 'application/json'); | |
xhr.send(paramsStr); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
var HTTPironmq = require('HTTPironmq');
should be:
var HTTPironmq = require('iron_mq');