Async HTTPGet for Monkey

Monkey Forums/Monkey Code/Async HTTPGet for Monkey

Indiepath(Posted 2011) [#1]
** Flash Target Added

I've only implemented HTML5 target so far but will move on to the others when I have more time.

Grab the files and plop them in your modules directory to use : http://www.moofoo.net/monkey/moofoo.rar

Simple use :


But you could extend the asyncStream class and over-ride the callback methods to do more complex things ;)


Indiepath(Posted 2011) [#2]
Example of how you might over-ride a method



Beaker(Posted 2011) [#3]
Good stuff.


Indiepath(Posted 2011) [#4]
So is this likely to get M U N G E D or obfuscated into oblivion in the future? Perhaps you'd let us tell the compiler that we've already used the obfuscation of choice :)


Indiepath(Posted 2011) [#5]
Hey 'cause people are requesting it - unobfuscated version of moofoo.html5.js



Indiepath(Posted 2011) [#6]
Just added Flash Target


degac(Posted 2011) [#7]
Just to know everyone.
I get an error about 'Overriding method does not match any overriden method'...

I found I need to 'strictize'(with :String) the methods to compile it.




Indiepath(Posted 2011) [#8]
My bad - I didn't test with a STRICT example.


Xaron(Posted 2011) [#9]
That link above is broken... :(


Suco-X(Posted 2011) [#10]
Hi guys.

Got some trouble with this stuff. Everytime I get an error if I want to start my request. Code:

ajax.js
// HTML5 moofoo runtime.
//
// Copyright 2011 Indiepath Ltd, all rights reserved.
// No warranty implied; use at your own risk.

//***** moofooStream class *****
function mfStrm(){};

mfStrm.prototype.getUrl=function( host, query ){
	var self = this;
	var xhr	= new XMLHttpRequest();
	
	if(xhr==null){
		self.onRequestError("Failed to create Request");

	};

	xhr.open("GET", host + query, true);


	xhr.onreadystatechange = function() {
		
		switch (xhr.readyState){
		case 0:
			self.onRequestError("Error: "+xhr.statusText);
			break;
		case 1:
			self.onConnectionEstablished();
			break;
		case 2:
			self.onRequestReceived();
			break;
		case 3:
			self.onRequestProcessing();
			break;
		case 4:
			if (xhr.status == 200){
				self.onRequestComplete(xhr.responseText);
				
			} else {
				self.onRequestError("Error: "+xhr.statusText);
			}
			break;
		}
	};

	xhr.send(null);
};

mfStrm.prototype.onRequestError=function(status){};
mfStrm.prototype.onConnectionEstablished=function(){};
mfStrm.prototype.onRequestReceived=function(){};
mfStrm.prototype.onRequestProcessing=function(){};
mfStrm.prototype.onRequestComplete=function( response ){};


monkey code:
' Module moofoo.stream
'
' Copyright 2011 Indiepath Ltd, all rights reserved.
' No warranty implied; use at your own risk.

Import "ajax.js"


Extern

Class moofooStream="mfStrm"
	Method getUrl( host$, query$)
	Method onRequestError:String(status:String) 
	Method onConnectionEstablished:String()
	Method onRequestReceived:String()
	Method onRequestProcessing:String()
	Method onRequestComplete:String(response$)
End

Public

Class asyncStream Extends moofooStream
	
	Method New()
	End
	Method onRequestError$(status:String)
		Print status
	End
	Method onConnectionEstablished$()
		Return "connection made"
	End
	Method onRequestReceived$()
		Return "request received"
	End
	Method onRequestProcessing$()
		Return "request processing"
	End
	Method onRequestComplete$(response$)
		Print response
	End		
End


Function Main()
	Local tmp:asyncStream = New asyncStream
	tmp.getUrl("http://localhost/test/index.php", "")
End


The file "index.php" in "/test" definitely exists but I´ll get an error without any text. xhr.status is 0.

May someone can explain what´s going wrong here.

Mfg Suco


degac(Posted 2011) [#11]
Have you tried with a 'real' on-line test?
I have similar problem on local, then I uploaded it online on my site and it did work.


Indiepath(Posted 2011) [#12]
Ooops, seems my DNS is pointing to a server that no longer exists - I'll fix it shortly.


wmaass(Posted 2011) [#13]
Anybody have moofoo.rar? I've gotten around to getting a test app on facebook and am now looking at actually getting Facebook user into into the app.


Indiepath(Posted 2011) [#14]
You can get it here for now : http://culturalvibes.co.uk/monkey/moofoo.rar


wmaass(Posted 2011) [#15]
Thanks Indepath.


thoast(Posted 2011) [#16]
For flash, all overriden functions in moofoo.stream.flash.as have to use same return type as overriding function (String), otherwise it will return error on compiling.

Thanks for this lib :)


Fred(Posted 2012) [#17]
@thoast
I'm trying to use moofoo with flash, but I can't get it to compile (I don't know actionscript).
with the example given by indiepath (#2) I have this:
Chargement du fichier de configuration C:\FlexSDK\frameworks\flex-config.xml

ERROR:C:\....build\flash\MonkeyGame.as(1869): col: 27 Erreur: override non compatible.

public override function onRequestError():String{

I changed the stream.moofoo.flash.as as you said. any clue ?


Leos(Posted 2012) [#18]
I had to change from "internl function" to "public function" to compile in flash.